Android ArrayAdapter - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Android ArrayAdapter class.

This code example shows how to use the following methods:getCount, getItem, isEmpty
 
import jp.mixi.compatibility.android.widget.ArrayAdapterCompat; 
 
public class ArrayAdapterCompatTest extends AndroidTestCase {
    public void testAddAllCollection() { 
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(getContext(), android.R.id.text1);
        List<String> list = new ArrayList<String>();
        list.add("test1");
        list.add("test2");
        list.add("test3");
        ArrayAdapterCompat.addAll(adapter, list);
        assertFalse(adapter.isEmpty());
        assertEquals(3, adapter.getCount());
        assertEquals("test1", adapter.getItem(0));
        assertEquals("test2", adapter.getItem(1));
        assertEquals("test3", adapter.getItem(2));
    } 
 
    public void testAddAllArray() { 
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(getContext(), android.R.id.text1);
        String[] array = new String[] {"test1", "test2", "test3"};
8
CodeRank
This code example shows how to use the following methods:getItem, insert, remove
        this.headers.add(section);  
        this.sections.put(section, adapter);  
    }   
 
    public void setSectionTitle(int section, String title) {
    	String oldTitle = this.headers.getItem(section);
 
    	// remove/add to headers array 
    	this.headers.remove(oldTitle);
    	this.headers.insert(title, section);
    	 
    	// remove/add to section map 
    	Adapter adapter = this.sections.get(oldTitle);
    	this.sections.remove(oldTitle);
    	this.sections.put(title, adapter);
    } 
     
    public Object getItem(int position) {  
        for(int i = 0; i < headers.getCount(); i++) {
        	String section = headers.getItem(i);
8
CodeRank
This code example shows how to use the following methods:
      public void onClick(View v) {
        List<String> list=Arrays.asList(items);
         
        Collections.shuffle(list);
         
        setListAdapter(new ArrayAdapter<String>(HeaderFooterDemo.this,
                            android.R.layout.simple_list_item_1,
                            list));
      } 
    }); 
     
    return(btn);
  } 
   
  private View buildFooter() {
    TextView txt=new TextView(this);
     
    updateFooter(txt);
     
    return(txt);
7
CodeRank
This code example shows how to use the following methods:add
 
	private void init() { 
		setBackgroundColor(Color.GREEN);
		 
		ListView listView = new ListView(getContext());
		ArrayAdapter<String> adapter = new ArrayAdapter<String>(getContext(),
				android.R.layout.simple_list_item_1);
		adapter.add("ListView 1 Item 1");
		adapter.add("ListView 1 Item 2");
		adapter.add("ListView 1 Item 3");
		adapter.add("ListView 1 Item 4");
		adapter.add("ListView 1 Item 5");
		adapter.add("ListView 1 Item 6");
 
		listView.setAdapter(adapter);
		 
		LayoutParams params = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
		addView(listView, params);
	} 
 
7
CodeRank
This code example shows how to use the following methods:add
	} 
 
	private void init() { 
		setBackgroundColor(Color.CYAN);
		ListView listView = new ListView(getContext());
		ArrayAdapter<String> adapter = new ArrayAdapter<String>(getContext(),
				android.R.layout.simple_list_item_1);
		adapter.add("ListView 2 Item 1");
		adapter.add("ListView 2 Item 2");
		adapter.add("ListView 2 Item 3");
		adapter.add("ListView 2 Item 4");
		adapter.add("ListView 2 Item 5");
		adapter.add("ListView 2 Item 6");
 
		listView.setAdapter(adapter);
		 
		LayoutParams params = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
		addView(listView, params);
	} 
 
7
CodeRank
This code example shows how to use the following methods:
	private ListAdapter adapter;
 
	@Override 
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, bestFoods);
		setListAdapter(adapter);
	} 
 
	@ItemClick 
	void listItemClicked(String food) {
		Toast.makeText(this, "click: " + food, Toast.LENGTH_SHORT).show();
	} 
 
	@ItemLongClick 
	void listItemLongClicked(String food) {
		Toast.makeText(this, "long click: " + food, Toast.LENGTH_SHORT).show();
	} 
 
	@ItemSelect 
