Android - ListView 中的 Intent

标签 android android-listview android-intent

我无法在我的 ListView 中创建 Intent 。它给出了一个错误“无法实例化 activity ComponentInfo”并由 Classcastexception 引起。这是代码 fragment -

lv.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view, int position,
                long id) {

Intent myIntent = new Intent(view.getContext(), Vol.class);
startActivityForResult(myIntent, 0);

        }});

这是造成麻烦的代码部分 -

Intent myIntent = new Intent(view.getContext(), Vol.class);
startActivityForResult(myIntent, 0);

我不明白为什么会出现 ClassCastException。请帮忙。谢谢!

最佳答案

尝试举办这样的 Activity

@Override
    public void onItemClick(AdapterView<?> a, View v, int position, long id) {
         if(position==0){
             Intent i = new Intent(this, abc.class);
             startActivity(i);

        } else if(position==1){
             Intent i = new Intent(this, xyz.class);
             startActivity(i);

        }

    }

关于Android - ListView 中的 Intent,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6908129/

相关文章:

java - Eclipse 中的 Android 应用程序 : Edit text not showing on Graphical layout

android - 如何在 Android 中的 Listview 的 CustomListAdapter 类中捕获 Intent 的结果

Android 内存泄漏 - 无法正确解除分配位图,内存不足错误 - 位图大小超出 VM 预算 [Mono Android]

android - 如何隐藏 android 最近列表中的最后一个 Activity View ?使用锁屏实现

android - 将消息正文和电话号码发送到 Viber

android - 当应用程序处于后台时,我的 FCM 通知不会展开

android - 如何将 fragment View 的参数(如宽度和高度)获取到 Activity?

android - 应用程序上下文可以在应用程序生命周期中更改吗?

Android Listview 项目点击

Android:如何通过 Intent 实现多选图片?