Example usage for android.widget ArrayAdapter ArrayAdapter

List of usage examples for android.widget ArrayAdapter ArrayAdapter

Introduction

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

Prototype

public ArrayAdapter(@NonNull Context context, @LayoutRes int resource, @NonNull List<T> objects) 

Source Link

Document

Constructor

Usage

From source file:Main.java

public static ArrayAdapter<String> getSpinnerAdapter(Context context, String[] datas) {
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(context, android.R.layout.simple_spinner_item,
            datas);//from   ww  w . j av  a  2s.  co  m
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    return adapter;
}

From source file:Main.java

public static void fillSpinner(Context ctx, Spinner spinner, String[] data) {
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(ctx, android.R.layout.simple_spinner_item, data);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinner.setAdapter(adapter);/*from  w w w  . j a  va2  s  .c  om*/
}

From source file:Main.java

public static void fillList(Context context, ListView lv, List<String> ls) {
    ArrayAdapter<String> adapter = new ArrayAdapter<>(context, android.R.layout.simple_list_item_1, ls);
    lv.setAdapter(adapter);//from  w ww . j av  a  2 s .c o m
}

From source file:Main.java

public static void SetSpinnerData(int redID, List<String> list, View view) {
    Spinner spinner = (Spinner) view.findViewById(redID);
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(view.getContext(),
            android.R.layout.simple_spinner_item, list);

    spinner.setAdapter(adapter);//from  w w w  .j  a v  a 2 s  .  c o  m
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
}

From source file:Main.java

public static void fillSpinner(Context context, Spinner lv, List<String> ls) {
    SpinnerAdapter adapter = new ArrayAdapter(context, android.R.layout.simple_spinner_item, ls);
    lv.setAdapter(adapter);//w  w  w.j a  va 2 s . c om
}

From source file:Main.java

public static void fillGrid(Context context, GridView lv, List<Drawable> ls) {
    ArrayAdapter<Drawable> adapter = new ArrayAdapter<>(context, android.R.layout.simple_list_item_1, ls);
    lv.setAdapter(adapter);/*  w  ww.j  a  v a 2s  .  c o m*/
}

From source file:Main.java

/**
 * Carica i dati di uno spinner con la lista passata
 * @param context - Context//from   w w  w.  j av a 2  s. c  om
 * @param spinner - Spinner da caricare
 * @param data - List di stringhe con cuoi caricare lo spinner
 * @param selectedPosition - Posizione di selezione (minimo zero)
 */
public static void setSpinnerData(Context context, Spinner spinner, List<String> data, int selectedPosition) {
    if (selectedPosition < 0)
        selectedPosition = 0;
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(context, android.R.layout.simple_spinner_item,
            data);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinner.setAdapter(adapter);
    spinner.setSelection(selectedPosition);
}

From source file:MainActivity.java

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

    ListView listSigns = getListView();
    ArrayAdapter<Zodiac> listAdapter = new ArrayAdapter<Zodiac>(this, android.R.layout.simple_list_item_1,
            Zodiac.signs);//  w w  w. j  a  v a  2  s.co  m
    listSigns.setAdapter(listAdapter);
}

From source file:Main.java

/**
 * Creates a standard Android adapter.  Input items can be of any type.
 * //  ww w.  j  a  v  a 2s.  c o  m
 * @param context Context with which to create the adapter
 * @param layoutId Android resource id to be used for a list row
 * @param items List of items to populate the adapter with
 * @return The created adapter
 */
public static <E> ArrayAdapter<E> createAdapter(Context context, int layoutId, List<E> items) {
    return new ArrayAdapter<E>(context, layoutId, items);
}

From source file:MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    String[] countries = new String[] { "China", "France", "Germany", "India", "Russia", "United Kingdom",
            "United States" };
    ListAdapter countryAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, countries);
    setListAdapter(countryAdapter);//  ww w . j  a v  a2s.  co  m

    getListView().setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            String s = ((TextView) view).getText() + " " + position;
            Toast.makeText(getApplicationContext(), s, Toast.LENGTH_SHORT).show();
        }
    });
}