My list includes eight items positioned beneath a 'header' row, all contained within a tab on my application. I cannot figure out how to change to an activity (or possibly a different tab) based upon the item clicked on in the list.
I'm currently extending the Activity class, not sure if this is an issue. I've attempted to use the onListItemClick whilst extending the ListActivity class; this however caused the application to crash.
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
public class Tab2 extends Activity {
private ListView listView1;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.tab2);
Cinema cinema_data[] = new Cinema[]{
new Cinema(R.drawable.blue, "Blue Cinema"),
new Cinema(R.drawable.green, "Green Cinema"),
new Cinema(R.drawable.purple, "Purple Cinema"),
new Cinema(R.drawable.red, "Red Cinema"),
new Cinema(R.drawable.yellow, "Gold Cinema"),
new Cinema(R.drawable.blue, "Cyan Cinema"),
new Cinema(R.drawable.green, "Lime Cinema"),
new Cinema(R.drawable.purple, "Magenta Cinema")
};
CinemaAdapter adapter = new CinemaAdapter(this,
R.layout.listview_item_row, cinema_data);
listView1 = (ListView)findViewById(R.id.listView1);
View header = (View)getLayoutInflater().inflate(R.layout.listview_header_row, null);
listView1.addHeaderView(header);
listView1.setAdapter(adapter);
}
}
any help will be greatly appreciated!
edit:
protected void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
try {
Intent i = new Intent("android.lab.two.Tab1");
startActivity(i);
} catch(Exception e){
e.printStackTrace();
}
}