Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
369 views
in Technique[技术] by (71.8m points)

android - How open new activity clicking an item in listview?

I can't start a new activity clicking over an item in my listview. I want that onItemClick can open the ApkInfoActivity.. Actually when i click nothing happen.

protected void onItemClick(ListView l, View v, int position, long id, AdapterView<?> parent) {
        super.onListItemClick(l, v, position, id);

       final ApplicationInfo app = applist.get(position);

       PackageInfo packageInfo = (PackageInfo) parent.getItemAtPosition(position);

       AppDataActivity appData = (AppDataActivity) getApplicationContext();
       appData.setPackageInfo(packageInfo);

       Intent appInfo = new Intent(getApplicationContext(), ApkInfoActivity.class);
       startActivity(appInfo);

    }

I can't find the problem..How can i solve?

EDIT with logcat:

10-29 17:14:07.710: E/AndroidRuntime(3535): FATAL EXCEPTION: main
10-29 17:14:07.710: E/AndroidRuntime(3535): java.lang.ClassCastException: android.content.pm.ApplicationInfo cannot be cast to android.content.pm.PackageInfo
10-29 17:14:07.710: E/AndroidRuntime(3535):     at com.dd.application.MainActivity.onItemClick(MainActivity.java:369)
10-29 17:14:07.710: E/AndroidRuntime(3535):     at android.widget.AdapterView.performItemClick(AdapterView.java:297)
10-29 17:14:07.710: E/AndroidRuntime(3535):     at android.widget.AbsListView.performItemClick(AbsListView.java:1149)
10-29 17:14:07.710: E/AndroidRuntime(3535):     at android.widget.AbsListView$PerformClick.run(AbsListView.java:2939)
10-29 17:14:07.710: E/AndroidRuntime(3535):     at android.widget.AbsListView$2.run(AbsListView.java:3622)
10-29 17:14:07.710: E/AndroidRuntime(3535):     at android.os.Handler.handleCallback(Handler.java:730)
10-29 17:14:07.710: E/AndroidRuntime(3535):     at android.os.Handler.dispatchMessage(Handler.java:92)
10-29 17:14:07.710: E/AndroidRuntime(3535):     at android.os.Looper.loop(Looper.java:137)
10-29 17:14:07.710: E/AndroidRuntime(3535):     at android.app.ActivityThread.main(ActivityThread.java:5323)
10-29 17:14:07.710: E/AndroidRuntime(3535):     at java.lang.reflect.Method.invokeNative(Native Method)
10-29 17:14:07.710: E/AndroidRuntime(3535):     at java.lang.reflect.Method.invoke(Method.java:525)
10-29 17:14:07.710: E/AndroidRuntime(3535):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:743)
10-29 17:14:07.710: E/AndroidRuntime(3535):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:559)
10-29 17:14:07.710: E/AndroidRuntime(3535):     at dalvik.system.NativeStart.main(Native Method)
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Use This for doing your work

 list.setOnItemClickListener(new AdapterView.onItemClickListener() {
   @Override
   public void onItemClick(AdapterView<?> adapter, View view, int position, long arg) {
      Intent appInfo = new Intent(YourActivity.this, ApkInfoActivity.class);
       startActivity(appInfo);
   } 
});

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...