Best code examples for Android ListView class (android.widget.ListView)

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Android ListView class.
You can now enable Codota on your own code to easily search and navigate your Java codebase.

Android ListView examples from Open Source projects
Examples using Android ListView getAdapter method:
This code example shows how to use the following methods: getChildAt, getAdapter, performItemClick
53:	long itemId = listView.getAdapter().getItemId(TESTED_CLICKED_INDEX); 
54:	View view = listView.getChildAt(TESTED_CLICKED_INDEX); 
-
57:	listView.performItemClick(view, TESTED_CLICKED_INDEX, itemId); 
Full Snippet Info
9
CodeRank
This code example shows how to use the following methods: getChildAt, getChildCount, getAdapter, getListPaddingTop
117:	View firstChild = mListView.getChildAt(0); 
118:	if (firstChild.getTop() < this.mListView.getListPaddingTop()) { 
119:	firstChild = mListView.getChildAt(1); 
-
122:	View lastChild = mListView.getChildAt(mListView.getChildCount() - 1); 
-
129:	View newLastChild = mListView.getChildAt(mListView.getChildCount() - 1); 
-
132:	assertEquals("Wrong view in last position", mListView.getAdapter().getCount() - 1, 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: getChildAt, getChildCount, getAdapter, getHeight, getListPaddingBottom
76:	int originalCount = mListView.getChildCount(); 
-
78:	TouchUtils.scrollToBottom(this, mListView); 
-
82:	mListView.getSelectedItemPosition()); 
-
84:	View lastChild = mListView.getChildAt(mListView.getChildCount() - 1); 
-
86:	assertEquals("List is not scrolled to the bottom", mListView.getAdapter().getCount() - 1, 
-
90:	mListView.getHeight() - mListView.getListPaddingBottom(), lastChild.getBottom()); 
-
93:	mListView.getChildCount(), originalCount + 1), 
94:	mListView.getChildCount() <= originalCount + 1); 
Full Snippet Info
7
CodeRank
Examples using Android ListView setDividerHeight method:
This code example shows how to use the following methods: setDividerHeight, setFastScrollEnabled
47:	super.configureList(activity, listView); 
-
49:	listView.setFastScrollEnabled(true); 
50:	listView.setDividerHeight(0); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: setDividerHeight, setFastScrollEnabled
46:	super.configureList(activity, listView); 
-
48:	listView.setFastScrollEnabled(true); 
49:	listView.setDividerHeight(0); 
Full Snippet Info
8
CodeRank
Examples using Android ListView addHeaderView method:
This code example shows how to use the following methods: addHeaderView, setAdapter, setEmptyView, setFocusable, setOnItemClickListener
92:	listView.addHeaderView(headerView()); 
-
94:	listView.setOnItemClickListener(this); 
-
97:	listView.setEmptyView(emptyView); 
-
101:	listView.setAdapter(adapter); 
102:	listView.setFocusable(true); 
Full Snippet Info
8
CodeRank
Examples using Android ListView addFooterView method:
This code example shows how to use the following methods: addFooterView, getFooterViewsCount, setAdapter, setSelection
119:	if (mListView.getFooterViewsCount() == 0) { 
120:	mListView.addFooterView(mLoadingView); 
121:	mListView.setAdapter(mAdapter); 
-
131:	mListView.setSelection(0); 
Full Snippet Info
9
CodeRank
This code example shows how to use the following methods: addFooterView, getFooterViewsCount, setAdapter, setSelection
132:	if (mListView.getFooterViewsCount() == 0) { 
133:	mListView.addFooterView(mLoadingView); 
134:	mListView.setAdapter(mAdapter); 
-
144:	mListView.setSelection(0); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: addFooterView, getFooterViewsCount, setAdapter, setSelection
132:	if (mListView.getFooterViewsCount() == 0) { 
133:	mListView.addFooterView(mLoadingView); 
134:	mListView.setAdapter(mAdapter); 
-
144:	mListView.setSelection(0); 
Full Snippet Info
8
CodeRank
Examples using Android ListView getHeaderViewsCount method:
This code example shows how to use the following methods: getChildAt, getHeaderViewsCount, getContext, getFirstVisiblePosition
37:	View v = mListView.getChildAt(position + mListView.getHeaderViewsCount() 
38:	- mListView.getFirstVisiblePosition()); 
-
50:	ImageView iv = new ImageView(mListView.getContext()); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: getChildAt, getHeaderViewsCount, getItemsCanFocus, isInTouchMode
44:	assertTrue("listview.getItemsCanFocus()", mListView.getItemsCanFocus()); 
45:	assertFalse("out of touch-mode", mListView.isInTouchMode()); 
46:	assertEquals("header view count", 1, mListView.getHeaderViewsCount()); 
47:	assertTrue("header has focus", mListView.getChildAt(0).isFocused()); 
Full Snippet Info
7
CodeRank
Examples using Android ListView getMaxScrollAmount method:
This code example shows how to use the following methods: getChildAt, getChildCount, getMaxScrollAmount, getCount, getVerticalFadingEdgeLength
44:	assertEquals("list item count", 5, mListView.getCount()); 
45:	assertEquals("list visible child count", 3, mListView.getChildCount()); 
46:	int firstTwoHeight = mListView.getChildAt(0).getHeight() + mListView.getChildAt(1).getHeight(); 
-
48:	firstTwoHeight <= mListView.getVerticalFadingEdgeLength()); 
-
50:	firstTwoHeight <= mListView.getMaxScrollAmount()); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: getChildAt, getChildCount, getMaxScrollAmount, getListPaddingBottom
47:	assertEquals("should only be one visible child", 1, mListView.getChildCount()); 
48:	final int amountOffScreen = mListView.getChildAt(0).getBottom() - (mListView.getBottom() - mListView.getListPaddingBottom()); 
-
50:	amountOffScreen > mListView.getMaxScrollAmount()); 
Full Snippet Info
7
CodeRank
Examples using Android ListView setAdapter method:
This code example shows how to use the following methods: setAdapter, getParent
43:	list.setAdapter(new SimpleListAdapter(this)); 
-
45:	((View) list.getParent()).setLayerType(View.LAYER_TYPE_HARDWARE, null); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: getAdapter, setAdapter, setOnScrollListener, setOnTouchListener
42:	ListAdapter rightAdapter = rightListView.getAdapter(); 
-
50:	rightListView.setAdapter(rightAdapter); 
-
53:	rightListView.setOnTouchListener(this); 
-
55:	rightListView.setOnScrollListener(this); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: setAdapter
43:	activityList.setAdapter(adapter); 
Full Snippet Info
8
CodeRank
Examples using Android ListView setSelection method:
This code example shows how to use the following methods: setSelection, postDelayed
22:	listView.postDelayed(new Runnable() { 
-
43:	listView.setSelection(position); 
Full Snippet Info
7
CodeRank
Examples using Android ListView setDivider method:
This code example shows how to use the following methods: setDivider, getContext, setSelector
166:	Theme theme = ThemeUtil.createTheme(listView.getContext()); 
167:	listView.setDivider(theme.getDrawable("line_seperator")); 
168:	listView.setSelector(theme.getDrawableByColor("selector_list_item")); 
Full Snippet Info
7
CodeRank
Examples using Android ListView getDividerHeight method:
This code example shows how to use the following methods: getAdapter, getDividerHeight, getLayoutParams, setLayoutParams
267:	int itemCount = lv.getAdapter().getCount(); 
268:	int divider = lv.getDividerHeight(); 
-
270:	ViewGroup.LayoutParams lp = lv.getLayoutParams(); 
-
272:	lv.setLayoutParams(lp); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: getAdapter, getDividerHeight, getLayoutParams, setLayoutParams
268:	int itemCount = lv.getAdapter().getCount(); 
269:	int divider = lv.getDividerHeight(); 
-
271:	ViewGroup.LayoutParams lp = lv.getLayoutParams(); 
-
273:	lv.setLayoutParams(lp); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: getAdapter, getDividerHeight, getLayoutParams, setLayoutParams
272:	int itemCount = lv.getAdapter().getCount(); 
273:	int divider = lv.getDividerHeight(); 
-
275:	ViewGroup.LayoutParams lp = lv.getLayoutParams(); 
-
277:	lv.setLayoutParams(lp); 
Full Snippet Info
7
CodeRank
Examples using Android ListView getFooterViewsCount method:
This code example shows how to use the following methods: addFooterView, getFooterViewsCount, setAdapter, setSelection
139:	if (mListView.getFooterViewsCount() == 0) { 
140:	mListView.addFooterView(mLoadingView); 
141:	mListView.setAdapter(mAdapter); 
-
151:	mListView.setSelection(0); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: addFooterView, getFooterViewsCount, setAdapter, setSelection
141:	if (mListView.getFooterViewsCount() == 0) { 
142:	mListView.addFooterView(mLoadingView); 
143:	mListView.setAdapter(mAdapter); 
-
153:	mListView.setSelection(0); 
Full Snippet Info
8
CodeRank
Examples for other Android ListView methods:
Related Android ListView Questions & Answers:
Other Android ListView Examples
1:	
2:	// Creating a button - Load More
3:	Button btnLoadMore = new Button(this);
-
1:	
2:	// Creating a button - Load More
3:	Button btnLoadMore = new Button(this);

Read More

14:		
15:		// List view
16:		private ListView lv;
17:		
18:		// Listview Adapter
-
36:	        						"Samsung Galaxy S3", "MacBook Air", "Mac Mini", "MacBook Pro"};
37:	        
38:	        lv = (ListView) findViewById(R.id.list_view);
39:	        inputSearch = (EditText) findViewById(R.id.inputSearch);
40:

Read More

21:	        this.setListAdapter(new ArrayAdapter<String>(this, R.layout.list_item, R.id.label, adobe_products));
22:	        
23:	        ListView lv = getListView();
24:	
25:	        // listening to single list item on click

Read More

1:	ListView listView = (ListView) findViewById(R.id.listview);
2:	listView.setAdapter(adapter);
3:	
-
1:	ListView listView = (ListView) findViewById(R.id.listview);
2:	listView.setAdapter(adapter);
3:

Read More

1:	ListView listView = getListView();
2:	listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL);
3:	listView.setMultiChoiceModeListener(new MultiChoiceModeListener() {

Read More

69:	
70:	    @Override 
71:	    public void onListItemClick(ListView l, View v, int position, long id) {
72:	        // Do something when a list item is clicked
73:	    }

Read More

ListView Class Overview
A view that shows items in a vertically scrolling list. The items come from the ListAd...
Methods
  • addFooterView
    Add a fixed view to appear at the bottom of the list.
  • getAdapter
    Returns the adapter currently in use in this ListView.
  • setDivider
    Sets the drawable that will be drawn between each item in the list.
  • setDividerHeight
    Sets the height of the divider that will be drawn between each item in the list.
  • setItemsCanFocus
    Indicates that the views created by the ListAdapter can contain focusable items.
  • setSelectionFromTop
    Sets the selected item and positions the selection y pixels from the top edge of the ListView.