我有一份清单,介绍活动情况,并使用定制改编器,因为我想在清单中一行和案文。
String[] options = res.getStringArray(R.array.menu_title);
TypedArray icons = res.obtainTypedArray(R.array.menu_icon);
ImageAndTextAdapter iadapter = new ImageAndTextAdapter(ctx, R.layout.row, options, icons);
MenuList.setAdapter(iadapter);
然后,我利用PetOnItemClickListener使清单调查被点击但失败。
MenuList.setOnItemClickListener(new ListView.OnItemClickListener() {
public void onItemClick(AdapterView<?> arg0, View v, int position, long id) {
Intent myIntent = new Intent(Menu.this, Revision.class);
Menu.this.startActivity(myIntent);
}
});
Here is the logcat:
11-22 16:55:17.419: E/AndroidRuntime(2056): FATAL EXCEPTION: main 11-22 16:55:17.419: E/AndroidRuntime(2056): java.lang.ClassCastException: android.widget.LinearLayout 11-22 16:55:17.419: E/AndroidRuntime(2056): at cs.ucl.cw.Menu$1.onItemClick(Menu.java:54) 11-22 16:55:17.419: E/AndroidRuntime(2056): at android.widget.AdapterView.performItemClick(AdapterView.java:284) 11-22 16:55:17.419: E/AndroidRuntime(2056): at android.widget.ListView.performItemClick(ListView.java:3513) 11-22 16:55:17.419: E/AndroidRuntime(2056): at android.widget.AbsListView$PerformClick.run(AbsListView.java:1849) 11-22 16:55:17.419: E/AndroidRuntime(2056): at android.os.Handler.handleCallback(Handler.java:587) 11-22 16:55:17.419: E/AndroidRuntime(2056): at android.os.Handler.dispatchMessage(Handler.java:92) 11-22 16:55:17.419: E/AndroidRuntime(2056): at android.os.Looper.loop(Looper.java:130) 11-22 16:55:17.419: E/AndroidRuntime(2056): at android.app.ActivityThread.main(ActivityThread.java:3835) 11-22 16:55:17.419: E/AndroidRuntime(2056): at java.lang.reflect.Method.invokeNative(Native Method) 11-22 16:55:17.419: E/AndroidRuntime(2056): at java.lang.reflect.Method.invoke(Method.java:507) 11-22 16:55:17.419: E/AndroidRuntime(2056): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:847) 11-22 16:55:17.419: E/AndroidRuntime(2056): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:605) 11-22 16:55:17.419: E/AndroidRuntime(2056): at dalvik.system.NativeStart.main(Native Method)
AIM: clickable listview which would bring up other activities. Thanks guys