Android onClick不处理多视图回收视图

Android onClick不处理多视图回收视图,android,android-recyclerview,Android,Android Recyclerview,我正在处理多视图回收器视图(只有2个视图)。因此,一个视图使用onClick正常工作,但在另一个视图中,当我单击该视图时,第一个视图的内容将加载到下一个活动中 下面是我的适配器代码: public class FeedAdapter extends RecyclerView.Adapter<FeedAdapter.MyViewHolder> { View itemView; View itemView1; private Context context; private List

我正在处理多视图回收器视图(只有2个视图)。因此,一个视图使用onClick正常工作,但在另一个视图中,当我单击该视图时,第一个视图的内容将加载到下一个活动中

下面是我的适配器代码:

public class FeedAdapter extends RecyclerView.Adapter<FeedAdapter.MyViewHolder> {

View itemView;
 View itemView1;
private Context context;
private List<WorldPopulation> worldpopulationlist = null;
private WorldPopulation movie;
private int x, b;

public FeedAdapter(FragmentActivity feeds, List<WorldPopulation> worldpopulationlist) {

    this.context = feeds;
    this.worldpopulationlist = worldpopulationlist;
    ArrayList<WorldPopulation> arraylist = new ArrayList<>();
    arraylist.addAll(worldpopulationlist);
}

@Override
public int getItemViewType(int position) {
    movie = worldpopulationlist.get(position);
    if (movie.getAds() ==1){
        return 1;
    }else  {
        return 0;
    }
}

public class MyViewHolder extends RecyclerView.ViewHolder {

    TextView imageContent, userName, author, authorName, pages, pageNo;
    TextView brandName, brandDescription, brandDescriptionText;
    ImageView feedsImage, brandImage, brandMainImage, userImage;
    View mview;

    public MyViewHolder(View v) {
        super(v);
        mview = v;

        imageContent = (TextView) v.findViewById(R.id.recycler_text);
        feedsImage = (ImageView) v.findViewById(R.id.flag);
        userImage = (ImageView) v.findViewById(R.id.userImage);
        userName = (TextView) v.findViewById(R.id.userName);

        author = (TextView) v.findViewById(R.id.author);
        authorName = (TextView) v.findViewById(R.id.author_name);
        pages = (TextView) v.findViewById(R.id.pages);
        pageNo = (TextView) v.findViewById(R.id.page_no);

        brandName = (TextView) v.findViewById(R.id.brand_name);
        brandDescription = (TextView) v.findViewById(R.id.author_brand_description);
        brandDescriptionText = (TextView) v.findViewById(R.id.author_name_brand_description);
        brandImage = (ImageView) v.findViewById(R.id.brand_image);
        brandMainImage = (ImageView) v.findViewById(R.id.brand_main_image);

    }
}

@Override
public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

    switch (viewType){
        case 1:
            Log.i("sand23","this is game");
            itemView1 = LayoutInflater.from(parent.getContext())
                    .inflate(R.layout.feeds_adv_single_row, parent, false);

            return new MyViewHolder(itemView1);

        case 0:
            Log.i("sand24","this is game2");
            itemView = LayoutInflater.from(parent.getContext())
                    .inflate(R.layout.feeds_single_row, parent, false);

            return new MyViewHolder(itemView);

    }
 return null;
}

@Override
public void onBindViewHolder(MyViewHolder holder, int position) {

    movie = worldpopulationlist.get(holder.getAdapterPosition());
    this.b = holder.getAdapterPosition();

    x = movie.getAds();

    if (x==1){
        holder.brandName.setText(movie.getAuthor_Name());
        holder.brandDescription.setText(movie.getObjectId());  // when setting brandDescription to the objectId it shows objectId ysZicAeoRU which is correct
        holder.brandDescriptionText.setText(movie.getPage_No());

        Picasso.with(context)
                .load(worldpopulationlist.get(holder.getAdapterPosition()).getBrand_Image())
                .into(holder.brandImage);

        Picasso.with(context)
                .load(worldpopulationlist.get(holder.getAdapterPosition()).getFlag())
                .into(holder.brandMainImage);

        holder.mview.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view)          // this onClick  opens objectId 5y6jCCrxxa 
            {

                Intent intent = new Intent(context, AdsActivity.class);

                intent.putExtra("adsNext", worldpopulationlist.get(b).getAdsSecond());

                intent.putExtra("objId", worldpopulationlist.get(b).getObjectId());

                intent.putExtra("brandImage", worldpopulationlist.get(b).getBrand_Image());

                intent.putExtra("brandName", worldpopulationlist.get(b).getAuthor_Name());

                intent.putExtra("link", worldpopulationlist.get(b).getLink());

                intent.putExtra("mobNo", worldpopulationlist.get(b).getCall());

                intent.putExtra("brandDescription", worldpopulationlist.get(b).getPages());

                intent.putExtra("brandDescriptionText", worldpopulationlist.get(b).getPage_No());

                intent.putExtra("contactUs", worldpopulationlist.get(b).getContactUs());

                intent.putExtra("aboutUs", worldpopulationlist.get(b).getAboutUs());

                context.startActivity(intent);
            }
        });

    }else {

        holder.imageContent.setText(movie.getImagesContent());
        holder.userName.setText(movie.getAddress());
        holder.author.setText(movie.getAuthor());
        holder.authorName.setText(movie.getAuthor_Name());
        holder.pages.setText(movie.getPages());
        holder.pageNo.setText(String.valueOf(movie.getClicks()));

        Picasso.with(context)
                .load(worldpopulationlist.get(holder.getAdapterPosition()).getUserImage())
                .into(holder.userImage);

        Picasso.with(context)
                .load(worldpopulationlist.get(holder.getAdapterPosition()).getFlag())
                .into(holder.feedsImage);


        holder.mview.setOnClickListener(new View.OnClickListener()    // this onCLick is working properly
        {
            @Override
            public void onClick(View view) {

                Intent intent = new Intent(context, Feeds_Second.class);

                intent.putExtra("rank", worldpopulationlist.get(b).getImagesContent());

                intent.putExtra("image", worldpopulationlist.get(b).getFlag());

                intent.putExtra("ads", worldpopulationlist.get(b).getAds());

                intent.putExtra("call", worldpopulationlist.get(b).getCall());

                intent.putExtra("objectId", worldpopulationlist.get(b).getObjectId());

                intent.putExtra("contactUs", worldpopulationlist.get(b).getContactUs());

                intent.putExtra("aboutUs", worldpopulationlist.get(b).getAboutUs());

                intent.putExtra("switch", worldpopulationlist.get(b).getSwitches());

                intent.putExtra("link", worldpopulationlist.get(b).getLink());

                intent.putExtra("clicks", worldpopulationlist.get(b).getClicks());


                context.startActivity(intent);
            }
        });
    }
}

