【问题标题】:How to open a URL in a web browser with an intent from a recycler adapter如何使用回收适配器的意图在 Web 浏览器中打开 URL
【发布时间】:2021-04-10 14:48:24
【问题描述】:

单击后,我无法打开 Web 浏览器以从我的回收站适配器获取 url。 我使用上下文初始化了适配器,但应用程序仍然会崩溃。

public class recyclerAdapter extends RecyclerView.Adapter<recyclerAdapter.ViewHolder> {

private ArrayList<Item> mItems;
    private Context mContext;
    private LayoutInflater mLayoutInflater;

    public RecyclerAdapter(ArrayList<Item> items, Context context) {
        mItems = items;
        mContext = context;
        mLayoutInflater = LayoutInflater.from(mContext);
    }

//other things....

public class ViewHolder extends RecyclerView.ViewHolder{
        public final ImageView mImageView;

        public TopFreeStoreViewHolder(@NonNull View itemView) {
            super(itemView);
            mImageView = itemView.findViewById(R.id.imageViewItem);
            mImageView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    String Url = www.google.com;
                    Intent intent = new Intent(Intent.ACTION_VIEW);
                    intent.setData(Uri.parse(Url));
                    mContext.startActivity(intent);
                }
            });
        }
    }
}

错误:android.content.ActivityNotFoundException:未找到处理 Intent { act=android.intent.action.VIEW dat=www.google.com. }

【问题讨论】:

    标签: java android android-recyclerview onclicklistener android-viewholder


    【解决方案1】:

    您使用的网址格式错误。试试这个,

    String Url = "https://www.google.com";
    

    【讨论】:

    • 这就是我所缺少的
    • @Lekan 如果回答正确,请标记为正确。
    猜你喜欢
    • 2021-07-12
    • 1970-01-01
    • 2013-09-19
    • 2021-05-21
    • 1970-01-01
    • 1970-01-01
    • 2019-04-12
    • 2018-05-02
    • 1970-01-01
    相关资源
    最近更新 更多