Example usage for android.widget SimpleAdapter SimpleAdapter

List of usage examples for android.widget SimpleAdapter SimpleAdapter

Introduction

In this page you can find the example usage for android.widget SimpleAdapter SimpleAdapter.

Prototype

public SimpleAdapter(Context context, List<? extends Map<String, ?>> data, @LayoutRes int resource,
        String[] from, @IdRes int[] to) 

Source Link

Document

Constructor

Usage

From source file:com.ichi2.anki.Feedback.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    Themes.applyTheme(this);
    super.onCreate(savedInstanceState);

    Resources res = getResources();

    Context context = getBaseContext();
    SharedPreferences sharedPreferences = AnkiDroidApp.getSharedPrefs(context);
    mReportErrorMode = sharedPreferences.getString("reportErrorMode", REPORT_ASK);

    mNonce = UUID.randomUUID().getMostSignificantBits();
    mFeedbackUrl = res.getString(R.string.feedback_post_url);
    mErrorUrl = res.getString(R.string.error_post_url);
    mImm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);

    mPostingFeedback = false;/* w w w  .  ja v a 2  s.c  o  m*/
    initAllAlertDialogs();

    getErrorFiles();
    Intent i = getIntent();
    mAllowFeedback = (i.hasExtra("request") && (i.getIntExtra("request", 0) == DeckPicker.REPORT_FEEDBACK
            || i.getIntExtra("request", 0) == DeckPicker.RESULT_DB_ERROR))
            || mReportErrorMode.equals(REPORT_ASK);
    if (!mAllowFeedback) {
        if (mReportErrorMode.equals(REPORT_ALWAYS)) { // Always report
            try {
                String feedback = "Automatically sent";
                Connection.sendFeedback(mSendListener, new Payload(new Object[] { mFeedbackUrl, mErrorUrl,
                        feedback, mErrorReports, mNonce, getApplication(), true }));
                if (mErrorReports.size() > 0) {
                    mPostingFeedback = true;
                }
                if (feedback.length() > 0) {
                    mPostingFeedback = true;
                }
            } catch (Exception e) {
                Log.e(AnkiDroidApp.TAG, e.toString());
            }
            finish();
            ActivityTransitionAnimation.slide(Feedback.this, ActivityTransitionAnimation.NONE);
            return;
        } else if (mReportErrorMode.equals(REPORT_NEVER)) { // Never report
            deleteFiles(false, false);
            finish();
            ActivityTransitionAnimation.slide(Feedback.this, ActivityTransitionAnimation.NONE);
            return;
        }
    }

    View mainView = getLayoutInflater().inflate(R.layout.feedback, null);
    setContentView(mainView);
    Themes.setWallpaper(mainView);
    Themes.setTextViewStyle(findViewById(R.id.tvFeedbackDisclaimer));
    Themes.setTextViewStyle(findViewById(R.id.lvFeedbackErrorList));

    Button btnSend = (Button) findViewById(R.id.btnFeedbackSend);
    Button btnKeepLatest = (Button) findViewById(R.id.btnFeedbackKeepLatest);
    Button btnClearAll = (Button) findViewById(R.id.btnFeedbackClearAll);
    mEtFeedbackText = (EditText) findViewById(R.id.etFeedbackText);
    mLvErrorList = (ListView) findViewById(R.id.lvFeedbackErrorList);

    mErrorAdapter = new SimpleAdapter(this, mErrorReports, R.layout.error_item,
            new String[] { "name", "state", "result" },
            new int[] { R.id.error_item_text, R.id.error_item_progress, R.id.error_item_status });
    mErrorAdapter.setViewBinder(new SimpleAdapter.ViewBinder() {
        @Override
        public boolean setViewValue(View view, Object arg1, String text) {
            switch (view.getId()) {
            case R.id.error_item_progress:
                if (text.equals(STATE_UPLOADING)) {
                    view.setVisibility(View.VISIBLE);
                } else {
                    view.setVisibility(View.GONE);
                }
                return true;
            case R.id.error_item_status:
                if (text.length() == 0) {
                    view.setVisibility(View.GONE);
                    return true;
                } else {
                    view.setVisibility(View.VISIBLE);
                    return false;
                }
            }
            return false;
        }
    });

    btnClearAll.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            deleteFiles(false, false);
            refreshErrorListView();
            refreshInterface();
        }
    });

    mLvErrorList.setAdapter(mErrorAdapter);

    btnSend.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            if (!mPostingFeedback) {
                String feedback = mEtFeedbackText.getText().toString();
                Connection.sendFeedback(mSendListener, new Payload(new Object[] { mFeedbackUrl, mErrorUrl,
                        feedback, mErrorReports, mNonce, getApplication(), false }));
                if (mErrorReports.size() > 0) {
                    mPostingFeedback = true;
                }
                if (feedback.length() > 0) {
                    mPostingFeedback = true;
                }
                refreshInterface();
            }
        }
    });

    btnKeepLatest.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            deleteFiles(false, true);
            refreshErrorListView();
            refreshInterface();
        }
    });

    refreshInterface();

    getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN
            | WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);

}

