因此,在执行此旧教程时,我遇到了 import android.R(simple_list_item_1 需要它)但破坏了我的 R.menu.cmenu(cmenu.xml)的问题,我在这里缺少什么?...是的,我有 xml 设置。
import android.R;
import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.MenuInflater;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
public class Menu extends ListActivity {
String classes[] = {"MainActivity", "TextPlay", "Email", "Camera", "Data", "OpenedClass"};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setListAdapter(new ArrayAdapter<String>(Menu.this, R.layout.simple_list_item_1, classes));
}
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
String cheese = classes[position];
try{
Class ourClass = Class.forName("com.example.test1." + cheese);
Intent ourIntent = new Intent(Menu.this, ourClass);
startActivity(ourIntent);
}catch (ClassNotFoundException e){
e.printStackTrace();
}
}
@Override
public boolean onCreateOptionsMenu(android.view.Menu menu) {
super.onCreateOptionsMenu(menu);
MenuInflater blowUp;
blowUp = getMenuInflater();
blowUp.inflate(R.menu.cmenu, menu); //cmenu has the error: rename
return true;
}
}