7
CodeRank
This code example shows how to use the following methods:setDropDownViewResource
		} 
	} 
 
	public static ArrayAdapter<String> newSpinnerAdapter(Context cxt,
			List<String> items) {
		ArrayAdapter<String> adapter = new ArrayAdapter<String>(cxt,
				android.R.layout.simple_spinner_item, items);
		adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
		return adapter;
	} 
 
	public static void setGray(SpannableString ss, List<String> items) {
		String data = ss.toString();
		for (String item : items) {
			int i = data.indexOf("@" + item);
			if (i != -1) {
				ss.setSpan(new ForegroundColorSpan(Color.GRAY), i,
						i + 1 + item.length(),
						Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
			} 
7
CodeRank
This code example shows how to use the following methods:
	@Override 
	public void onCreate (Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		GdxTests.tests.add(MatrixTest.class); 
		List<String> testNames = GdxTests.getNames();
		setListAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, testNames));
 
		prefs = getSharedPreferences("libgdx-tests", Context.MODE_PRIVATE);
		getListView().setSelectionFromTop(prefs.getInt("index", 0), prefs.getInt("top", 0));
	} 
 
	protected void onListItemClick (ListView listView, View view, int position, long id) {
		super.onListItemClick(listView, view, position, id);
 
		Editor editor = prefs.edit();
		editor.putInt("index", listView.getFirstVisiblePosition());
		editor.putInt("top", listView.getChildAt(0) == null ? 0 : listView.getChildAt(0).getTop());
		editor.commit();
 
		Object o = this.getListAdapter().getItem(position);
7
CodeRank
This code example shows how to use the following methods:getItem
  public void onListItemClick(ListView l, View v, int position,
                              long id) {
    super.onListItemClick(l, v, position, id);
     
    if (listener!=null) {
      listener.onFeedSelected(adapter.getItem(position));
    } 
  } 
   
  public void addNewFeed(Feed feed) {
    adapter.add(feed);
  } 
 
  private void loadFeeds() { 
    adapter=new ArrayAdapter<Feed>(getActivity(), R.layout.row,
                                    Feed.getFeeds()); 
    setListAdapter(adapter);
  } 
   
  public void setOnFeedListener(OnFeedListener listener) {
7
CodeRank
This code example shows how to use the following methods:
	@Override 
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
 
        setListAdapter(new ArrayAdapter<String>(this,
                android.R.layout.simple_list_item_1, mStrings));
        getListView().setOnItemClickListener(this);
    } 
 
    private String[] mStrings = {"1. Simple", "2. Custom", "3. Tap close / Doubletap zoom"};
 
	@Override 
	public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
		Intent intent = null;
		switch (position) {
		case 0: 
			intent = new Intent(this, SimpleMap.class);
			startActivity(intent);
			break; 
		case 1: 
7
CodeRank

Related Android ArrayAdapter Questions & Answers:

Other Android ArrayAdapter Examples

19:	        
20:	        // Binding resources Array to ListAdapter
21:	        this.setListAdapter(new ArrayAdapter<String>(this, R.layout.list_item, R.id.label, adobe_products));
22:	        
23:	    }

Read More

17:		
18:		// Listview Adapter
19:		ArrayAdapter<String> adapter;
20:		
21:		// Search EditText
-
40:	        
41:	        // Adding items to listview
42:	        adapter = new ArrayAdapter<String>(this, R.layout.list_item, R.id.product_name, products);
43:	        lv.setAdapter(adapter);       
44:

Read More

19:	        
20:	        // Binding resources Array to ListAdapter
21:	        this.setListAdapter(new ArrayAdapter<String>(this, R.layout.list_item, R.id.label, adobe_products));
22:	        
23:	        ListView lv = getListView();

Read More

See Code Examples for Android ArrayAdapter Methods: