I don't really understand the structure of the views you're using.
But, anyway, the idea behind a "RecyclerView" is that it recycles and
reuses the views that are part of the list. It uses a "limited" pool of
inflated views, and "binds" them to the data that's needed on the screen.
So, if you click a star, and change the image to "filled", when that view
is reused, it will still be "filled". You need to choose the image on
the onBindViewHolder,
not only on the onClick for the star.

Marina

PS:  If you use "Search_Result_Adapter extends RecyclerView.Adapter<
ChildViewHolder>" you can save yourself all the casts to ChildViewHolder on
the whole adapter.


On Fri, Dec 30, 2016 at 11:24 PM, Jagapathi Chowdary <
[email protected]> wrote:

> this is my code
>
>
> import android.Manifest;
> import android.app.Activity;
> import android.content.Intent;
> import android.content.pm.PackageManager;
> import android.net.Uri;
> import android.os.Build;
> import android.support.v4.app.ActivityCompat;
> import android.support.v7.widget.RecyclerView;
> import android.view.LayoutInflater;
> import android.view.View;
> import android.view.ViewGroup;
> import android.widget.ImageView;
> import android.widget.LinearLayout;
> import android.widget.TextView;
> import android.widget.Toast;
>
> import java.util.ArrayList;
>
> /**
>  * Created by PPS on 4/2/2016.
>  */
> public class Search_Result_Adapter extends 
> RecyclerView.Adapter<RecyclerView.ViewHolder>
> {
>     private final int HEADER = 0;
>     private final int CHILD = 1;
>     final private int REQUEST_CODE_ASK_PERMISSION = 123;
>     Activity activity;
>     private ArrayList<Integer> star_check = new ArrayList<Integer>();
>     private ArrayList<String> user_id_list = new ArrayList<String>();
>     private ArrayList<Object> data;
>     private int click_position, star = 0;
>     private Intent callIntent;
>
>     public Search_Result_Adapter(Activity activity, ArrayList<Object>
> data) {
>         this.activity = activity;
>         this.data = data;
>     }
>
>     @Override
>     public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent,
> int viewType) {
>
>         RecyclerView.ViewHolder holder = null;
>         ArrayList<String> save_value = new ArrayList<>();
>         save_value.add("0");
>         DataHold.getInstance().setUser_list(save_value);
>
>         LayoutInflater inflater = LayoutInflater.from(parent.
> getContext());
>         switch (viewType) {
>             case HEADER:
>                 View v_parent = 
> inflater.inflate(R.layout.search_parent_result,
> parent, false);
>                 holder = new ParentViewHolder(v_parent);
>
>                 break;
>             case CHILD:
>                 View v_child = inflater.inflate(R.layout.search_child_result,
> parent, false);
>                 holder = new ChildViewHolder(v_child);
>                 break;
>
>             default:
>                 View v_parent1 = 
> inflater.inflate(R.layout.search_parent_result,
> parent, false);
>                 holder = new ParentViewHolder(v_parent1);
> //                Toast.makeText(activity.getApplicationContext(), "" +
> data.size(), Toast.LENGTH_SHORT).show();
>                 break;
>         }
>         return holder;
>     }
>
>     @Override
>     public void onBindViewHolder(final RecyclerView.ViewHolder holder,
> final int position) {
>
>         if (holder.getItemViewType() == HEADER) {
>             Search_Header_Model headermodel = (Search_Header_Model)
> data.get(position);
>             ((ParentViewHolder) holder).address.setText(
> headermodel.getAddress());
> //            Toast.makeText(activity.getApplicationContext(), "Header:
> "+headermodel.getAddress(), Toast.LENGTH_SHORT).show();
>         } else if (holder.getItemViewType() == CHILD) {
>             final Search_Child_Model child_model = (Search_Child_Model)
> data.get(position);
>             ((ChildViewHolder) holder).row1.setText(child_
> model.getRow1());
>             ((ChildViewHolder) holder).row2.setText(child_
> model.getRow2());
>             ((ChildViewHolder) holder).row3.setText(child_
> model.getRow3());
>             ((ChildViewHolder) holder).row4.setText(child_
> model.getRow4());
>             ((ChildViewHolder) holder).row5.setText(child_
> model.getRow5());
>             ((ChildViewHolder) holder).image2.setOnClickListener(new
> View.OnClickListener() {
>                 @Override
>                 public void onClick(View view) {
>
>                     if 
> (star_check.contains(((ChildViewHolder)holder).getAdapterPosition()))
> {
>                         for (int i = 0; i < star_check.size(); i++) {
>                             if (star_check.get(i) ==
> ((ChildViewHolder)holder).getAdapterPosition()) {
>                                 star_check.remove(i);
>                                 ((ChildViewHolder) holder).image2.
> setImageResource(R.mipmap.single_blank);
>                             }
>                         }
>                         updateUserList();
>                     }
>                     else {
>                             ((ChildViewHolder) holder).image2.
> setImageResource(R.mipmap.single_filed);
>                             star_check.add(((ChildViewHolder)holder).
> getAdapterPosition());
>
>                         updateUserList();
>                     }
>                 }
>
>                 private void updateUserList() {
>                     DataHold.getInstance().setSave_check("0");
>
>                     user_id_list.add(child_model.getUser_id());
>                     DataHold.getInstance().setUser_list(user_id_list);
>                 }
>             });
>             ((ChildViewHolder) holder).row1.setOnClickListener(new
> View.OnClickListener() {
>                 @Override
>                 public void onClick(View v) {
>
>                     click_position = position;
>                     final Search_Child_Model child_model_click =
> (Search_Child_Model) data.get(click_position);
>
>                     Dialog_Screen_row dsc = new
> Dialog_Screen_row(activity, R.style.AlertDialogCustom,
>                             child_model_click.getRow1(),
> child_model_click.getRow2(), child_model_click.getRow3(),
>                             child_model_click.getRow4(),
> child_model_click.getRow5(), child_model.getRow5(),
>                             child_model.getMobile(),
> child_model.getUser_id(), child_model.getDate(), child_model.getComment());
>                     dsc.setCanceledOnTouchOutside(true);
>                     dsc.show();
>                 }
>
>             });
>
>             ((ChildViewHolder) holder).row2.setOnClickListener(new
> View.OnClickListener() {
>                 @Override
>                 public void onClick(View view) {
>                     click_position = position;
>                     final Search_Child_Model child_model_click =
> (Search_Child_Model) data.get(click_position);
>
>                     Dialog_Screen_row dsc = new
> Dialog_Screen_row(activity, R.style.AlertDialogCustom,
>                             child_model_click.getRow1(),
> child_model_click.getRow2(), child_model_click.getRow3(),
>                             child_model_click.getRow4(),
> child_model_click.getRow5(), child_model.getRow5(),
>                             child_model.getMobile(),
> child_model.getUser_id(), child_model.getDate(), child_model.getComment());
>                     dsc.setCanceledOnTouchOutside(true);
>                     dsc.show();
>                 }
>             });
>             ((ChildViewHolder) holder).row3.setOnClickListener(new
> View.OnClickListener() {
>                 @Override
>                 public void onClick(View view) {
>                     click_position = position;
>                     final Search_Child_Model child_model_click =
> (Search_Child_Model) data.get(click_position);
>
>                     Dialog_Screen_row dsc = new
> Dialog_Screen_row(activity, R.style.AlertDialogCustom,
>                             child_model_click.getRow1(),
> child_model_click.getRow2(), child_model_click.getRow3(),
>                             child_model_click.getRow4(),
> child_model_click.getRow5(), child_model.getRow5(),
>                             child_model.getMobile(),
> child_model.getUser_id(), child_model.getDate(), child_model.getComment());
>                     dsc.setCanceledOnTouchOutside(true);
>                     dsc.show();
>                 }
>             });
>             ((ChildViewHolder) holder).row4.setOnClickListener(new
> View.OnClickListener() {
>                 @Override
>                 public void onClick(View view) {
>                     click_position = position;
>                     final Search_Child_Model child_model_click =
> (Search_Child_Model) data.get(click_position);
>
>                     Dialog_Screen_row dsc = new
> Dialog_Screen_row(activity, R.style.AlertDialogCustom,
>                             child_model_click.getRow1(),
> child_model_click.getRow2(), child_model_click.getRow3(),
>                             child_model_click.getRow4(),
> child_model_click.getRow5(), child_model.getRow5(),
>                             child_model.getMobile(),
> child_model.getUser_id(), child_model.getDate(), child_model.getComment());
>                     dsc.setCanceledOnTouchOutside(true);
>                     dsc.show();
>                 }
>             });
>             ((ChildViewHolder) holder).row5.setOnClickListener(new
> View.OnClickListener() {
>                 @Override
>                 public void onClick(View view) {
>                     click_position = position;
>                     final Search_Child_Model child_model_click =
> (Search_Child_Model) data.get(click_position);
>
>                     Dialog_Screen_row dsc = new
> Dialog_Screen_row(activity, R.style.AlertDialogCustom,
>                             child_model_click.getRow1(),
> child_model_click.getRow2(), child_model_click.getRow3(),
>                             child_model_click.getRow4(),
> child_model_click.getRow5(), child_model.getRow5(),
>                             child_model.getMobile(),
> child_model.getUser_id(), child_model.getDate(), child_model.getComment());
>                     dsc.setCanceledOnTouchOutside(true);
>                     dsc.show();
>                 }
>             });
>
>             ((ChildViewHolder) holder).image3.setOnClickListener(new
> View.OnClickListener() {
>                 @Override
>                 public void onClick(View v) {
>                     Dialog_Screen_x ds = new Dialog_Screen_x(activity,
> R.style.AlertDialogCustom, child_model.getMobile(),
> child_model.getUser_id(), "yes");
>                     ds.setCanceledOnTouchOutside(true);
>                     ds.show();
>                 }
>             });
>             ((ChildViewHolder) holder).image1.setOnClickListener(new
> View.OnClickListener() {
>
>                 @Override
>                 public void onClick(View v) {
>                     String mnumber = child_model.getMobile();
>                     if (mnumber == null) {
>                         mnumber = "";
>                     }
>
>                     if (mnumber.length() > 1) {
>
>                         callIntent = new Intent(Intent.ACTION_CALL);
>                         callIntent.setData(Uri.parse("tel:" +
> Uri.encode(mnumber.trim())));
>                         callIntent.setFlags(Intent.
> FLAG_ACTIVITY_NEW_TASK);
>                         if (ActivityCompat.checkSelfPermission(activity,
> Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {
>                             // TODO: Consider calling
>                             //    ActivityCompat#requestPermissions
>                             // here to request the missing permissions,
> and then overriding
>                             //   public void
> onRequestPermissionsResult(int requestCode, String[] permissions,
>                             //
>  int[] grantResults)
>                             // to handle the case where the user grants
> the permission. See the documentation
>                             // for ActivityCompat#requestPermissions for
> more details.
>                             if (Build.VERSION.SDK_INT >=
> Build.VERSION_CODES.M) {
>                                 activity.requestPermissions(new
> String[]{Manifest.permission.CALL_PHONE}, REQUEST_CODE_ASK_PERMISSION);
>                             }
>                         }
>                         activity.startActivity(callIntent);
>                     } else {
>                         Toast.makeText(activity, "No Number Found",
> Toast.LENGTH_SHORT).show();
>                     }
>                 }
>             });
>         } else {
>             Toast.makeText(activity, "No data found",
> Toast.LENGTH_SHORT).show();
>         }
>     }
>
>
>     @Override
>     public int getItemViewType(int position1) {
>         if (data.get(position1) instanceof Search_Header_Model) {
>             return HEADER;
>         } else if (data.get(position1) instanceof Search_Child_Model) {
>             return CHILD;
>         } else {
>             return -1;
>         }
>     }
>
>     @Override
>     public int getItemCount() {
>         return data.size();
>     }
>
>
>     private class ParentViewHolder extends RecyclerView.ViewHolder {
>         TextView address;
>
>         ParentViewHolder(View itemView) {
>             super(itemView);
>
>             address = (TextView) itemView.findViewById(R.id.text_head);
>         }
>     }
>
>     private class ChildViewHolder extends RecyclerView.ViewHolder
> implements View.OnClickListener {
>         private TextView row1, row2, row3, row4, row5;
>         private ImageView image1, image2, image3;
>         private LinearLayout linear1;
>
>         ChildViewHolder(View itemView) {
>             super(itemView);
>             linear1 = (LinearLayout) itemView.findViewById(R.id.
> linear111);
>             row1 = (AutoResizeTextView) itemView.findViewById(R.id.row1);
>             row2 = (AutoResizeTextView) itemView.findViewById(R.id.row2);
>             row3 = (AutoResizeTextView) itemView.findViewById(R.id.row3);
>             row4 = (AutoResizeTextView) itemView.findViewById(R.id.row4);
>             row5 = (AutoResizeTextView) itemView.findViewById(R.id.row5);
>             image1 = (ImageView) itemView.findViewById(R.id.row_image1);
>             image2 = (ImageView) itemView.findViewById(R.id.row_image2);
>             image2.setOnClickListener(this);
>             image3 = (ImageView) itemView.findViewById(R.id.row_image3);
>         }
>
>         @Override
>         public void onClick(View view) {
>
>         }
>     }
>
> }
>
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Android Developers" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at https://groups.google.com/group/android-developers.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/android-developers/1d973e31-d44d-4080-9b05-
> bfde2e2700a7%40googlegroups.com
> <https://groups.google.com/d/msgid/android-developers/1d973e31-d44d-4080-9b05-bfde2e2700a7%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/android-developers.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/android-developers/CACaNmX0%2BsndHBNTn53Z2wcR3P4-9GQN%2Boc0YcsBmFeorrLGjAQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to