我真的在努力将菜单链接在一起。我想要创建的应用程序是一个菜单集合,它们指向我计划在应用程序中打开的各个站点的URL链接。我创建了一个包含8个选项的列表活动菜单,我有8个类,还有其他选项。我的问题是如何将菜单链接在一起。我问这个问题,有人说我应该映射。这是代码:
public class MyList extends ListActivity {
private static final String Cp = null;
private static final String Pp = null;
private static final String L2 = null;
private static final String L1 = null;
/** Called when the activity is first created. */
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
// Create an array of Strings, that will be put to our ListActivity
String[] names = new String[] { "Pp", "Cp", "L1", "L2", "Bt", "Se", "As", "Travel"};
// Create an ArrayAdapter, that will actually make the Strings above
// appear in the ListView
this.setListAdapter(new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_checked, names));
}
{Map<String, Runner> runners = new HashMap<String, Runner>();
runners.put("Pp", (Runner) new Pp());
runners.put("Cp", (Runner) new Cp());
runners.put("L1", (Runner) new L1());
runners.put("L2", (Runner) new L2());
public void onListItemClick(runners.get(getListView()).L2();
runners.get(getListView()).L1();
runners.get(getListView()).Pp();
runners.get(getListView()).Cp(); {
我已经设置了一个名为runners的类,并在每个选项中添加了下一个菜单,如下所示:
public interface Runner {
void L2();
void L1();
void Pp();
void Cp();
}
目前我在此行公共虚空onListItemClick(runners.get(getListView())上收到一个错误.League2(); void是变量onListItemClick的无效类型,我是否正确完成了这个,我错过了什么,这是我应该使用这种方法的方式吗?
答案 0 :(得分:0)
也许只是格式化?
public void onListItemClick(){ 。runners.get(getListView())L2(); 。runners.get(getListView())L1(); 。runners.get(getListView())PP(); 。runners.get(getListView())CP(); }