因此,在我的应用程序中,我有一个开始屏幕图像+声音,持续2秒,然后进入菜单。菜单项如下所示:
<activity
android:name=".helloWorld"
android:label="@string/app_name">
<intent-filter>
<action android:name="ro.dixy.Boston_Tutorial_App.HELLOWORLD"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
在我的Menu.java文件中,有以下代码行:
protected void onListItem(ListView l, View v, int position, long id)
{
super.onListItemClick(l,v,position,id);
String test = classes[position];
try
{
//Selectare meniu in functie de nume(pozitie)
Class ourClass = Class.forName("ro.dixy.Boston_Tutorial_App." + test);
Intent ourIntent = new Intent(Menu.this, ourClass);
startActivity(ourIntent);
}
catch(ClassNotFoundException e)
{
e.printStackTrace();
}
}
问题是,当我单击“类”中的菜单时,它什么也没做。
我是Android的新手,我正尝试从Boston Tutorials学习它。
告诉我您是否还有其他需要。谢谢你。
这:
Menu.java
public class Menu extends ListActivity
{
//Nume Meniuri
String classes[] = {"helloWorld","TextPlay","example2","example3","example4","example5"};
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
//ListAdapter pentru ListActivity
setListAdapter(new ArrayAdapter<String>(Menu.this, android.R.layout.simple_list_item_1, classes));
}
protected void onListItem(ListView l, View v, int position, long id)
{
super.onListItemClick(l, v, position, id);
String test = classes[position];
try
{
//Selectare meniu in functie de nume(pozitie)
Class ourClass = Class.forName("ro.dixy.Boston_Tutorial_App." + test);
Intent ourIntent = new Intent(Menu.this, ourClass);
startActivity(ourIntent);
}
catch(ClassNotFoundException e)
{
e.printStackTrace();
}
}
}
发现我的错误。这是好的代码:
@Override
protected void onListItemClick(ListView l, View v, int position, long id)
{
//your code here
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句