我创建了一个列表。现在,当我单击列表项时,我想运行一个 Java 类,它是另一个名称列表。
这是我的代码:
public class SecondAct extends ListActivity {
private String[] items = { "Pending Retailers", "Ordered Retailers",
"No Order Retailers", "Today's Plan", "Messages", "Daily Sales",
"Pending Invoices", "Day Close", "Tools and Updates", "Exit" };
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_multiple_choice, items);
// Get the activity's ListView and set its choice mode as multiple choice
getListView().setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
setListAdapter(adapter);
}
protected void onListItemClick(ListView l, View v, int position, long id) {
// TODO Auto-generated method stub
super.onListItemClick(l, v, position, id);
String selectionValue = "";
selectionValue = (String) getListView().getItemAtPosition(position);
Log.i("List Selection Value: ",
(String) getListView().getItemAtPosition(position));
if (selectionValue.equalsIgnoreCase("Pending Retailers")) {
Intent intent = new Intent("my.com.npi.List");
startActivity(intent);
AlertDialog alertDialog = new AlertDialog.Builder(SecondAct.this)
.create();
alertDialog.setTitle("Pending Retailers Selected");
alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// here we i add functions
}
});
// alertDialog.setIcon(R.drawable.icon);
alertDialog.show();
}
else if (selectionValue.equalsIgnoreCase("Exit")) {
finish();
}
}
}
现在,当我单击第一项时,应用程序被强制关闭。我使用意图开始新活动,但它不起作用。无望的卡住了!请帮忙。
谢谢。