Android provides the list view as a standard view to display the group of scrollable items. The list view is bounded with an Adapter which provides an array of items or database query to populate the list view.
The standard way to list the data in list view is to use the cursor loader which provides an asynchronous method to load the list view from query object.
See the example below using the list view bounded with simple cursor adapter which reads the contacts data. (You can use the list view using cursor loader in android 3.0 and with backward support with 1.6)
(Note : add the following permission to android manifest file
<uses-permission android:name="android.permission.READ_CONTACTS" /> )
public class ListViewExample extends ListActivity implements LoaderManager.LoaderCallbacks<Cursor> { // Create the Simple Adapter Object SimpleCursorAdapter mAdapter; // These are the Contacts rows that we will retrieve static final String[] DataObj = new String[] {ContactsContract.Data._ID, ContactsContract.Data.DISPLAY_NAME}; // This is the select criteria static final String Query = "((" + ContactsContract.Data.DISPLAY_NAME + " NOTNULL) AND (" + ContactsContract.Data.DISPLAY_NAME + " != '' ))"; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Create a progress bar to display while the list loads ProgressBar progressBar = new ProgressBar(this); progressBar.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, Gravity.CENTER)); progressBar.setIndeterminate(true); getListView().setEmptyView(progressBar); // Must add the progress bar to the root of the layout ViewGroup root = (ViewGroup) findViewById(android.R.id.content); root.addView(progressBar); // For the cursor adapter, specify which columns go into which views String[] fromColumns = {ContactsContract.Data.DISPLAY_NAME}; int[] toViews = {android.R.id.text1}; // The TextView in simple_list_item_1 // Create an empty adapter we will use to display the loaded data. // We pass null for the cursor, then update it in onLoadFinished() mAdapter = new SimpleCursorAdapter(this, android.R.layout.simple_list_item_1, null, fromColumns, toViews, 0); setListAdapter(mAdapter); // Prepare the loader. Either re-connect with an existing one, // or start a new one. getLoaderManager().initLoader(0, null, this); } // Called when a new Loader needs to be created public Loader<Cursor> onCreateLoader(int id, Bundle args) { // Now create and return a CursorLoader that will take care of // creating a Cursor for the data being displayed. return new CursorLoader(this, ContactsContract.Data.CONTENT_URI, DataObj, Query, null, null); } // Called when a previously created loader has finished loading public void onLoadFinished(Loader<Cursor> loader, Cursor data) { // Swap the new cursor in. (The framework will take care of closing the // old cursor once we return.) mAdapter.swapCursor(data); } // Called when a previously created loader is reset, making the data unavailable public void onLoaderReset(Loader<Cursor> loader) { // This is called when the last Cursor provided to onLoadFinished() // above is about to be closed. We need to make sure we are no // longer using it. mAdapter.swapCursor(null); } @Override public void onListItemClick(ListView l, View v, int position, long id) { // Do something when a list item is clicked } }
We liked your content, I would like to contribute and share a few details about salesforce training in hyderabad which is highly updated and offers online salesforce training which helps you to get highly trained in salesforce just by sitting at home and helps you to boost your salesforce skills with updated techniques
ReplyDeletehttps://bayanlarsitesi.com/
ReplyDeleteAltınşehir
Karaköy
Alemdağ
Gürpınar
BAS3
Eskişehir
ReplyDeleteDenizli
Malatya
Diyarbakır
Kocaeli
Z3COJ0
Diyarbakır
ReplyDeleteKırklareli
Kastamonu
Siirt
Diyarbakır
AXOQ3N
Denizli
ReplyDeleteAnkara
Antep
Bursa
Eskişehir
B1OYSB
yalova
ReplyDeleteyozgat
elazığ
van
sakarya
PL03
7788C
ReplyDeleteŞırnak Şehir İçi Nakliyat
Uşak Lojistik
Balıkesir Evden Eve Nakliyat
Burdur Şehirler Arası Nakliyat
Erzincan Parça Eşya Taşıma
Adana Evden Eve Nakliyat
Yozgat Lojistik
Çankaya Fayans Ustası
Batman Parça Eşya Taşıma
92F6E
ReplyDeleteMadencilik Nedir
Bitcoin Kazma
Mexc Borsası Kimin
Bitcoin Üretme
Bitcoin Çıkarma Siteleri
Kripto Para Nasıl Kazılır
Binance Ne Zaman Kuruldu
Paribu Borsası Güvenilir mi
Bitcoin Madenciliği Siteleri
04792
ReplyDeletekocaeli telefonda görüntülü sohbet
Artvin Yabancı Canlı Sohbet
siirt yabancı görüntülü sohbet siteleri
en iyi sesli sohbet uygulamaları
Diyarbakır Seslı Sohbet Sıtelerı
bitlis görüntülü sohbet sitesi
urfa canli sohbet bedava
kırıkkale en iyi görüntülü sohbet uygulamaları
Ardahan Görüntülü Sohbet Uygulamaları Ücretsiz
9721D
ReplyDeleteBinance Referans Kodu
Snapchat Takipçi Hilesi
Binance Madencilik Nasıl Yapılır
Youtube İzlenme Hilesi
Tumblr Takipçi Hilesi
Bitcoin Nasıl Alınır
Bitcoin Kazanma
Youtube Beğeni Satın Al
Coin Nasıl Çıkarılır
9FBC7
ReplyDeleteDlive Takipçi Hilesi
Facebook Beğeni Hilesi
Coin Madenciliği Nasıl Yapılır
Nonolive Takipçi Satın Al
Kwai Takipçi Hilesi
Mexc Borsası Kimin
Paribu Borsası Güvenilir mi
Binance Referans Kodu
Soundcloud Takipçi Hilesi
706BD
ReplyDeleteuwu lend
ledger live
poocoin
raydium
yearn
arculus
dextools
satoshi
shiba