From source file:com.chinaftw.music.ui.ActionBarCastActivity.java

private void populateDrawerItems() {
    mDrawerMenuContents = new DrawerMenuContents(this);
    final int selectedPosition = mDrawerMenuContents.getPosition(this.getClass());
    final int unselectedColor = Color.WHITE;
    final int selectedColor = getResources().getColor(R.color.drawer_item_selected_background);
    SimpleAdapter adapter = new SimpleAdapter(this, mDrawerMenuContents.getItems(), R.layout.drawer_list_item,
            new String[] { DrawerMenuContents.FIELD_TITLE, DrawerMenuContents.FIELD_ICON },
            new int[] { R.id.drawer_item_title, R.id.drawer_item_icon }) {
        @Override//  w  ww .jav  a2s  .  c  om
        public View getView(int position, View convertView, ViewGroup parent) {
            View view = super.getView(position, convertView, parent);
            int color = unselectedColor;
            if (position == selectedPosition) {
                color = selectedColor;
            }
            view.setBackgroundColor(color);
            return view;
        }
    };

    mDrawerList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            if (position != selectedPosition) {
                view.setBackgroundColor(getResources().getColor(R.color.drawer_item_selected_background));
                mItemToOpenWhenDrawerCloses = position;
            }
            mDrawerLayout.closeDrawers();
        }
    });
    mDrawerList.setAdapter(adapter);
}

From source file:com.example.android.uamp.ui.ActionBarCastActivity.java

private void populateDrawerItems() {
    mDrawerMenuContents = new DrawerMenuContents(this);
    final int selectedPosition = mDrawerMenuContents.getPosition(this.getClass());
    final int unselectedColor = getResources().getColor(R.color.white);
    final int selectedColor = getResources().getColor(R.color.drawer_item_selected_background);
    SimpleAdapter adapter = new SimpleAdapter(this, mDrawerMenuContents.getItems(), R.layout.drawer_list_item,
            new String[] { DrawerMenuContents.FIELD_TITLE, DrawerMenuContents.FIELD_ICON },
            new int[] { R.id.drawer_item_title, R.id.drawer_item_icon }) {
        @Override//from   www  .ja  v a  2s  . c o  m
        public View getView(int position, View convertView, ViewGroup parent) {
            View view = super.getView(position, convertView, parent);
            int color = unselectedColor;
            if (position == selectedPosition) {
                color = selectedColor;
            }
            view.setBackgroundColor(color);
            return view;
        }
    };

    mDrawerList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            if (position != selectedPosition) {
                view.setBackgroundColor(getResources().getColor(R.color.drawer_item_selected_background));
                mItemToOpenWhenDrawerCloses = position;
            }
            mDrawerLayout.closeDrawers();
        }
    });
    mDrawerList.setAdapter(adapter);
}

From source file:com.hichinaschool.flashcards.anki.Feedback.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    Themes.applyTheme(this);
    super.onCreate(savedInstanceState);

    Resources res = getResources();

    Context context = getBaseContext();
    SharedPreferences sharedPreferences = AnkiDroidApp.getSharedPrefs(context);
    mReportErrorMode = sharedPreferences.getString("reportErrorMode", REPORT_ASK);

    mNonce = UUID.randomUUID().getMostSignificantBits();
    mFeedbackUrl = res.getString(R.string.feedback_post_url);
    mErrorUrl = res.getString(R.string.error_post_url);
    mImm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);

    mPostingFeedback = false;/*from  ww  w.  ja va2s  .  co  m*/
    initAllAlertDialogs();

    getErrorFiles();
    Intent i = getIntent();
    mAllowFeedback = (i.hasExtra("request") && (i.getIntExtra("request", 0) == DeckPicker.REPORT_FEEDBACK
            || i.getIntExtra("request", 0) == DeckPicker.RESULT_DB_ERROR))
            || mReportErrorMode.equals(REPORT_ASK);
    if (!mAllowFeedback) {
        if (mReportErrorMode.equals(REPORT_ALWAYS)) { // Always report
            try {
                String feedback = "Automatically sent";
                Connection.sendFeedback(mSendListener, new Payload(new Object[] { mFeedbackUrl, mErrorUrl,
                        feedback, mErrorReports, mNonce, getApplication(), true }));
                if (mErrorReports.size() > 0) {
                    mPostingFeedback = true;
                }
                if (feedback.length() > 0) {
                    mPostingFeedback = true;
                }
            } catch (Exception e) {
                Log.e(AnkiDroidApp.TAG, e.toString());
            }
            finish();
            if (AnkiDroidApp.SDK_VERSION > 4) {
                ActivityTransitionAnimation.slide(Feedback.this, ActivityTransitionAnimation.NONE);
            }
            return;
        } else if (mReportErrorMode.equals(REPORT_NEVER)) { // Never report
            deleteFiles(false, false);
            finish();
            if (AnkiDroidApp.SDK_VERSION > 4) {
                ActivityTransitionAnimation.slide(Feedback.this, ActivityTransitionAnimation.NONE);
            }
            return;
        }
    }

    View mainView = getLayoutInflater().inflate(R.layout.feedback, null);
    setContentView(mainView);
    Themes.setWallpaper(mainView);
    Themes.setTextViewStyle(findViewById(R.id.tvFeedbackDisclaimer));
    Themes.setTextViewStyle(findViewById(R.id.lvFeedbackErrorList));

    Button btnSend = (Button) findViewById(R.id.btnFeedbackSend);
    Button btnKeepLatest = (Button) findViewById(R.id.btnFeedbackKeepLatest);
    Button btnClearAll = (Button) findViewById(R.id.btnFeedbackClearAll);
    mEtFeedbackText = (EditText) findViewById(R.id.etFeedbackText);
    mLvErrorList = (ListView) findViewById(R.id.lvFeedbackErrorList);

    mErrorAdapter = new SimpleAdapter(this, mErrorReports, R.layout.error_item,
            new String[] { "name", "state", "result" },
            new int[] { R.id.error_item_text, R.id.error_item_progress, R.id.error_item_status });
    mErrorAdapter.setViewBinder(new SimpleAdapter.ViewBinder() {
        @Override
        public boolean setViewValue(View view, Object arg1, String text) {
            switch (view.getId()) {
            case R.id.error_item_progress:
                if (text.equals(STATE_UPLOADING)) {
                    view.setVisibility(View.VISIBLE);
                } else {
                    view.setVisibility(View.GONE);
                }
                return true;
            case R.id.error_item_status:
                if (text.length() == 0) {
                    view.setVisibility(View.GONE);
                    return true;
                } else {
                    view.setVisibility(View.VISIBLE);
                    return false;
                }
            }
            return false;
        }
    });

    btnClearAll.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            deleteFiles(false, false);
            refreshErrorListView();
            refreshInterface();
        }
    });

    mLvErrorList.setAdapter(mErrorAdapter);

    btnSend.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            if (!mPostingFeedback) {
                String feedback = mEtFeedbackText.getText().toString();
                Connection.sendFeedback(mSendListener, new Payload(new Object[] { mFeedbackUrl, mErrorUrl,
                        feedback, mErrorReports, mNonce, getApplication(), false }));
                if (mErrorReports.size() > 0) {
                    mPostingFeedback = true;
                }
                if (feedback.length() > 0) {
                    mPostingFeedback = true;
                }
                refreshInterface();
            }
        }
    });

    btnKeepLatest.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            deleteFiles(false, true);
            refreshErrorListView();
            refreshInterface();
        }
    });

    refreshInterface();

    getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN
            | WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);

}

From source file:org.ohmage.prompt.singlechoicecustom.SingleChoiceCustomPrompt.java

