Created
June 20, 2013 07:44
-
-
Save Phonbopit/5820927 to your computer and use it in GitHub Desktop.
android-listview-example
1.ListView http://devsharing.com/2013/android/android-listview-example/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<TextView xmlns:android="http://schemas.android.com/apk/res/android" | |
android:layout_width="fill_parent" | |
android:layout_height="fill_parent" | |
android:padding="12dp" | |
android:textSize="25sp" | |
android:textColor="#0101df"> | |
</TextView> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ListViewActivity extends ListActivity { | |
String[] players = new String[] | |
{ "Leonel Messi", | |
"Zinedine Zidane", | |
"Diego Maradona", | |
"Marco Van Basten", | |
"Ronaldinho", | |
"Steven Gerrard", | |
"Cristiano Ronaldo", | |
"Gareth Bale", | |
"Neymar", | |
"Zlatan Ibrahimovich" }; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
//ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1, players); | |
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,R.layout.listview, players); | |
setListAdapter(adapter); | |
} | |
@Override | |
protected void onListItemClick(ListView listView, View view, int position, long id) { | |
String item = (String) getListAdapter().getItem(position); | |
Toast.makeText(this, item + " selected", Toast.LENGTH_LONG).show(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment