package com.example.data_server_assi;
import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;
公共类Menu扩展了ListActivity {
String[] menu = {"AddInfo","DataBaseInfo"};
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setListAdapter(new ArrayAdapter<String>(Menu.this, android.R.layout.simple_list_item_1, menu));
}
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
// TODO Auto-generated method stub
super.onListItemClick(l, v, position, id);
try {
Toast.makeText(Menu.this, "Test" ,Toast.LENGTH_SHORT).show();
Class menuItem = Class.forName("com.example.data_server_assi."+menu[position]);
Intent menuIntent = new Intent(Menu.this,menuItem);
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}`
答案 0 :(得分:1)
下面的代码,您错过了一行代码:
Intent menuIntent = new Intent(Menu.this,menuItem);
startActivity(menuIntent);
OR
startActivity(new Intent(menu.this,menuItem));
答案 1 :(得分:0)
您错过了开始活动 -
startActivity(YOUR_INTENT_NAME);