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
This code example shows how to use the following methods: getChildAt, performItemClick, getAdapter
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: setFastScrollEnabled, setDividerHeight
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: getLeft, getRight, getTop
49:	assertTrue(list.getTop()>=spinner.getBottom()); 
50:	assertTrue(list.getLeft()==spinner.getLeft()); 
51:	assertTrue(list.getRight()==spinner.getRight()); 
Full Snippet Info
8
CodeRank
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
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: setId
24:	ListView listView = new ListView(this); 
25:	listView.setId(android.R.id.list); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: setOnCreateContextMenuListener, setOnItemClickListener
29:	this.agendaList = new ListView(getActivity()); 
30:	this.agendaList.setOnItemClickListener(agendaClickListener); 
31:	this.agendaList.setOnCreateContextMenuListener(this); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: getPaddingBottom, getPaddingTop, setPadding
70:	int paddingTop = list.getPaddingTop(); 
71:	int paddingBottom = list.getPaddingBottom(); 
72:	list.setPadding(0, paddingTop, 0, paddingBottom); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: setFastScrollEnabled, setDividerHeight
46:	super.configureList(activity, listView); 
-
48:	listView.setFastScrollEnabled(true); 
49:	listView.setDividerHeight(0); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: getChildAt, getFirstVisiblePosition
52:	editor.putInt("index", listView.getFirstVisiblePosition()); 
53:	editor.putInt("top", listView.getChildAt(0) == null ? 0 : listView.getChildAt(0).getTop()); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: getContext, getChildAt, getHeaderViewsCount, 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: getVerticalFadingEdgeLength, getChildAt, getChildCount, getMaxScrollAmount, getCount
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: setId, setPadding
78:	final ListView lv = new ListView(this); 
-
82:	lv.setId(android.R.id.list); 
83:	lv.setPadding(padding, 0, padding, 0); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: getChildAt, getChildCount, getListPaddingTop, getAdapter
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: getParent, setAdapter
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: clearChoices, setItemChecked
41:	modeView.clearChoices(); 
42:	modeView.setItemChecked(lastPosition, true); 
Full Snippet Info
7
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: scrollToBottom, getHeight, getChildAt, getChildCount, 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
This code example shows how to use the following methods: setOnTouchListener, setOnScrollListener, getAdapter, setAdapter
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: getLeft, getRight, getTop
49:	assertTrue(list.getTop()>=spinner.getBottom()); 
50:	assertTrue(list.getLeft()==spinner.getLeft()); 
51:	assertTrue(list.getRight()==spinner.getRight()); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: isInTouchMode, getChildAt, getChildCount, sleep, getFirstVisiblePosition
84:	assertTrue("List not in touch mode", mListView.isInTouchMode()); 
-
86:	firstVisiblePosition == mListView.getFirstVisiblePosition()); 
-
165:	int firstVisiblePosition = mListView.getFirstVisiblePosition(); 
-
167:	assertTrue("List not in touch mode", mListView.isInTouchMode()); 
-
169:	TouchUtils.clickView(this, mListView.getChildAt(mListView.getChildCount() - 1)); 
-
173:	Thread.sleep(3000); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: setAdapter
43:	activityList.setAdapter(adapter); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: isInTouchMode, getChildAt, getHeaderViewsCount, getItemsCanFocus
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
This code example shows how to use the following methods: postDelayed, setSelection
22:	listView.postDelayed(new Runnable() { 
-
43:	listView.setSelection(position); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: getItemAtPosition
127:	Map<String, Object> map = (Map<String, Object>)l.getItemAtPosition(position); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: setId, setPadding
107:	final ListView lv = new ListView(this); 
-
111:	lv.setId(android.R.id.list); 
112:	lv.setPadding(padding, 0, padding, 0); 
Full Snippet Info
7
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: setAdapter
21:	ListAdapter adapter = new SimpleCursorAdapter(this, 
-
27:	getListView().setAdapter(adapter); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: getContext, setDivider, 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
This code example shows how to use the following methods: setAdapter, setEmptyView, setFocusable, setOnItemClickListener
88:	listView.setOnItemClickListener(this); 
-
92:	listView.setEmptyView(emptyView); 
-
98:	listView.setAdapter(adapter); 
99:	listView.setFocusable(true); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: ofFloat, getVisibility
100:	if (mEnglishList.getVisibility() == View.GONE) { 
-
107:	ObjectAnimator visToInvis = ObjectAnimator.ofFloat(visibleList, "rotationY", 0f, 90f); 
-
110:	final ObjectAnimator invisToVis = ObjectAnimator.ofFloat(invisibleList, "rotationY", 
-
114:	visToInvis.addListener(new AnimatorListenerAdapter() { 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: getLayoutParams, setLayoutParams, getAdapter, getDividerHeight
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: setAdapter, setOnItemClickListener
37:	ListView lv=new ListView(this); 
38:	lv.setAdapter(new DocksAdapter(this)); 
39:	lv.setOnItemClickListener(this); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: getVerticalFadingEdgeLength, getChildCount, getSelectedView, getAdapter
44:	mListView.getSelectedView().getHeight() < mListView.getVerticalFadingEdgeLength()); 
-
46:	mListView.getChildCount() < mListView.getAdapter().getCount()); 
Full Snippet Info
7
CodeRank
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: getChildAt, getChildCount, getListPaddingBottom, getMaxScrollAmount
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
This code example shows how to use the following methods: getItemAtPosition
51:	ActivityInfo info = (ActivityInfo) l.getItemAtPosition(position); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: getLayoutParams, setLayoutParams, getAdapter, getDividerHeight
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: setId
24:	ListView listView = new ListView(this); 
25:	listView.setId(android.R.id.list); 
Full Snippet Info
7
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
This code example shows how to use the following methods: getItemAtPosition
109:	Event event = (Event) l.getItemAtPosition(position); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: getLayoutParams, setLayoutParams, getAdapter, getDividerHeight
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
This code example shows how to use the following methods: getLayoutParams, setLayoutParams, getAdapter, getDividerHeight
270:	int itemCount = lv.getAdapter().getCount(); 
271:	int divider = lv.getDividerHeight(); 
-
273:	ViewGroup.LayoutParams lp = lv.getLayoutParams(); 
-
275:	lv.setLayoutParams(lp); 
Full Snippet Info
7
CodeRank
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

See Code Examples for Android ListView Methods: