android – 如何打开新的活动点击列表视图中的项目?

前端之家收集整理的这篇文章主要介绍了android – 如何打开新的活动点击列表视图中的项目?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我无法在列表视图中的项目上点击新的活动.我想要onItemClick可以打开ApkInfoActivity ..其实当我点击没有发生.
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);

    }

我找不到问题.我如何解决

使用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)

解决方法

用这个做你的工作
list.setOnItemClickListener(new AdapterView.onItemClickListener() {
   @Override
   public void onItemClick(AdapterView<?> adapter,View view,long arg) {
      Intent appInfo = new Intent(YourActivity.this,ApkInfoActivity.class);
       startActivity(appInfo);
   } 
});
原文链接:/android/311662.html

猜你在找的Android相关文章