I have created a list view within a tab with a list of teams within it. I want to create a activity which when clicked goes to another class, I want to do this with 20 items that will be in this list. My code so far is:
public class ll2 extends ListActivity {
static final String[] teams = new String[]{"Accrington Stanley",
"Aldershot", "Barnet", "Bradford City", "Burton Albion",
"Bury", "Cheltenham Town", "Chesterfield", "Crewe Alexandra"};
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final String[] TEAMS = getResources().getStringArray(R.array.twoteams_array);
setListAdapter(new ArrayAdapter<String>(this, R.layout.list_item, TEAMS));
ListView lv = getListView();
lv.setTextFilterEnabled(true);
lv.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// When clicked, show a toast with the TextView text
Toast.makeText(getApplicationContext(), ((TextView) view).getText(),
Toast.LENGTH_SHORT).show();
Intent intent;
intent = new Intent().setClass(this, Bradford.class);
}
});
}
}
I have read some tutorials, but they do not mention how to maka a clickable listview.
How can I achieve this?
You’ll probably want to override the
onListItemClickmethod in yourListActivity. Based on the position, you will construct an appropriate intent.If you need to access data associated with the item, the documentation provides this suggestion: