ListView :
- A view that shows items in a vertically scrolling list. The items come from the ListAdapter associated with this view.
- Contains a vertically scrolling, horizontally filled list of View objects, each of which typically contains a row of data; the user can choose an item to perform some action upon.
- In ListView we have set adapter of ArrayAdapter which gathers data from an Array is generally used when there is only a single column data or when the data comes from a resource array.
Download Android ListView :Example Code
First We will create a layout file main.xml as follows:
Than we will Create a java File as follows :
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> <TextView android:text="Select Color" android:id="@+id/textView1" android:textAppearance="?android:attr/textAppearanceLarge" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <ListView android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="@+id/listView01" /> </LinearLayout>
package com.contnr; import android.app.Activity; import android.os.Bundle; import android.view.View; import android.widget.AdapterView; import android.widget.AdapterView.OnItemClickListener; import android.widget.ArrayAdapter; import android.widget.ListView; import android.widget.TextView; import android.widget.Toast; public class ListViewContainerActivity extends Activity { /** Called when the activity is first created. */ ListView lv; TextView tv; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); String [] colors= {"Red","Green","Blue","Pink","Gray"}; lv=(ListView)findViewById(R.id.listView01); tv=(TextView)findViewById(R.id.textView1); ArrayAdapter<String> adapter=new ArrayAdapter<String>(getApplicationContext(), android.R.layout.simple_list_item_1, colors); lv.setAdapter(adapter); lv.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView<?> myAdapter, View view, int myItemId, long myLang) { // TODO Auto-generated method stub String selectedItem=lv.getItemAtPosition(myItemId).toString(); tv.setText("You Selected: "+ selectedItem); Toast.makeText(getApplicationContext(), selectedItem, 2).show(); } }); } }When you click on any of the List Item that displayed in Toast and in TextView also as follows....
Isparta
ReplyDeleteTunceli
Yozgat
Çorum
Konya
ZP8C4G
Bayburt
ReplyDeleteKars
Batman
Urfa
İzmir
XFO8P
Antalya
ReplyDeleteTrabzon
Niğde
Maraş
Antep
AKY1
Bursa
ReplyDeleteKırşehir
Muş
Mersin
Çanakkale
8VLY
Muğla
ReplyDeleteBitlis
Karaman
RHQ2
Afyon
ReplyDeleteBalıkesir
Kırklareli
Amasya
Bilecik
VHKBİX
Samsun
ReplyDeleteNevşehir
Van
Bartın
Edirne
Q5BG
İstanbul
ReplyDeleteSivas
Kırıkkale
Zonguldak
Iğdır
KKKR
Uşak
ReplyDeleteAnkara
Adıyaman
Hatay
Şırnak
S470
Çorum Lojistik
ReplyDeleteKaraman Lojistik
Gümüşhane Lojistik
Denizli Lojistik
Artvin Lojistik
J4QU
adana evden eve nakliyat
ReplyDeleteafyon evden eve nakliyat
istanbul evden eve nakliyat
burdur evden eve nakliyat
gümüşhane evden eve nakliyat
ENPURF
4C100
ReplyDeleteKonya Lojistik
Malatya Lojistik
Elazığ Parça Eşya Taşıma
Kırklareli Evden Eve Nakliyat
Denizli Evden Eve Nakliyat
78D3B
ReplyDeleteNiğde Evden Eve Nakliyat
Siirt Evden Eve Nakliyat
Balıkesir Evden Eve Nakliyat
Iğdır Evden Eve Nakliyat
Bayburt Evden Eve Nakliyat
D5F24
ReplyDeleteNiğde Evden Eve Nakliyat
Konya Şehir İçi Nakliyat
Kırşehir Evden Eve Nakliyat
Kırşehir Parça Eşya Taşıma
Kırıkkale Şehirler Arası Nakliyat
Diyarbakır Parça Eşya Taşıma
Amasya Lojistik
Kütahya Şehirler Arası Nakliyat
Batıkent Fayans Ustası
D254A
ReplyDeleteTrabzon Şehirler Arası Nakliyat
Kırşehir Şehirler Arası Nakliyat
Bingöl Lojistik
Şırnak Parça Eşya Taşıma
Manisa Şehirler Arası Nakliyat
Edirne Lojistik
Muğla Lojistik
Antep Parça Eşya Taşıma
Ağrı Lojistik
D1B6C
ReplyDeletesolflare
shiba
satoshi
ledger desktop
eigenlayer
poocoin
dexscreener
avax
trezor suite
5E891
ReplyDeletesatoshivm
defillama
layerzero
dexview
uniswap
DefiLlama
quickswap
thorchain
dexscreener