@Override
public View getView(final Context context) {

    mCustomChoices.clear();/* w  w w  . j a  va 2s .c o  m*/
    SingleChoiceCustomDbAdapter dbAdapter = new SingleChoiceCustomDbAdapter(context);
    String surveyId = ((SurveyActivity) context).getSurveyId();
    SharedPreferencesHelper prefs = new SharedPreferencesHelper(context);
    String campaignUrn = ((SurveyActivity) context).getCampaignUrn();
    String username = prefs.getUsername();
    if (dbAdapter.open()) {
        Cursor c = dbAdapter.getCustomChoices(username, campaignUrn, surveyId,
                SingleChoiceCustomPrompt.this.getId());
        c.moveToFirst();
        for (int i = 0; i < c.getCount(); i++) {
            //c.getLong(c.getColumnIndex(SingleChoiceCustomDbAdapter.KEY_ID));
            int key = c.getInt(c.getColumnIndex(SingleChoiceCustomDbAdapter.KEY_CHOICE_ID));
            String label = c.getString(c.getColumnIndex(SingleChoiceCustomDbAdapter.KEY_CHOICE_VALUE));
            mCustomChoices.add(new KVLTriplet(String.valueOf(key), null, label));
            c.moveToNext();
        }
        c.close();
        dbAdapter.close();
    }

    LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    //      mListView = (ListView) inflater.inflate(R.layout.prompt_single_choice_custom, null);
    mListView = new CustomChoiceListView(context);
    mListView.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
    mListView.setTextFilterEnabled(false);

    mListView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
    mListView.setDescendantFocusability(ViewGroup.FOCUS_AFTER_DESCENDANTS);

    mFooterView = inflater.inflate(R.layout.custom_choice_footer, null);

    EditText mEditText = (EditText) mFooterView.findViewById(R.id.new_choice_edit);
    ImageButton mButton = (ImageButton) mFooterView.findViewById(R.id.ok_button);
    ImageButton mCancelButton = (ImageButton) mFooterView.findViewById(R.id.cancel_button);

    showAddItemControls(context, mIsAddingNewItem);

    mButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {

            if (mEnteredText != null && !mEnteredText.equals("")) {
                SingleChoiceCustomDbAdapter dbAdapter = new SingleChoiceCustomDbAdapter(context);
                String surveyId = ((SurveyActivity) context).getSurveyId();
                SharedPreferencesHelper prefs = new SharedPreferencesHelper(context);
                String campaignUrn = ((SurveyActivity) context).getCampaignUrn();
                String username = prefs.getUsername();

                int choiceId = 100;
                ArrayList<String> keys = new ArrayList<String>();
                for (KVLTriplet choice : mChoices) {
                    keys.add(choice.key.trim());
                }
                for (KVLTriplet choice : mCustomChoices) {
                    keys.add(choice.key.trim());
                }
                while (keys.contains(String.valueOf(choiceId))) {
                    choiceId++;
                }

                if (dbAdapter.open()) {
                    dbAdapter.addCustomChoice(choiceId, mEnteredText, username, campaignUrn, surveyId,
                            SingleChoiceCustomPrompt.this.getId());
                    dbAdapter.close();
                }

                showAddItemControls(context, false);

                mSelectedIndex = mListView.getCount() - 1;

                ((SurveyActivity) context).reloadCurrentPrompt();
            } else {
                Toast.makeText(context, "Please enter some text", Toast.LENGTH_SHORT).show();
            }
        }
    });

    mCancelButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            //            EditText edit = (EditText) mFooterView.findViewById(R.id.new_choice_edit);
            showAddItemControls(context, false);
        }
    });

    mEditText.addTextChangedListener(new TextWatcher() {

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            // TODO Auto-generated method stub

        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            // TODO Auto-generated method stub

        }

        @Override
        public void afterTextChanged(Editable s) {
            // TODO Auto-generated method stub
            mEnteredText = s.toString();
            //            mListView.setSelectionFromTop(mLastIndex, mLastTop);
            //            EditText editText = (EditText) mFooterView.findViewById(R.id.new_choice_edit);
            //            editText.requestFocus();
        }
    });

    mListView.addFooterView(mFooterView);

    String[] from = new String[] { "value" };
    int[] to = new int[] { android.R.id.text1 };

    List<HashMap<String, String>> data = new ArrayList<HashMap<String, String>>();
    for (int i = 0; i < mChoices.size(); i++) {
        HashMap<String, String> map = new HashMap<String, String>();
        map.put("key", mChoices.get(i).key);
        map.put("value", mChoices.get(i).label);
        data.add(map);
    }
    for (int i = 0; i < mCustomChoices.size(); i++) {
        HashMap<String, String> map = new HashMap<String, String>();
        map.put("key", mCustomChoices.get(i).key);
        map.put("value", mCustomChoices.get(i).label);
        data.add(map);
    }

    SimpleAdapter adapter = new SimpleAdapter(context, data, R.layout.single_choice_list_item, from, to);

    adapter.setViewBinder(new ViewBinder() {

        @Override
        public boolean setViewValue(View view, Object data, String textRepresentation) {
            ((CheckedTextView) view).setText((String) data);
            return true;
        }
    });

    mListView.setAdapter(adapter);

    if (mSelectedIndex >= 0 && mSelectedIndex < mChoices.size() + mCustomChoices.size()) {
        mListView.setItemChecked(mSelectedIndex, true);
    }

    mListView.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

            if (position == mListView.getCount() - 1) {
                showAddItemControls(context, true);
                mSelectedIndex = -1;
                mLastIndex = mListView.getLastVisiblePosition();
                View v = mListView.getChildAt(mLastIndex);
                mLastTop = (v == null) ? 0 : v.getTop();
                mListView.setSelectionFromTop(mLastIndex, mLastTop);
            } else {
                //Map<String, String> map = (HashMap<String, String>) parent.getItemAtPosition(position);
                //mSelectedKey = map.get("key");
                mSelectedIndex = position;
                //((SurveyActivity)context).setResponse(index, id, value)
            }
        }
    });

    mListView.setSelectionFromTop(mLastIndex, mLastTop);

    return mListView;
}

From source file:org.ohmage.prompt.multichoicecustom.MultiChoiceCustomPrompt.java

@Override
public View getView(final Context context) {

    mCustomChoices.clear();//w w w  .  j av a 2s  .c  o m
    MultiChoiceCustomDbAdapter dbAdapter = new MultiChoiceCustomDbAdapter(context);
    String surveyId = ((SurveyActivity) context).getSurveyId();
    SharedPreferencesHelper prefs = new SharedPreferencesHelper(context);
    String campaignUrn = ((SurveyActivity) context).getCampaignUrn();
    String username = prefs.getUsername();
    if (dbAdapter.open()) {
        Cursor c = dbAdapter.getCustomChoices(username, campaignUrn, surveyId,
                MultiChoiceCustomPrompt.this.getId());
        c.moveToFirst();
        for (int i = 0; i < c.getCount(); i++) {
            //c.getLong(c.getColumnIndex(MultiChoiceCustomDbAdapter.KEY_ID));
            int key = c.getInt(c.getColumnIndex(MultiChoiceCustomDbAdapter.KEY_CHOICE_ID));
            String label = c.getString(c.getColumnIndex(MultiChoiceCustomDbAdapter.KEY_CHOICE_VALUE));
            mCustomChoices.add(new KVLTriplet(String.valueOf(key), null, label));
            c.moveToNext();
        }
        c.close();
        dbAdapter.close();
    }

    LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    //      mListView = (ListView) inflater.inflate(R.layout.prompt_single_choice_custom, null);
    mListView = new CustomChoiceListView(context);
    mListView.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
    mListView.setTextFilterEnabled(false);

    mListView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
    mListView.setDescendantFocusability(ViewGroup.FOCUS_AFTER_DESCENDANTS);

    mFooterView = inflater.inflate(R.layout.custom_choice_footer, null);

    EditText mEditText = (EditText) mFooterView.findViewById(R.id.new_choice_edit);
    ImageButton mButton = (ImageButton) mFooterView.findViewById(R.id.ok_button);
    ImageButton mCancelButton = (ImageButton) mFooterView.findViewById(R.id.cancel_button);

    showAddItemControls(context, mIsAddingNewItem);

    mButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {

            if (mEnteredText != null && !mEnteredText.equals("")) {
                MultiChoiceCustomDbAdapter dbAdapter = new MultiChoiceCustomDbAdapter(context);
                String surveyId = ((SurveyActivity) context).getSurveyId();
                SharedPreferencesHelper prefs = new SharedPreferencesHelper(context);
                String campaignUrn = ((SurveyActivity) context).getCampaignUrn();
                String username = prefs.getUsername();

                int choiceId = 100;
                ArrayList<String> keys = new ArrayList<String>();
                for (KVLTriplet choice : mChoices) {
                    keys.add(choice.key.trim());
                }
                for (KVLTriplet choice : mCustomChoices) {
                    keys.add(choice.key.trim());
                }
                while (keys.contains(String.valueOf(choiceId))) {
                    choiceId++;
                }

                if (dbAdapter.open()) {
                    dbAdapter.addCustomChoice(choiceId, mEnteredText, username, campaignUrn, surveyId,
                            MultiChoiceCustomPrompt.this.getId());
                    dbAdapter.close();
                }

                showAddItemControls(context, false);

                mSelectedIndexes.add(Integer.valueOf(mListView.getCount() - 1));

                ((SurveyActivity) context).reloadCurrentPrompt();
            } else {
                Toast.makeText(context, "Please enter some text", Toast.LENGTH_SHORT).show();
            }
        }
    });

    mCancelButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            //            EditText edit = (EditText) mFooterView.findViewById(R.id.new_choice_edit);
            showAddItemControls(context, false);
        }
    });

    mEditText.addTextChangedListener(new TextWatcher() {

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            // TODO Auto-generated method stub

        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            // TODO Auto-generated method stub

        }

        @Override
        public void afterTextChanged(Editable s) {
            // TODO Auto-generated method stub
            mEnteredText = s.toString();
            //            mListView.setSelectionFromTop(mLastIndex, mLastTop);
            //            EditText editText = (EditText) mFooterView.findViewById(R.id.new_choice_edit);
            //            editText.requestFocus();
        }
    });

    mListView.addFooterView(mFooterView);

    String[] from = new String[] { "value" };
    int[] to = new int[] { android.R.id.text1 };

    List<HashMap<String, String>> data = new ArrayList<HashMap<String, String>>();
    for (int i = 0; i < mChoices.size(); i++) {
        HashMap<String, String> map = new HashMap<String, String>();
        map.put("key", mChoices.get(i).key);
        map.put("value", mChoices.get(i).label);
        data.add(map);
    }
    for (int i = 0; i < mCustomChoices.size(); i++) {
        HashMap<String, String> map = new HashMap<String, String>();
        map.put("key", mCustomChoices.get(i).key);
        map.put("value", mCustomChoices.get(i).label);
        data.add(map);
    }

    SimpleAdapter adapter = new SimpleAdapter(context, data, R.layout.multi_choice_list_item, from, to);

    adapter.setViewBinder(new ViewBinder() {

        @Override
        public boolean setViewValue(View view, Object data, String textRepresentation) {
            ((CheckedTextView) view).setText((String) data);
            return true;
        }
    });

    mListView.setAdapter(adapter);

    if (mSelectedIndexes.size() > 0) {
        for (int index : mSelectedIndexes) {
            if (index >= 0 && index < mChoices.size() + mCustomChoices.size())
                mListView.setItemChecked(index, true);
        }
    }

    mListView.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

            if (position == mListView.getCount() - 1) {
                showAddItemControls(context, true);
                mLastIndex = mListView.getLastVisiblePosition();
                View v = mListView.getChildAt(mLastIndex);
                mLastTop = (v == null) ? 0 : v.getTop();
                mListView.setSelectionFromTop(mLastIndex, mLastTop);
            } else {
                //SparseBooleanArray checkItemPositions = ((ListView)parent).getCheckedItemPositions();
                if (((ListView) parent).isItemChecked(position)) {
                    mSelectedIndexes.add(Integer.valueOf(position));
                } else {
                    mSelectedIndexes.remove(Integer.valueOf(position));
                }
            }
        }
    });

    mListView.setSelectionFromTop(mLastIndex, mLastTop);

    return mListView;
}

