AndroidList.java
package com.exercise.AndroidList;
import android.app.ListActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;
public class AndroidList extends ListActivity {
String[] DayOfWeek = {"Sunday", "Monday", "Tuesday",
"Wednesday", "Thursday", "Friday", "Saturday"
};
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setContentView(R.layout.main);
setListAdapter(new ArrayAdapter<String>(this,
R.layout.row, R.id.weekofday, DayOfWeek));
}
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
// TODO Auto-generated method stub
//super.onListItemClick(l, v, position, id);
String selection = l.getItemAtPosition(position).toString();
Toast.makeText(this, selection, Toast.LENGTH_LONG).show();
}
}
next: Custom ArrayAdapter, with with different icons.
how to I define an argument, an id for example, instead of index of array? I noted that the id that passed by parameter of onListItemClick method is Index of array
ReplyDeleteHello Hélio,
ReplyDeleteThe arguments are passed by Android S to you, not defined by you. Please read here: http://developer.android.com/reference/android/app/ListActivity.html#onListItemClick(android.widget.ListView, android.view.View, int, long).
I want to do:
ReplyDeleteprotected void onListItemClick (ListView l, View v, int position, long id){
super.onListItemClick(l, v, position, id);
setContentView(R.layout.mylayout);
}
whatever mylayout does contain, i want to move to it.I get strange exceptions in the LogCat, trying to solve them but i couldn't get where I want.How could I solve this?