我有一个ListView
。它包含带有图像的文本。我知道如果我单击该ListView
项目Toast
会出现一个,但我想要的是单击该项目以打开它们各自的活动。
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ArrayList<Recipedetails> image_details = GetSearchResults();
final ListView lv1 = (ListView) findViewById(R.id.listV_main);
lv1.setAdapter(new ItemListBaseAdapter(this, image_details));
lv1.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> a, View v, int position, long id) {
Object o = lv1.getItemAtPosition(position);
Recipedetails obj_itemDetails = (Recipedetails)o;
Toast.makeText(SouthIndian.this, "You have chosen : " + " " + obj_itemDetails.getName(), Toast.LENGTH_LONG).show();
switch(obj_itemDetails.getName())
{
case "Vegterian":
Intent newActivity = new Intent(SouthIndian.this,
SouthIndianvegrecipes.class);
startActivity(newActivity);
break;
case "Non-Vegterian":
Intent new1Activity = new Intent(SouthIndian.this,
SouthIndiannonvegrecipes.class);
startActivity(new1Activity);
break;
//same for other Activity
}
}
});
}
private ArrayList<Recipedetails> GetSearchResults(){
ArrayList<Recipedetails> results = new ArrayList<Recipedetails>();
Recipedetails item_details = new Recipedetails();
item_details.setName("Vegterian");
item_details.setItemDescription("Recipes made by raw materials");
//item_details.setPrice("RS 310.00");
item_details.setImageNumber(1);
results.add(item_details);
item_details = new Recipedetails();
item_details.setName("Non-Vegterian");
item_details.setItemDescription("Flesh of sweet animals");
//item_details.setPrice("RS 350.00");
item_details.setImageNumber(2);
results.add(item_details);
item_details = new Recipedetails();
item_details.setName("Pickels");
item_details.setItemDescription("Touchable dish by Homemade");
//item_details.setPrice("RS 250.00");
item_details.setImageNumber(3);
results.add(item_details);
item_details = new Recipedetails();
item_details.setName("Soups");
item_details.setItemDescription("Startup for our food");
//item_details.setPrice("RS 350.00");
item_details.setImageNumber(4);
results.add(item_details);
return results;
}
我想要的是,如果我点击它必须去他们的第一张图片Activity
。就像它必须进行各自的活动,而不是同一个活动。我怎样才能做到这一点?
我的 AndroidManifest.xml
<activity
android:name="com.example.recipestutors.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="RecipeActivity" android:label="@string/activity_recipeview" android:theme="@style/AppTheme"></activity>
<activity android:name="SouthIndian" android:label="@string/activity_SouthIndianrecipeview" android:theme="@style/AppTheme"></activity>
<activity android:name="NorthIndian" android:label="@string/activity_NorthIndianrecipeview" android:theme="@style/AppTheme"></activity>
<activity android:name="Western" android:label="@string/activity_Westernrecipeview" android:theme="@style/AppTheme"></activity>
<activity android:name="Chinese" android:label="@string/activity_Chineserecipeview" android:theme="@style/AppTheme"></activity>
<activity android:name="SouthIndianvegrecipes" android:label="@string/activity_Chineserecipeview" android:theme="@style/AppTheme"></activity>
<activity android:name="SouthIndiannonvegrecipes" android:label="@string/activity_Chineserecipeview" android:theme="@style/AppTheme"></activity>
</application>
logcat 显示错误
03-05 10:47:36.091: E/AndroidRuntime(3485): FATAL EXCEPTION: main
03-05 10:47:36.091: E/AndroidRuntime(3485): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.recipestutors/com.example.recipestutors.MainActivity}: java.lang.ClassNotFoundException: Didn't find class "com.example.recipestutors.MainActivity" on path: /data/app/com.example.recipestutors-1.apk
03-05 10:47:36.091: E/AndroidRuntime(3485): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2106)
03-05 10:47:36.091: E/AndroidRuntime(3485): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
03-05 10:47:36.091: E/AndroidRuntime(3485): at android.app.ActivityThread.access$600(ActivityThread.java:141)
03-05 10:47:36.091: E/AndroidRuntime(3485): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
03-05 10:47:36.091: E/AndroidRuntime(3485): at android.os.Handler.dispatchMessage(Handler.java:99)
03-05 10:47:36.091: E/AndroidRuntime(3485): at android.os.Looper.loop(Looper.java:137)
03-05 10:47:36.091: E/AndroidRuntime(3485): at android.app.ActivityThread.main(ActivityThread.java:5039)
03-05 10:47:36.091: E/AndroidRuntime(3485): at java.lang.reflect.Method.invokeNative(Native Method)
03-05 10:47:36.091: E/AndroidRuntime(3485): at java.lang.reflect.Method.invoke(Method.java:511)
03-05 10:47:36.091: E/AndroidRuntime(3485): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
03-05 10:47:36.091: E/AndroidRuntime(3485): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
03-05 10:47:36.091: E/AndroidRuntime(3485): at dalvik.system.NativeStart.main(Native Method)
03-05 10:47:36.091: E/AndroidRuntime(3485): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.example.recipestutors.MainActivity" on path: /data/app/com.example.recipestutors-1.apk
03-05 10:47:36.091: E/AndroidRuntime(3485): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:65)
03-05 10:47:36.091: E/AndroidRuntime(3485): at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
03-05 10:47:36.091: E/AndroidRuntime(3485): at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
03-05 10:47:36.091: E/AndroidRuntime(3485): at android.app.Instrumentation.newActivity(Instrumentation.java:1054)
03-05 10:47:36.091: E/AndroidRuntime(3485): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2097)
03-05 10:47:36.091: E/AndroidRuntime(3485): ... 11 more