ListActivity with ItemClickListener to change different activity

public class Pilihansoal extends ListActivity{
	String[] mtpelajaran = {"matematika","b.indonesia","b.inggris"};
	TextView selection; 
	ListView list;
	
	public void onCreate(Bundle savedInstanceState){
		super.onCreate(savedInstanceState);
		setContentView(R.layout.listsoal); 
		setListAdapter(new ArrayAdapter(this,android.R.layout.simple_list_item_1,mtpelajaran)); 
		selection=(TextView)findViewById(R.id.selection);
	}
	public void onListItemClick(ListView parent, View v, int position, long id) { 
		
		switch(position){
			case 0:
				Intent m = new Intent(this,pertanyaan1.class);
				startActivity(m);
				break;
			case 1:
				Intent i = new Intent(this,pertanyaan1.class);
				startActivity(i); 
				break;
			case 2:
				Intent r = new Intent(this,pertanyaan1.class);
				startActivity(r);
				break;
		}
	}
}

list.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
	xmlns:android="http://schemas.android.com/apk/res/android"
	android:orientation="vertical"
	android:layout_width="fill_parent" 
	android:layout_height="fill_parent" >
	<TextView
		android:id="@+id/selection"
		android:layout_width="fill_parent"
		android:layout_height="wrap_content"/>
	<ListView
		android:id="@android:id/list"
		android:layout_width="fill_parent" 
		android:layout_height="fill_parent"
		android:drawSelectorOnTop="false"
		android:choiceMode="singleChoice"
		/>
</LinearLayout>	

4 thoughts on “ListActivity with ItemClickListener to change different activity

  1. Kalo dikirim ke listactivity yang lain gimana? krn klo di pertanyaan1.class nya diganti ListActivity Logcatnya ngasih tau ga nemu Activity

    Thx

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s