我使用这个代码跳转ListView
到选定的类别。
public class mainmenu extends Activity {
private ListView lv1;
private ArrayAdapter<String> listAdapter;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.mainmenu);
lv1 = (ListView) findViewById(R.id.options);
String[] lv_arr = new String[]{"Book a Classified Ad", "Book a Classified display Ad", "Book a display Ad", "Page Position Availability", "MIS", "Market Share", "Approval", "Upload Material", "Exit"};
ArrayList<String> Options = new ArrayList<String>();
Options.addAll(Arrays.asList(lv_arr));
listAdapter = new ArrayAdapter<String>(this, R.layout.simplerow, Options);
lv1.setAdapter(listAdapter);
lv1.setTextFilterEnabled(true);
lv1.setClickable(true);
lv1.setOnItemClickListener(new ListView.OnItemClickListener() {
public void onItemClick(AdapterView<?> a, View v, int position, long id) {
position = a.getSelectedItemPosition();
a.setSelection(position);
int pos1 = position;
if (pos1 == 0) {
Intent intent = getIntent();
intent = new Intent(mainmenu.this, classifiedAd.class);
startActivity(intent);
} else if (pos1 == 1 || pos1 == 2) {
Intent intent1 = new Intent(mainmenu.this, displayAd.class);
startActivity(intent1);
} else if (pos1 == 3) {
Intent intent3 = new Intent(mainmenu.this, spaceAvail.class);
startActivity(intent3);
} else if (pos1 == 4) {
Intent intent4 = new Intent(mainmenu.this, mis.class);
startActivity(intent4);
} else if (pos1 == 5) {
Intent intent5 = new Intent(mainmenu.this, mark.class);
startActivity(intent5);
} else if (pos1 == 6) {
Intent intent6 = new Intent(mainmenu.this, approval.class);
startActivity(intent6);
} else if (pos1 == 7) {
Intent intent7 = new Intent(mainmenu.this, uploadMat.class);
startActivity(intent7);
} else if (pos1 == 8) {
finish();
}
}
});
}
}
问题出在哪儿 ?