@Override
public int getItemCount() {
    return worldpopulationlist.size();
}
公共类FeedAdapter扩展了RecyclerView.Adapter{
查看项目视图;
查看项目视图1;
私人语境;
私有列表worldpopulationlist=null;
私人世界人口电影;
私有int x,b;
公共FeedAdapter(碎片活动源,列表worldpopulationlist){
this.context=feed;
this.worldpopulationlist=worldpopulationlist;
ArrayList ArrayList=新的ArrayList();
arraylist.addAll(世界人口列表);
}
@凌驾
public int getItemViewType(int位置){
movie=worldpopulationlist.get(位置);
if(movie.getAds()==1){
返回1;
}否则{
返回0;
}
}
公共类MyViewHolder扩展了RecyclerView.ViewHolder{
TextView图像内容、用户名、作者、作者姓名、页面、页码;
text查看品牌名称、品牌描述、品牌描述文本;
ImageView feedsImage、brandImage、brandMainImage、userImage;
视图视图;
公共MyViewHolder(视图v){
超级(五);
mview=v;
imageContent=(TextView)v.findViewById(R.id.recycler\u text);
feedsImage=(ImageView)v.findViewById(R.id.flag);
userImage=(ImageView)v.findviewbyd(R.id.userImage);
userName=(TextView)v.findViewById(R.id.userName);
作者=(文本视图)v.findviewbyd(R.id.author);
authorName=(TextView)v.findviewbyd(R.id.author\u name);
pages=(TextView)v.findViewById(R.id.pages);
pageNo=(TextView)v.findViewById(R.id.page_no);
brandName=(TextView)v.findViewById(R.id.brand_name);
brandDescription=(TextView)v.findViewById(R.id.author\u brand\u description);
brandDescriptionText=(TextView)v.findViewById(R.id.author\u name\u brand\u description);
brandImage=(ImageView)v.findViewById(R.id.brand_image);
brandMainImage=(ImageView)v.findViewById(R.id.brand\u main\u image);
}
}
@凌驾
公共MyViewHolder onCreateViewHolder(视图组父级,int-viewType){
开关(视图类型){
案例1:
Log.i(“sand23”,“这是游戏”);
itemView1=LayoutInflater.from(parent.getContext())
.充气(R.layout.feeds\u adv\u single\u row,parent,false);
返回新的MyViewHolder(itemView1);
案例0:
Log.i(“sand24”,“这是game2”);
itemView=LayoutInflater.from(parent.getContext())
.充气(R.layout.feeds\u单行,父级,false);
返回新的MyViewHolder(itemView);
}
返回null;
}
@凌驾
公共无效onBindViewHolder(MyViewHolder,int位置){
movie=worldpopulationlist.get(holder.getAdapterPosition());
this.b=holder.getAdapterPosition();
x=movie.getAds();
如果(x==1){
holder.brandName.setText(movie.getAuthor_Name());
holder.brandDescription.setText(movie.getObjectId());//将brandDescription设置为objectId时,会显示objectId ysZicAeoRU,这是正确的
holder.brandDescriptionText.setText(movie.getPage_No());
毕加索。与(上下文)
.load(worldpopulationlist.get(holder.getAdapterPosition()).getBrand_Image())
.插入(支架.品牌图像);
毕加索。与(上下文)
.load(worldpopulationlist.get(holder.getAdapterPosition()).getFlag())
.into(holder.brandmain图像);
holder.mview.setOnClickListener(新视图.OnClickListener(){
@凌驾
public void onClick(视图)//此onClick打开objectId 5y6jCCrxxa
{
意向意向=新意向(上下文,AdsActivity.class);
intent.putExtra(“adsNext”,worldpopulationlist.get(b.getAdsSecond());
intent.putExtra(“objId”,worldpopulationlist.get(b.getObjectId());
intent.putExtra(“brandImage”,worldpopulationlist.get(b.getBrand_Image());
intent.putExtra(“brandName”,worldpopulationlist.get(b.getAuthor_Name());
intent.putExtra(“link”,worldpopulationlist.get(b.getLink());
intent.putExtra(“mobNo”,worldpopulationlist.get(b.getCall());
intent.putExtra(“brandDescription”,worldpopulationlist.get(b.getPages());
intent.putExtra(“brandDescriptionText”,worldpopulationlist.get(b).getPage_No());
intent.putExtra(“contactUs”,worldpopulationlist.get(b.getContactUs());
intent.putExtra(“aboutUs”,worldpopulationlist.get(b.getAboutUs());
背景。开始触觉(意图);
}
});
}否则{
holder.imageContent.setText(movie.getImagesContent());
holder.userName.setText(movie.getAddress());
holder.author.setText(movie.getAuthor());
holder.authorName.setText(movie.getAuthor_Name());
holder.pages.setText(movie.getPages());
holder.pageNo.setText(String.valueOf(movie.getClicks());
毕加索。与(上下文)
.load(worldpopulationlist.get(holder.getAdapterPosition()).getUserImage())
.into(holder.userImage);
毕加索。与(上下文)
.load(worldpopulationlist.get(holder.getAdapterPosition()).getFlag())
.进入(保持架、饲料箱);
holder.mview.setOnClickListener(new View.OnClickListener()//此onCLick工作正常
{
@凌驾
公共void onClick(视图){
意向意向=新意向(上下文,feed_Second.class);
intent.putExtra(“rank”,worldpopulationlist.get(b.getImagesContent());
intent.putExtra(“image”,worldpopulationlist.get(b.getFlag());
意向。putExtra(“广告”),世界人口
public class FeedAdapter extends RecyclerView.Adapter<FeedAdapter.MyViewHolder> {

View itemView;
private View itemView1;
private Context context;
private List<WorldPopulation> worldpopulationlist = null;
private WorldPopulation movie;
private int x;

public FeedAdapter(FragmentActivity feeds, List<WorldPopulation> worldpopulationlist) {

    this.context = feeds;
    this.worldpopulationlist = worldpopulationlist;
    ArrayList<WorldPopulation> arraylist = new ArrayList<>();
    arraylist.addAll(worldpopulationlist);
}

@Override
public int getItemViewType(int position) {
    movie = worldpopulationlist.get(position);
    if (movie.getAds() == 1) {
        return 1;
    } else {
        return 0;
    }
}

public class MyViewHolder extends RecyclerView.ViewHolder {

    TextView imageContent, userName, author, authorName, pages, pageNo;
    TextView brandName, brandDescription, brandDescriptionText;
    ImageView feedsImage, brandImage, brandMainImage, userImage;
    View mview;

    public MyViewHolder(View v) {
        super(v);
        mview = v;

        imageContent = (TextView) v.findViewById(R.id.recycler_text);
        feedsImage = (ImageView) v.findViewById(R.id.flag);
        userImage = (ImageView) v.findViewById(R.id.userImage);
        userName = (TextView) v.findViewById(R.id.userName);

        author = (TextView) v.findViewById(R.id.author);
        authorName = (TextView) v.findViewById(R.id.author_name);
        pages = (TextView) v.findViewById(R.id.pages);
        pageNo = (TextView) v.findViewById(R.id.page_no);

        brandName = (TextView) v.findViewById(R.id.brand_name);
        brandDescription = (TextView) v.findViewById(R.id.author_brand_description);
        brandDescriptionText = (TextView) v.findViewById(R.id.author_name_brand_description);
        brandImage = (ImageView) v.findViewById(R.id.brand_image);
        brandMainImage = (ImageView) v.findViewById(R.id.brand_main_image);

    }
}

@Override
public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

    switch (viewType) {
        case 1:

            itemView1 = LayoutInflater.from(parent.getContext())
                    .inflate(R.layout.feeds_adv_single_row, parent, false);

            return new MyViewHolder(itemView1);

        case 0:

            itemView = LayoutInflater.from(parent.getContext())
                    .inflate(R.layout.feeds_single_row, parent, false);

            return new MyViewHolder(itemView);

    }
    return null;
}

@Override
public void onBindViewHolder(MyViewHolder holder, final int position) {

    movie = worldpopulationlist.get(holder.getAdapterPosition());

    if (holder.mview == itemView1) {

        holder.mview.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                Intent intent = new Intent(context, AdsActivity.class);

                intent.putExtra("adsNext", worldpopulationlist.get(position).getAdsSecond());

                intent.putExtra("objId", worldpopulationlist.get(position).getObjectId());

                intent.putExtra("brandImage", worldpopulationlist.get(position).getBrand_Image());

                intent.putExtra("brandName", worldpopulationlist.get(position).getAuthor_Name());

                intent.putExtra("link", worldpopulationlist.get(position).getLink());

                intent.putExtra("mobNo", worldpopulationlist.get(position).getCall());

                intent.putExtra("brandDescription", worldpopulationlist.get(position).getPages());

                intent.putExtra("brandDescriptionText", worldpopulationlist.get(position).getPage_No());

                intent.putExtra("contactUs", worldpopulationlist.get(position).getContactUs());

                intent.putExtra("aboutUs", worldpopulationlist.get(position).getAboutUs());


                context.startActivity(intent);
            }
        });

    } else if (holder.mview == itemView) {

        holder.mview.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {


                Intent intent = new Intent(context, Feeds_Second.class);

                intent.putExtra("rank", worldpopulationlist.get(position).getImagesContent());

                intent.putExtra("image", worldpopulationlist.get(position).getFlag());

                intent.putExtra("ads", worldpopulationlist.get(position).getAds());

                intent.putExtra("call", worldpopulationlist.get(position).getCall());

                intent.putExtra("objectId", worldpopulationlist.get(position).getObjectId());

                intent.putExtra("contactUs", worldpopulationlist.get(position).getContactUs());

                intent.putExtra("aboutUs", worldpopulationlist.get(position).getAboutUs());

                intent.putExtra("switch", worldpopulationlist.get(position).getSwitches());

                intent.putExtra("link", worldpopulationlist.get(position).getLink());

                intent.putExtra("clicks", worldpopulationlist.get(position).getClicks());

                context.startActivity(intent);
            }
        });

    }

    x = movie.getAds();



    if (x == 1) {
        holder.brandName.setText(movie.getAuthor_Name());
        holder.brandDescription.setText(movie.getPages());  // when setting brandDescription to the objectId it shows objectId ysZicAeoRU
        holder.brandDescriptionText.setText(movie.getPage_No());

        Picasso.with(context)
                .load(worldpopulationlist.get(holder.getAdapterPosition()).getBrand_Image())
                .into(holder.brandImage);

        Picasso.with(context)
                .load(worldpopulationlist.get(holder.getAdapterPosition()).getFlag())
                .into(holder.brandMainImage);


    } else {

        holder.imageContent.setText(movie.getImagesContent());
        holder.userName.setText(movie.getAddress());
        holder.author.setText(movie.getAuthor());
        holder.authorName.setText(movie.getAuthor_Name());
        holder.pages.setText(movie.getPages());
        holder.pageNo.setText(String.valueOf(movie.getClicks()));

        Picasso.with(context)
                .load(worldpopulationlist.get(holder.getAdapterPosition()).getUserImage())
                .into(holder.userImage);

        Picasso.with(context)
                .load(worldpopulationlist.get(holder.getAdapterPosition()).getFlag())
                .into(holder.feedsImage);
    }
}

@Override
public int getItemCount() {
    return worldpopulationlist.size();
}
    public class MyViewHolder extends RecyclerView.ViewHolder {

        TextView imageContent, userName, author, authorName, pages, pageNo;
        TextView brandName, brandDescription, brandDescriptionText;
        ImageView feedsImage, brandImage, brandMainImage, userImage;
        View mview;

        public MyViewHolder(View v) {
            super(v);
            mview = v;

            imageContent = (TextView) v.findViewById(R.id.recycler_text);
            feedsImage = (ImageView) v.findViewById(R.id.flag);
            userImage = (ImageView) v.findViewById(R.id.userImage);
            userName = (TextView) v.findViewById(R.id.userName);

            author = (TextView) v.findViewById(R.id.author);
            authorName = (TextView) v.findViewById(R.id.author_name);
            pages = (TextView) v.findViewById(R.id.pages);
            pageNo = (TextView) v.findViewById(R.id.page_no);

            brandName = (TextView) v.findViewById(R.id.brand_name);
            brandDescription = (TextView) v.findViewById(R.id.author_brand_description);
            brandDescriptionText = (TextView) v.findViewById(R.id.author_name_brand_description);
            brandImage = (ImageView) v.findViewById(R.id.brand_image);
            brandMainImage = (ImageView) v.findViewById(R.id.brand_main_image);

            v.setOnClickListener(new View.OnClickListener() {
             @Override
             public void onClick(View view) {
                int pos = getAdapterPosition();
                WorldPopulation movie = worldpopulationlist.get(holder.getAdapterPosition());
                if(movie.getAds()==1){
                 Intent intent = new Intent(context, AdsActivity.class);

                intent.putExtra("adsNext", worldpopulationlist.get(b).getAdsSecond());

                intent.putExtra("objId", worldpopulationlist.get(b).getObjectId());

                intent.putExtra("brandImage", worldpopulationlist.get(b).getBrand_Image());

                intent.putExtra("brandName", worldpopulationlist.get(b).getAuthor_Name());

                intent.putExtra("link", worldpopulationlist.get(b).getLink());

                intent.putExtra("mobNo", worldpopulationlist.get(b).getCall());

                intent.putExtra("brandDescription", worldpopulationlist.get(b).getPages());

                intent.putExtra("brandDescriptionText", worldpopulationlist.get(b).getPage_No());

                intent.putExtra("contactUs", worldpopulationlist.get(b).getContactUs());

                intent.putExtra("aboutUs", worldpopulationlist.get(b).getAboutUs());

                context.startActivity(intent);
                }else{
                  Intent intent = new Intent(context, Feeds_Second.class);

                intent.putExtra("rank", worldpopulationlist.get(b).getImagesContent());

                intent.putExtra("image", worldpopulationlist.get(b).getFlag());

                intent.putExtra("ads", worldpopulationlist.get(b).getAds());

                intent.putExtra("call", worldpopulationlist.get(b).getCall());

                intent.putExtra("objectId", worldpopulationlist.get(b).getObjectId());

                intent.putExtra("contactUs", worldpopulationlist.get(b).getContactUs());

                intent.putExtra("aboutUs", worldpopulationlist.get(b).getAboutUs());

                intent.putExtra("switch", worldpopulationlist.get(b).getSwitches());

                intent.putExtra("link", worldpopulationlist.get(b).getLink());

                intent.putExtra("clicks", worldpopulationlist.get(b).getClicks());


                context.startActivity(intent);
                }
             }
         });
        }
    }