我有一个自定义列表视图,如果用户单击一个项目,我会尝试进入下一个屏幕。它似乎不起作用。我试过如果其他,切换。如果我不使用它们,它会起作用,但这样的话,每个项目都会进入同一个屏幕。任何帮助都会得到帮助。
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.options_main);
OptionMainHeader option_list[] = new OptionMainHeader[]
{
new OptionMainHeader(R.drawable.clock_icon_48, "Helo"),
new OptionMainHeader(R.drawable.weather_cloudy, "Apple"),
new OptionMainHeader(R.drawable.weather_cloudy, "Mango"),
new OptionMainHeader(R.drawable.weather_cloudy, "Banana"),
};
OptionMainHeader1 adapter = new OptionMainHeader1(this, R.layout.option_main_header1, option_list);
listView1 = (ListView)findViewById(R.id.listView1);
View header = (View)getLayoutInflater().inflate(R.layout.option_main_header, null);
listView1.addHeaderView(header);
listView1.setAdapter(adapter);
listView1.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
int position = listView1.getSelectedItemPosition();
String selectedFromList =(String) (listView1.getItemAtPosition(position));
if (selectedFromList == "Helo"){
Intent CurrentWaitTime = new Intent(getApplicationContext(), go.class);
startActivity(CurrentWaitTime);
} else if (selectedFromList == "Apple"){
Intent Appointments = new Intent(getApplicationContext(), no.class);
startActivity(Appointments);
} else if (selectedFromList == "Mango"){
Intent Logout = new Intent(getApplicationContext(), go.class);
startActivity(Logout);
} else if (selectedFromList == "Banana"){
Intent Exit = new Intent(getApplicationContext(), low.class);
startActivity(Exit);
}
}
});
}