From source file:edu.rutgers.winlab.crowdpp.ui.SettingsFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    settings = getActivity().getSharedPreferences("config", Context.MODE_PRIVATE);
    editor = settings.edit();// www  .  j av a2  s  .c o m

    title = new String[] { "Period", "Interval", "Duration", "Location", "Upload", "Project page", "Contact me",
            "Version" };

    content = new String[] { "Specify when you want the service run every day.",
            "Specify how frequently you want the service to run.",
            "Specify how long you want to record every time.",
            "Specify if you want the location data be collected.",
            "Specify if you want to contribute the data to the cloud.",
            "Brings you to the project page. Please leave a comment.",
            "Report a bug or send your comment via email.", "1.0" };

    choice = new String[] {
            settings.getString("start", "").concat(" to ").concat(settings.getString("end", "")),
            settings.getString("interval", "").concat(" Min"),
            settings.getString("duration", "").concat(" Min"), settings.getString("location", ""),
            settings.getString("upload", ""), "", "", "" };

    ArrayList<HashMap<String, String>> listItem = new ArrayList<HashMap<String, String>>();

    for (int i = 0; i < title.length; i++) {
        HashMap<String, String> map = new HashMap<String, String>();
        map.put("tv_settings_title", title[i]);
        map.put("tv_settings_content", content[i]);
        map.put("tv_settings_choice", choice[i]);
        listItem.add(map);
    }

    // bind the listview adapter with the setting content
    SimpleAdapter mSimpleAdapter = new SimpleAdapter(inflater.getContext(), listItem, R.layout.settings_item,
            new String[] { "tv_settings_title", "tv_settings_content", "tv_settings_choice" },
            new int[] { R.id.tv_settings_title, R.id.tv_settings_content, R.id.tv_settings_choice });

    setListAdapter(mSimpleAdapter);

    return super.onCreateView(inflater, container, savedInstanceState);
}

From source file:com.saulcintero.moveon.fragments.Summary2_hiit.java

