Android:ListView

De Wiki Fred
Aller à : navigation, rechercher

Android ListView

Etape 1 : Liste Simple

res/layout/main.xml

 1 <?xml version="1.0" encoding="utf-8"?>
 2 
 3 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 4     android:layout_width="fill_parent"
 5     android:layout_height="fill_parent"
 6     android:orientation="vertical" 
 7     >
 8 
 9     <ListView
10         android:id="@+android:id/myList"
11         android:layout_width="799dp"
12         android:layout_height="456dp" >
13 
14     </ListView>
15 
16 </LinearLayout>

MyActivity.java

 1 public class MyActivity extends Activity
 2 {
 3     @Override
 4     public void onCreate(Bundle savedInstanceState)
 5     {
 6         super.onCreate(savedInstanceState);
 7         setContentView(R.layout.main);
 8 
 9         String[] listeStrings = {"France","Allemagne","Russie"};
10 
11         ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,listeStrings);
12 
13         ListView lv = (ListView) findViewById(R.id.myList);
14         
15         lv.setAdapter(adapter);
16     }
17 }