Android has a built-in layout android.R.layout.simple_list_item_1
But how do you really take advantage of this, without creating a separate XML of your own?
Here is how I did it...
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
List<String> data = new ArrayList<String>();
data.add("King");
data.add("Queen");
data.add("Bishop");
data.add("Rook");
ArrayAdapter arrayAdapter = new ArrayAdapter(this, android.R.layout.simple_list_item_1, data );
setListAdapter(arrayAdapter);
getListView().setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view, int position,
long arg3) {
//item clicked
}
});
}
---------------------
No setContentView, no separate XML required
!
Thats all!! Trust me.
No comments:
Post a Comment