private void splitData(String[] hiit, ArrayList<int[]> hiit_intervals) {
    DBManager = new DataManager(mContext);
    DBManager.Open();//from   w ww.j  a va  2s .  c o  m

    if (hiit_intervals.size() > 0) {
        List<HashMap<String, String>> mList = new ArrayList<HashMap<String, String>>();

        float last_distance = 0;
        float last_time = 0;
        boolean havePrepTime = false, haveCooldownTime = false;

        int loops = (hiit_intervals.size() * Integer.parseInt(hiit[1]));

        if (Integer.parseInt(hiit[2]) > 0) {
            havePrepTime = true;
            loops += 1;
        }

        if (Integer.parseInt(hiit[3]) > 0) {
            haveCooldownTime = true;
            loops += 1;
        }

        for (int i = 0; i < loops; i++) {
            if (i == 0) {
                if (havePrepTime) {
                    cursor = DBManager.CustomQuery(
                            getString(R.string.summary2_hiit_query_part1) + " " + accum_intervals_seconds + " "
                                    + getString(R.string.summary2_hiit_query_part2) + " "
                                    + (accum_intervals_seconds + hiit_intervals.get(actions)[1]) + " "
                                    + getString(R.string.summary2_hiit_query_part3),
                            "SELECT * FROM locations WHERE _id = '" + id + "' AND time BETWEEN "
                                    + accum_intervals_seconds + " AND " + (accum_intervals_seconds + hiit[2]));
                } else {
                    cursor = DBManager.CustomQuery(
                            getString(R.string.summary2_hiit_query_part1) + " " + accum_intervals_seconds + " "
                                    + getString(R.string.summary2_hiit_query_part2) + " "
                                    + +(accum_intervals_seconds + hiit_intervals.get(actions)[1]) + " "
                                    + getString(R.string.summary2_hiit_query_part3),
                            "SELECT * FROM locations WHERE _id = '" + id + "' AND time BETWEEN "
                                    + accum_intervals_seconds + " AND "
                                    + (accum_intervals_seconds + hiit_intervals.get(actions)[1]));
                }
            } else {
                if (haveCooldownTime && (i == (loops - 1))) {
                    cursor = DBManager.CustomQuery(
                            getString(R.string.summary2_hiit_query_part1) + " " + accum_intervals_seconds + " "
                                    + getString(R.string.summary2_hiit_query_part2) + " "
                                    + (accum_intervals_seconds + Integer.parseInt(hiit[3])) + " "
                                    + getString(R.string.summary2_hiit_query_part3),
                            "SELECT * FROM locations WHERE _id = '" + id + "' AND time BETWEEN "
                                    + accum_intervals_seconds + " AND "
                                    + (accum_intervals_seconds + Integer.parseInt(hiit[3])));
                } else {
                    cursor = DBManager.CustomQuery(
                            getString(R.string.summary2_hiit_query_part1) + " " + accum_intervals_seconds + " "
                                    + getString(R.string.summary2_hiit_query_part2) + " "
                                    + (accum_intervals_seconds + hiit_intervals.get(actions)[1]) + " "
                                    + getString(R.string.summary2_hiit_query_part3),
                            "SELECT * FROM locations WHERE _id = '" + id + "' AND time BETWEEN "
                                    + accum_intervals_seconds + " AND "
                                    + (accum_intervals_seconds + hiit_intervals.get(actions)[1]));
                }
            }

            float distance = 0;
            float time = 0;

            cursor.moveToFirst();
            while (!cursor.isAfterLast()) {
                if (cursor.isLast())
                    distance = (isMetric ? distance + cursor.getFloat(cursor.getColumnIndex("distance"))
                            : distance
                                    + ((cursor.getFloat(cursor.getColumnIndex("distance")) * 1000f) / 1609f));

                cursor.moveToNext();
            }

            if (distance < last_distance)
                distance = last_distance;

            HashMap<String, String> hm = new HashMap<String, String>();
            if ((i == 0) && (Integer.parseInt(hiit[2]) > 0)) {
                hm.put("summary2_icon", String.valueOf(R.drawable.hiit_gray));
            } else {
                if ((Integer.parseInt(hiit[3]) > 0) && (i == (loops - 1))) {
                    hm.put("summary2_icon", String.valueOf(R.drawable.hiit_blue));
                } else {
                    switch (hiit_intervals.get(actions)[0]) {
                    case 1:
                        hm.put("summary2_icon", String.valueOf(R.drawable.hiit_green));
                        break;
                    case 2:
                        hm.put("summary2_icon", String.valueOf(R.drawable.hiit_yellow));
                        break;
                    case 3:
                        hm.put("summary2_icon", String.valueOf(R.drawable.hiit_orange));
                        break;
                    case 4:
                        hm.put("summary2_icon", String.valueOf(R.drawable.hiit_red));
                        break;
                    }
                }
            }
            hm.put("summary2_distance",
                    String.valueOf(FunctionUtils.customizedRound(((distance - last_distance)), 2)));

            if ((i == 0) && ((Integer.parseInt(hiit[2]) > 0))) {
                if (Integer.parseInt(hiit[2]) < 3600)
                    hm.put("summary2_time", FunctionUtils.shortFormatTime(Long.parseLong(hiit[2])));
                else
                    hm.put("summary2_time", FunctionUtils.longFormatTime(Long.parseLong(hiit[2])));
            } else {
                if ((Integer.parseInt(hiit[3]) > 0) && (i == (loops - 1))) {
                    if (Integer.parseInt(hiit[0]) < 3600)
                        hm.put("summary2_time", FunctionUtils.shortFormatTime(Long.parseLong(hiit[0])));
                    else
                        hm.put("summary2_time", FunctionUtils.longFormatTime(Long.parseLong(hiit[0])));
                } else {
                    if ((accum_intervals_seconds + hiit_intervals.get(actions)[1]) < 3600)
                        hm.put("summary2_time", FunctionUtils
                                .shortFormatTime((accum_intervals_seconds + hiit_intervals.get(actions)[1])));
                    else
                        hm.put("summary2_time", FunctionUtils
                                .longFormatTime((accum_intervals_seconds + hiit_intervals.get(actions)[1])));
                }
            }

            if ((i == 0) && ((Integer.parseInt(hiit[2]) > 0))) {
                time = (long) (Long.parseLong(hiit[2]));
            } else {
                if ((Integer.parseInt(hiit[3]) > 0) && (i == (loops - 1)))
                    time = (long) (accum_intervals_seconds + Integer.parseInt(hiit[3]));
                else
                    time = (long) (accum_intervals_seconds + hiit_intervals.get(actions)[1]);
            }

            hm.put("summary2_ritm",
                    String.valueOf(FunctionUtils.calculateRitm(mContext, (long) (time - last_time),
                            String.valueOf((isMetric ? distance - last_distance
                                    : (FunctionUtils.getKilometersFromMiles(distance)
                                            - FunctionUtils.getKilometersFromMiles(last_distance)))),
                            isMetric, false)));
            mList.add(hm);

            if ((i == 0) && ((Integer.parseInt(hiit[2]) > 0)))
                accum_intervals_seconds = Integer.parseInt(hiit[2]);
            else
                accum_intervals_seconds = accum_intervals_seconds + hiit_intervals.get(actions)[1];

            last_distance = distance;
            last_time = time;

            if (((i == 0) && (!havePrepTime)) || (i > 0)) {
                if (actions < (hiit_intervals.size() - 1)) {
                    actions += 1;
                } else {
                    actions = 0;
                }
            }

        }

        String[] from = { "summary2_icon", "summary2_distance", "summary2_time", "summary2_ritm" };
        int[] to = { R.id.summary2_icon, R.id.summary2_long_unit, R.id.summary2_time, R.id.summary2_ritm };

        SimpleAdapter adapter = new SimpleAdapter(mContext, mList, R.layout.summary2_list_row, from, to);
        summary2ListView.setAdapter(adapter);

        cursor.close();
    }

    DBManager.Close();
}

