During my holidays, sometimes i got bored with my computer. So I decided to learn some Android's component. ListView it is. Seems to be little difficult to program the listview, I learn from another source to understand and solve this problem.
Lets go to the point, first, you must initialize the array to input the data. Use arrayadapter to set the array.
Lets go to the point, first, you must initialize the array to input the data. Use arrayadapter to set the array.
private ArrayAdapterdataAdapter;
dataAdapter = new ArrayAdapter(this, android.R.layout.simple_expandable_list_item_1);
list = (ListView) findViewById(R.id.listView1);
list.setAdapter(dataAdapter);On my project, listView1 is my listView.Change the variable inside the function findViewById to your ListView's name on your project. If you want to add some data inside the list, add this function :
dataAdapter.add("Hello World");Compile and run the program. Next step, set event listener to component, so we can get the event when list is pressed.
list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView arg0, View arg1, int arg2,
long arg3) {
Object o = list.getItemAtPosition(arg2);
// get clicked string by using o.toString();
}Ok done, Im sorry its not perfect at all.