【问题标题】:I want to open Adapter class when I click the imageView but i get ActivityNotFoundException,any alternative method to do so?我想在单击 imageView 时打开 Adapter 类,但我得到 ActivityNotFoundException,有什么替代方法吗?
【发布时间】:2021-03-08 06:07:21
【问题描述】:

@覆盖 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?

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

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

【问题讨论】:

  • “打开这个适配器类”是什么意思?通常,适配器用于一小部分 UI,例如列表中的一行。

标签: java android adapter


【解决方案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);

【讨论】:

    猜你喜欢
    • 2018-12-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-07-01
    • 2017-08-08
    • 2017-06-08
    • 2021-08-20
    • 2017-03-02
    相关资源
    最近更新 更多