我想在单击 imageView 时打开 Adapter 类,但出现 ActivityNotFoundException,有什么替代方法可以这样做?

发布时间:2021-03-07 21:51

@覆盖 public void onClick(View v) {

    int i = v.getId();

    if (i==R.id.cars){

        Intent open_adapter_class = new Intent(this,ItemsAdapter.class);

        startActivity(open_adapter_class );

}

}

//这是我得到的错误

android.content.ActivityNotFoundException:无法找到显式活动类

{com.dikolobe.salesagent/com.dikolobe.salesagent.ItemsAdapter};你有没有在你的

AndroidManifest.xml?

我知道我收到此错误,因为适配器不是活动,所以我只想获得有关如何操作的帮助

如果有办法打开这个适配器类

回答1

来自 Android 文档:

<块引用>

意图是对要执行的操作的抽象描述。 它可以与 startActivity 一起使用来启动一个 Activity, broadcastIntent 将其发送给任何感兴趣的 BroadcastReceiver 组件和 Context.startService(Intent)

因此,ItemsAdapter 必须是一个活动(例如...扩展 AppCompatActivity),以便您从一个活动更改为另一个活动。

但是你能做的是pass an object from that class to another activity

Intent open_adapter_class = new Intent(this,ItemsAdapter.class);