I'm having a problem understanding what's going wrong in this code, I feel the problem may be related to the OnItemClickListener. When I try to emulate it it responds with a message like this: "Unfortunately, MyAplication has stopped.".
public class MainActivity extends ListActivity {
private ArrayList<ViewListing> arrayList;
private ListView list = (ListView) findViewById(R.id.listview);
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
arrayList = new ArrayList<ViewListing>();
arrayList.add(new ViewListing(0, R.drawable.anjelly, "Item 1"));
arrayList.add(new ViewListing(1, R.drawable.construct, "Item 2"));
arrayList.add(new ViewListing(2, R.drawable.darkdestroyer, "Item 3"));
ListViewAdapter adp = new ListViewAdapter(getApplicationContext(), arrayList);
setListAdapter(adp);
list.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
switch(position) {
case 1:
Toast.makeText(getApplicationContext(), "1 Selected", Toast.LENGTH_SHORT).show();
case 2:
Toast.makeText(getApplicationContext(), "2 Selected", Toast.LENGTH_SHORT).show();
case 3:
Toast.makeText(getApplicationContext(), "3 Selected", Toast.LENGTH_SHORT).show();
}
}
});
}
}