From source file:subhamguptaminor.androidbelieve.drawerwithswipetabs.CardFlipActivity.java

protected void showList() {
    try {//w  w w  .jav  a  2s  . c o  m
        JSONObject jsonObj = new JSONObject(myJSON);
        peoples = jsonObj.getJSONArray(TAG_RESULTS);

        for (int i = 0; i < peoples.length(); i++) {
            JSONObject c = peoples.getJSONObject(i);
            String ques = c.getString(TAG_QUES);

            HashMap<String, String> persons = new HashMap<String, String>();

            persons.put(TAG_QUES, ques);

            personList.add(persons);
        }

        ListAdapter adapter = new SimpleAdapter(CardFlipActivity.this, personList, R.layout.list_quest,
                new String[] { TAG_QUES }, new int[] { R.id.question });

        list.setAdapter(adapter);
        Toast.makeText(this, "Updating", Toast.LENGTH_SHORT).show();

    } catch (JSONException e) {
        e.printStackTrace();
    }

}

From source file:com.misterpereira.android.kiteplayer.ui.ActionBarCastActivity.java

private void populateDrawerItems() {

    mDrawerMenuContents = new DrawerMenuContents(this, mDBApi);
    final int selectedPosition = mDrawerMenuContents.getPosition(this.getClass());

    SimpleAdapter adapter = new SimpleAdapter(this, mDrawerMenuContents.getItems(), R.layout.drawer_list_item,
            new String[] { DrawerMenuContents.FIELD_TITLE, DrawerMenuContents.FIELD_ICON },
            new int[] { R.id.drawer_item_title, R.id.drawer_item_icon });

    mDrawerList.setOnItemClickListener((parent, view, position, id) -> {
        if (position != selectedPosition) {
            mItemToOpenWhenDrawerCloses = position;
        }/*from  w  w w .  j a v a 2  s .co m*/
        mDrawerList.setItemChecked(position, true);
        mDrawerLayout.closeDrawers();
    });
    mDrawerList.setAdapter(adapter);
    mDrawerList.post(() -> mDrawerList.setItemChecked(selectedPosition, true));
}