这是我的代码,当点击项目0("字母")时,我需要去TESTCLASS,当点击列表项目1("数字")时,我需要去TESTCLASS1。列表项存储在名为LesssonCategories的2D数组中。请帮忙。先谢谢你。
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import java.util.ArrayList;
import java.util.HashMap;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.app.ListActivity;
import android.os.Bundle;
import android.widget.ListView;
import android.widget.SimpleAdapter;
public class Lesson extends ListActivity {
//ArrayList holds the data (as HashMaps) to load into the ListView
ArrayList<HashMap<String,String>> list = new ArrayList<HashMap<String,String>>();
//SimpleAdapter does the work to load the data in to the ListView
private SimpleAdapter sa;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.lesson_layout);
//HashMap links each line of data to the correct TextView
HashMap<String,String> item;
for(int i=0;i<LesssonCategories.length;i++){
item = new HashMap<String,String>();
item.put( "line1", LesssonCategories[i][0]);
item.put( "line2", LesssonCategories[i][1]);
list.add( item );
}
sa = new SimpleAdapter(this, list,
R.layout.lesson_two_lines,
new String[] { "line1","line2" },
new int[] {R.id.line_a, R.id.line_b});
setListAdapter(sa);
}
private String[][] LesssonCategories =
{{"Alphabets","Abjad"},
{"Numbers","Angka"},
{"Colours","Warna"},
{"Day","Hari"},
{"Month","Bulan"},
{"Time","Masa"},
{"Questions","Kata Tanya"},
{"Family","Keluarga"},
{"Home","Rumah"},
{"Race & Religion","Bangsa & Agama"},
{"Festivals","Perayaan"},
{"Animals","Haiwan"},
{"Food & Drink","Makanan & Minuman"},
{"Clothes","Pakaian"},
{"Building","Bangunan"},
{"School","Sekolah"},
{"Feelings","Perasaan"},
{"Greetings","Ucapan"},
{"Malaysia States","Negeri dalam Malaysia"},
{"State Capitals","Ibu Negeri"}};
protected void onListItemClick(ListView listView, View view, int position, long id) {
switch( position )
{
case 0: Intent newActivity0 = new Intent(this, TESTCLASS.class);
startActivity(newActivity0);
break;
case 1: Intent newActivity1 = new Intent(this, TESTCLASS.class);
startActivity(newActivity1);
break;
case 2: Intent newActivity2 = new Intent(this, TESTCLASS.class);
startActivity(newActivity2);
break;
}
}
}