java—如何在web浏览器中打开一个url,并从回收器适配器获得一个意图

mzsu5hc0  于 2021-06-27  发布在  Java
关注(0)|答案(1)|浏览(346)

单击后,我无法打开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. }

fkvaft9z

fkvaft9z1#

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

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

相关问题