List of usage examples for android.widget ListView setItemChecked
public void setItemChecked(int position, boolean value)
From source file:com.example.flashcards.wizardpager.wizard.ui.SingleChoiceFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { Log.d(LOG_TAG, "getSctivity() " + getActivity()); View rootView = inflater.inflate(R.layout.fragment_page, container, false); ((TextView) rootView.findViewById(android.R.id.title)).setText(mPage.getTitle()); final ListView listView = (ListView) rootView.findViewById(android.R.id.list); setListAdapter(new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_single_choice, android.R.id.text1, mChoices)); listView.setChoiceMode(ListView.CHOICE_MODE_SINGLE); // Pre-select currently selected item. new Handler().post(new Runnable() { @Override/*from www .java 2 s .c o m*/ public void run() { String selection = mPage.getData().getString(Page.SIMPLE_DATA_KEY); for (int i = 0; i < mChoices.size(); i++) { if (mChoices.get(i).equals(selection)) { listView.setItemChecked(i, true); break; } } } }); return rootView; }
From source file:com.sharpcart.android.wizardpager.wizard.ui.SingleChoiceFragment.java
@Override public View onCreateView(final LayoutInflater inflater, final ViewGroup container, final Bundle savedInstanceState) { final View rootView = inflater.inflate(R.layout.fragment_page, container, false); ((TextView) rootView.findViewById(android.R.id.title)).setText(mPage.getTitle()); final ListView listView = (ListView) rootView.findViewById(android.R.id.list); setListAdapter(new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_single_choice, android.R.id.text1, mChoices)); listView.setChoiceMode(AbsListView.CHOICE_MODE_SINGLE); // Pre-select currently selected item. new Handler().post(new Runnable() { @Override/*from w ww. j a va 2s. co m*/ public void run() { final String selection = mPage.getData().getString(Page.SIMPLE_DATA_KEY); for (int i = 0; i < mChoices.size(); i++) { if (mChoices.get(i).equals(selection)) { listView.setItemChecked(i, true); break; } } } }); return rootView; }
From source file:io.jari.geenstijl.Blog.java
void initUI(final Artikel[] artikelen, final boolean doSwitchState) { final PullToRefreshLayout mPullToRefreshLayout = (PullToRefreshLayout) findViewById(R.id.ptr_layout); runOnUiThread(new Runnable() { public void run() { ListView siteSwitch = (ListView) findViewById(R.id.site_switcher); String domain = getSharedPreferences("geenstijl", 0).getString("gsdomain", "www.geenstijl.nl"); if (domain.equals("www.geenstijl.nl")) { actionBar.setTitle("GeenStijl"); siteSwitch.setItemChecked(0, true); } else { actionBar.setTitle("GeenStijl.TV"); siteSwitch.setItemChecked(1, true); }//from w ww . jav a 2s. co m final ListView show = (ListView) findViewById(R.id.show); if (showTopPadding == 0) showTopPadding = show.getPaddingTop(); show.setScrollingCacheEnabled(false); show.setAdapter(new ArtikelAdapter(Blog.this, 0, artikelen)); //#HOLOYOLO if (Build.VERSION.SDK_INT >= 19) { SystemBarTintManager.SystemBarConfig config = tintManager.getConfig(); show.setPadding(0, showTopPadding + config.getPixelInsetTop(true), 0, 0); } //hiding the actionbar when scrolling show.setOnScrollListener(new AbsListView.OnScrollListener() { int mLastFirstVisibleItem = 0; public void onScrollStateChanged(AbsListView view, int scrollState) { } public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { if (view.getId() == show.getId()) { final int currentFirstVisibleItem = show.getFirstVisiblePosition(); if (currentFirstVisibleItem > mLastFirstVisibleItem && actionBar.isShowing()) { enableImmersive(true, show); } else if (currentFirstVisibleItem < mLastFirstVisibleItem && !actionBar.isShowing()) { enableImmersive(false, show); } mLastFirstVisibleItem = currentFirstVisibleItem; } } }); //footer if (show.getAdapter().getClass() != HeaderViewListAdapter.class) { //check if footer is present, if not, add it View footer = getLayoutInflater().inflate(R.layout.meerrr, null); final View button = footer.findViewById(R.id.more); if (Build.VERSION.SDK_INT >= 19) { ViewGroup.LayoutParams params = button.getLayoutParams(); SystemBarTintManager.SystemBarConfig config = tintManager.getConfig(); ((ViewGroup.MarginLayoutParams) params).bottomMargin = config.getPixelInsetBottom(); } button.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { button.setEnabled(false); mPullToRefreshLayout.setRefreshing(true); enableImmersive(false, show); forceNoImmersive = true; new Thread(new Runnable() { public void run() { try { final Artikel[] artikelen2 = API.getArticles(true, true, getApplicationContext()); runOnUiThread(new Runnable() { public void run() { ListView show = (ListView) findViewById(R.id.show); //java is such a beautiful language *cough* ArtikelAdapter artikelAdapter = (ArtikelAdapter) ((HeaderViewListAdapter) show .getAdapter()).getWrappedAdapter(); artikelAdapter.update(artikelen2); mPullToRefreshLayout.setRefreshComplete(); button.setVisibility(View.GONE); forceNoImmersive = false; } }); } catch (final Exception e) { e.printStackTrace(); runOnUiThread(new Runnable() { public void run() { button.setEnabled(true); mPullToRefreshLayout.setRefreshComplete(); forceNoImmersive = false; Crouton.makeText(Blog.this, e.getLocalizedMessage() == null ? "Onbekende fout" : e.getLocalizedMessage(), Style.ALERT).show(); } }); } } }).start(); } }); show.addFooterView(footer); } //grreat success! if (doSwitchState) switchState(STATE_SHOW); else mPullToRefreshLayout.setRefreshComplete(); } }); }
From source file:de.bennir.DVBViewerController.wizard.ui.SingleChoiceFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_page, container, false); String title = null;//from ww w. j a va2s . c o m try { title = getString(getResources().getIdentifier(mKey, "string", "de.bennir.DVBViewerController")); } catch (Exception e) { e.printStackTrace(); } if (title == null) ((TextView) rootView.findViewById(android.R.id.title)).setText(mPage.getTitle()); else ((TextView) rootView.findViewById(android.R.id.title)).setText(title); final ListView listView = (ListView) rootView.findViewById(android.R.id.list); setListAdapter(new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_single_choice, android.R.id.text1, mChoices)); listView.setChoiceMode(ListView.CHOICE_MODE_SINGLE); // Pre-select currently selected item. new Handler().post(new Runnable() { @Override public void run() { String selection = mPage.getData().getString(Page.SIMPLE_DATA_KEY); for (int i = 0; i < mChoices.size(); i++) { if (mChoices.get(i).equals(selection)) { listView.setItemChecked(i, true); break; } } } }); return rootView; }
From source file:com.lastsoft.plog.wizard.ui.SingleChoiceFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_page, container, false); ((TextView) rootView.findViewById(android.R.id.title)).setText(mPage.getTitle()); final ListView listView = (ListView) rootView.findViewById(android.R.id.list); setListAdapter(new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_single_choice, android.R.id.text1, mChoices)); listView.setChoiceMode(ListView.CHOICE_MODE_SINGLE); // Pre-select currently selected item. new Handler().post(new Runnable() { @Override/*from w w w.j av a2 s .co m*/ public void run() { String selection = mPage.getData().getString(Page.SIMPLE_DATA_KEY); for (int i = 0; i < mChoices.size(); i++) { if (mChoices.get(i).equals(selection)) { listView.setItemChecked(i, true); break; } } } }); return rootView; }
From source file:com.wizard.ui.SingleChoiceFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_page, container, false); ((TextView) rootView.findViewById(android.R.id.title)).setText(mPage.getTitle()); final ListView listView = (ListView) rootView.findViewById(android.R.id.list); setListAdapter(new ArrayAdapter<String>(getActivity(), //android.R.layout.simple_list_item_single_choice, R.layout.mylist, android.R.id.text1, mChoices)); listView.setChoiceMode(ListView.CHOICE_MODE_SINGLE); // Pre-select currently selected item. new Handler().post(new Runnable() { @Override/*w w w. j a v a 2 s . com*/ public void run() { String selection = mPage.getData().getString(Page.SIMPLE_DATA_KEY); for (int i = 0; i < mChoices.size(); i++) { if (mChoices.get(i).equals(selection)) { listView.setItemChecked(i, true); break; } } } }); return rootView; }
From source file:ni.org.ics.estudios.appmovil.wizard.ui.SingleChoiceFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_page, container, false); mTitleTextInput = (TextView) rootView.findViewById(android.R.id.title); mTitleTextInput.setText(mPage.getTitle()); if (!mPage.ismEnabled()) { mTitleTextInput.setTextColor(Color.GRAY); } else {// w w w. j a v a2 s .c o m mTitleTextInput.setTextColor(Color.parseColor(mPage.getTextColor())); } mHintTextInput = (TextView) rootView.findViewById(R.id.label_hint); mHintTextInput.setText(mPage.getHint()); mHintTextInput.setTextColor(Color.parseColor(mPage.getmHintTextColor())); final ListView listView = (ListView) rootView.findViewById(android.R.id.list); setListAdapter(new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_single_choice, android.R.id.text1, mChoices)); listView.setChoiceMode(AbsListView.CHOICE_MODE_SINGLE); listView.setEnabled(mPage.ismEnabled()); // Pre-select currently selected item. new Handler().post(new Runnable() { @Override public void run() { String selection = mPage.getData().getString(Page.SIMPLE_DATA_KEY); for (int i = 0; i < mChoices.size(); i++) { if (mChoices.get(i).equals(selection)) { listView.setItemChecked(i, true); break; } } } }); return rootView; }
From source file:com.example.flashcards.wizardpager.wizard.ui.TopicChoiceFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { Log.d(LOG_TAG, "TopicFragment onCreateView"); View rootView = inflater.inflate(R.layout.fragment_page, container, false); Log.d(LOG_TAG, "TopicFragment infalted"); ((TextView) rootView.findViewById(android.R.id.title)).setText(mPage.getTitle()); final ListView listView = (ListView) rootView.findViewById(android.R.id.list); setListAdapter(new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_single_choice, android.R.id.text1, mChoices)); listView.setChoiceMode(ListView.CHOICE_MODE_SINGLE); // Pre-select currently selected item. new Handler().post(new Runnable() { @Override//from ww w . j a va2s . c om public void run() { String selection = mPage.getData().getString(Page.SIMPLE_DATA_KEY); for (int i = 0; i < mChoices.size(); i++) { if (mChoices.get(i).equals(selection)) { listView.setItemChecked(i, true); break; } } } }); return rootView; }
From source file:org.opendatakit.survey.android.fragments.InstanceUploaderListFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { view = inflater.inflate(ID, container, false); // set up long click listener mUploadButton = (Button) view.findViewById(R.id.upload_button); mUploadButton.setOnClickListener(new OnClickListener() { @Override/*ww w . j av a 2 s .c om*/ public void onClick(View arg0) { ConnectivityManager connectivityManager = (ConnectivityManager) getActivity() .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo ni = connectivityManager.getActiveNetworkInfo(); if (ni == null || !ni.isConnected()) { Toast.makeText(getActivity(), R.string.no_connection, Toast.LENGTH_SHORT).show(); } else { // items selected uploadSelectedFiles(); mToggled = false; mSelected.clear(); clearChoices(); } } }); mToggleButton = (Button) view.findViewById(R.id.toggle_button); mToggleButton.setLongClickable(true); mToggleButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // toggle selections of items to all or none ListView ls = getListView(); mToggled = !mToggled; // remove all items from selected list mSelected.clear(); for (int pos = 0; pos < ls.getCount(); pos++) { ls.setItemChecked(pos, mToggled); // add all items if mToggled sets to select all if (mToggled) { Cursor c = (Cursor) ls.getItemAtPosition(pos); String uuid = ODKDatabaseUtils.get().getIndexAsString(c, c.getColumnIndex(InstanceColumns._ID)); mSelected.add(uuid); } } mUploadButton.setEnabled(!(mSelected.size() == 0)); } }); mToggleButton.setOnLongClickListener(this); if (savedInstanceState != null) { String[] selectedArray = savedInstanceState.getStringArray(BUNDLE_SELECTED_ITEMS_KEY); for (int i = 0; i < selectedArray.length; i++) mSelected.add(selectedArray[i]); // indicating whether or not select-all is on or off. if (savedInstanceState.containsKey(BUNDLE_TOGGLED_KEY)) { mToggled = savedInstanceState.getBoolean(BUNDLE_TOGGLED_KEY); } // to restore alert dialog. if (savedInstanceState.containsKey(DIALOG_TITLE)) { mAlertTitle = savedInstanceState.getString(DIALOG_TITLE); } if (savedInstanceState.containsKey(DIALOG_MSG)) { mAlertMsg = savedInstanceState.getString(DIALOG_MSG); } if (savedInstanceState.containsKey(DIALOG_STATE)) { mDialogState = DialogState.valueOf(savedInstanceState.getString(DIALOG_STATE)); } if (savedInstanceState.containsKey(SHOW_UNSENT)) { mShowUnsent = savedInstanceState.getBoolean(SHOW_UNSENT); } if (savedInstanceState.containsKey(URL)) { mUrl = URI.create(savedInstanceState.getString(URL)); } } mUploadButton.setEnabled(!(mSelected.size() == 0)); return view; }
From source file:com.ht.app.RestaurantsActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { if (mDrawerToggle.onOptionsItemSelected(item)) { return true; }//from www .jav a2s . co m final String cuisines[] = getResources().getStringArray(R.array.cuisines_titles); List<String> cl = Arrays.asList(cuisines); //cl.addAll(cuisines); int id = item.getItemId(); int cuisineIndex = cl.indexOf(mCurrentSelectedCuisine); if (id == R.id.action_cusines) { AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle(R.string.title_dialog_cuisines).setSingleChoiceItems(R.array.cuisines_titles, cuisineIndex >= 0 ? cuisineIndex : 0, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { // String cuisine mCurrentSelectedCuisine = cuisines[which]; } }); builder.setNegativeButton(R.string.btn_clear_all_text, null); builder.setPositiveButton(R.string.btn_apply_text, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { dialog = null; if (mCuisineUrls.containsKey(mCurrentSelectedCuisine)) { mCuisineUrl = mCuisineUrls.get(mCurrentSelectedCuisine); } else mCuisineUrl = ""; startLoading(); } }); dialog = builder.create(); dialog.setOnShowListener(new DialogInterface.OnShowListener() { @Override public void onShow(final DialogInterface dialogInterface) { Button b = dialog.getButton(AlertDialog.BUTTON_NEGATIVE); b.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { // TODO Do something mCurrentSelectedCuisine = ""; ListView lv = dialog.getListView(); lv.setItemChecked(0, true); } }); } }); dialog.show(); return true; } return super.onOptionsItemSelected(item); }