List of usage examples for android.widget ArrayAdapter add
public void add(@Nullable T object)
From source file:tech.salroid.filmy.fragment.SavedMovies.java
@Override public void itemLongClicked(final Cursor mycursor, final int position) { AlertDialog.Builder adb = new AlertDialog.Builder(getActivity()); final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<>(getActivity(), android.R.layout.simple_list_item_1); arrayAdapter.add("Remove"); final Context context = getActivity(); adb.setAdapter(arrayAdapter, new DialogInterface.OnClickListener() { @Override//from w ww .j a v a2s.c om public void onClick(DialogInterface dialogInterface, int i) { final String deleteSelection = FilmContract.SaveEntry.TABLE_NAME + "." + FilmContract.SaveEntry.SAVE_ID + " = ? AND " + FilmContract.SaveEntry.TABLE_NAME + "." + FilmContract.SaveEntry.SAVE_FLAG + " = ? "; int flag_index = mycursor.getColumnIndex(FilmContract.SaveEntry.SAVE_FLAG); int flag = mycursor.getInt(flag_index); final String[] deletionArgs = { mycursor.getString(mycursor.getColumnIndex(FilmContract.SaveEntry.SAVE_ID)), String.valueOf(flag) }; long deletion_id = context.getContentResolver().delete(FilmContract.SaveEntry.CONTENT_URI, deleteSelection, deletionArgs); if (deletion_id != -1) { mainActivityAdapter.notifyItemRemoved(position); if (mainActivityAdapter.getItemCount() == 1) my_saved_movies_recycler.setVisibility(View.GONE); } } }); adb.show(); }
From source file:org.delta.pass.SwipeRefreshChatList.java
/** * When the AsyncTask finishes, it calls onRefreshComplete(), which updates the data in the * ListAdapter and turns off the progress bar. *//*from ww w . j a v a2s .c o m*/ private void onRefreshComplete(List<String> result) { //Log.i(LOG_TAG, "onRefreshComplete"); // Remove all items from the ListAdapter, and then replace them with the new items ArrayAdapter<String> adapter = (ArrayAdapter<String>) getListAdapter(); adapter.clear(); for (String cheese : result) { adapter.add(cheese); } // Stop the refreshing indicator setRefreshing(false); }
From source file:org.deviceconnect.android.uiapp.fragment.profile.ExtraProfileFragment.java
@Override public View onCreateView(final LayoutInflater inflater, final ViewGroup container, final Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_extra_service, container, false); view.setBackgroundColor(getResources().getColor(android.R.color.background_light)); final String[] methods = { "GET", "POST", "PUT", "DELETE" }; ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_spinner_item); for (int i = 0; i < methods.length; i++) { adapter.add(methods[i]); }/* ww w.j ava 2 s. c o m*/ Spinner spinner = (Spinner) view.findViewById(R.id.spinner); spinner.setAdapter(adapter); Button sendButton = (Button) view.findViewById(R.id.fragment_extra_send); sendButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(final View view) { onClickSend(view); } }); return view; }
From source file:com.nexus.nsnik.randomno.view.fragments.dailogFragments.AboutDialogFragment.java
private void showLibrariesList() { if (getActivity() != null) { AlertDialog.Builder choosePath = new AlertDialog.Builder(getActivity()); choosePath.setTitle(getActivity().getResources().getString(R.string.aboutLibrariesHead)); ArrayAdapter<String> arrayAdapter = new ArrayAdapter<>(getActivity(), android.R.layout.simple_list_item_1); for (LibraryObject libraryObject : mLibraryList) { arrayAdapter.add(libraryObject.libraryName()); }/*from ww w . j ava2s.co m*/ choosePath.setAdapter(arrayAdapter, (dialog, position) -> openUrl(mLibraryList.get(position).libraryLink())); choosePath.create().show(); } }
From source file:tech.salroid.filmy.fragment.Favorite.java
@Override public void itemLongClicked(final Cursor mycursor, final int position) { AlertDialog.Builder adb = new AlertDialog.Builder(getActivity()); final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<>(getActivity(), android.R.layout.simple_list_item_1); arrayAdapter.add("Remove"); final Context context = getActivity(); adb.setAdapter(arrayAdapter, new DialogInterface.OnClickListener() { @Override/*from w w w. j av a2 s. co m*/ public void onClick(DialogInterface dialogInterface, int i) { final String deleteSelection = FilmContract.SaveEntry.TABLE_NAME + "." + FilmContract.SaveEntry.SAVE_ID + " = ? AND " + FilmContract.SaveEntry.TABLE_NAME + "." + FilmContract.SaveEntry.SAVE_FLAG + " = ? "; int flag_index = mycursor.getColumnIndex(FilmContract.SaveEntry.SAVE_FLAG); int flag = mycursor.getInt(flag_index); final String[] deletionArgs = { mycursor.getString(mycursor.getColumnIndex(FilmContract.SaveEntry.SAVE_ID)), String.valueOf(flag) }; long deletion_id = context.getContentResolver().delete(FilmContract.SaveEntry.CONTENT_URI, deleteSelection, deletionArgs); if (deletion_id != -1) { mainActivityAdapter.notifyItemRemoved(position); if (mainActivityAdapter.getItemCount() == 1) my_saved_movies_recycler.setVisibility(View.GONE); } } }); adb.show(); }
From source file:own.projects.lemiroapp.OptionsActivity.java
private void setWhoStarts() { final ArrayAdapter<String> items = new ArrayAdapter<String>(this, layout.simple_list_item_1); items.add("White"); items.add("Black"); whoStartsSpinner = (Spinner) findViewById(R.id.whoStartsSpinner); whoStartsSpinner.setAdapter(items);/*from ww w .j a v a 2 s . com*/ whoStartsSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) { if (pos == 0) { options.whoStarts = Options.Color.WHITE; } else if (pos == 1) { options.whoStarts = Options.Color.BLACK; } else { Log.e("Options", "setWhoStarts Failed"); setResult(Activity.RESULT_CANCELED); finish(); } //enableOKButtonIfReady(5); } @Override public void onNothingSelected(AdapterView<?> parent) { } }); }
From source file:com.googlecode.eyesfree.utils.AccessibilityNodeInfoUtilsTest.java
public void testListWithSingleItem() throws Throwable { setContentView(R.layout.list_with_single_item); final Context context = getActivity(); final ListView list = (ListView) getViewForId(R.id.list); // Add an adapter with a single item. final ArrayAdapter<String> adapter = new ArrayAdapter<String>(context, android.R.layout.simple_list_item_1); adapter.add(context.getString(R.string.single_list_item)); runTestOnUiThread(new Runnable() { @Override//from w w w . ja va 2 s .c om public void run() { list.setAdapter(adapter); } }); waitForAccessibilityIdleSync(); final View firstItem = list.getChildAt(0); assertNotNull("Obtain first item of " + list.getChildCount(), firstItem); assertShouldFocusNode("List is not focusable", R.id.list, false); assertShouldFocusNode("First item is focusable", firstItem, true); }
From source file:own.projects.lemiroapp.OptionsActivity.java
private void setPlayerDifficultyFor(final Player player) { final ArrayAdapter<String> items = new ArrayAdapter<String>(this, layout.simple_list_item_1); items.add("Human Player"); for (Options.Difficulties diff : Options.Difficulties.values()) { items.add(diff + " Bot"); }/* w ww . j a va 2s. c o m*/ Spinner spinner = null; if (player.getColor().equals(Options.Color.WHITE)) { playerWhiteSpinner = (Spinner) findViewById(R.id.playerWhiteSpinner); spinner = playerWhiteSpinner; } else { playerBlackSpinner = (Spinner) findViewById(R.id.playerBlackSpinner); spinner = playerBlackSpinner; } spinner.setAdapter(items); spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) { if (pos == 0) { // no difficulty for human player return; } else { // -1 offset because first entry is the human player player.setDifficulty(Options.Difficulties.values()[pos - 1]); } } @Override public void onNothingSelected(AdapterView<?> parent) { } }); spinner.setClickable(true); spinner.setEnabled(true); }
From source file:tech.salroid.filmy.activities.SavedMovies.java
@Override public void itemLongClicked(final Cursor mycursor, final int position) { AlertDialog.Builder adb = new AlertDialog.Builder(SavedMovies.this); final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<>(SavedMovies.this, android.R.layout.simple_list_item_1); arrayAdapter.add("Remove"); final Context context = this; adb.setAdapter(arrayAdapter, new DialogInterface.OnClickListener() { @Override/*w w w . jav a 2 s . c o m*/ public void onClick(DialogInterface dialogInterface, int i) { final String deleteSelection = FilmContract.SaveEntry.TABLE_NAME + "." + FilmContract.SaveEntry.SAVE_ID + " = ? "; final String[] deletionArgs = { mycursor.getString(mycursor.getColumnIndex(FilmContract.SaveEntry.SAVE_ID)) }; long deletion_id = context.getContentResolver().delete(FilmContract.SaveEntry.CONTENT_URI, deleteSelection, deletionArgs); if (deletion_id != -1) { mainActivityAdapter.notifyItemRemoved(position); if (mainActivityAdapter.getItemCount() == 1) my_saved_movies_recycler.setVisibility(View.GONE); } } }); adb.show(); }
From source file:com.googlecode.eyesfree.utils.AccessibilityNodeInfoUtilsTest.java
public void testListWithNonSelectableHeader() throws Throwable { setContentView(R.layout.list_with_single_item); final Context context = getActivity(); final ListView list = (ListView) getViewForId(R.id.list); // Add a single list header. final LayoutInflater inflater = LayoutInflater.from(context); final View headerView = inflater.inflate(R.layout.list_header_row, list, false); // Add an adapter with two items. final ArrayAdapter<String> adapter = new ArrayAdapter<String>(context, android.R.layout.simple_list_item_1); adapter.add(context.getString(R.string.first_list_item)); adapter.add(context.getString(R.string.second_list_item)); runTestOnUiThread(new Runnable() { @Override//from www . j av a2 s . c o m public void run() { list.addHeaderView(headerView, mInsCtx.getString(R.string.list_header), false); list.setAdapter(adapter); } }); waitForAccessibilityIdleSync(); final View firstItem = list.getChildAt(1); final View secondItem = list.getChildAt(2); assertNotNull("Obtain first item", firstItem); assertNotNull("Obtain second item", secondItem); assertShouldFocusNode("Non-selectable header is focusable", R.id.header_item, true); assertShouldFocusNode("First item is focusable", firstItem, true); assertShouldFocusNode("Second item is focusable", secondItem, true); assertShouldFocusNode("List is not focusable", R.id.list, false); assertFocusFromHover("Non-selectable header receives focus", R.id.header_item, R.id.header_item); assertFocusFromHover("First item receives focus", firstItem, firstItem); assertFocusFromHover("Second item receives focus", secondItem, secondItem); assertFocusFromHover("List does not receive focus", R.id.list, -1); }