Senario: To get rating feedback for multiple multiple products.
Problem: Ratingbar value resets on scrolling listview by calling setOnRatingBarChangeListener
Expected output:
Customized listview adpater code:
public class FeedbackAdapter extends BaseAdapter {
static Context context;
List<FeedbackRowDetails> row;
ViewHolder holder;
public FeedbackAdapter(Context context,List<FeedbackRowDetails> row)
{
this.context = context;
this.row =row;
}
private class ViewHolder {
TextView tv_slno, tv_productname, tv_time;
RatingBar rb_productrating;
}
#Override
public View getView( final int position, View convertView, ViewGroup parent) {
LayoutInflater mInflater = (LayoutInflater) context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
if (convertView == null)
{
convertView = mInflater.inflate(R.layout.custom_feedback_row_format,null);
holder = new ViewHolder();
holder.tv_slno = (TextView) convertView.findViewById(R.id.tv_slno);
holder.tv_time = (TextView) convertView.findViewById(R.id.tv_time);
holder.tv_productname = (TextView) convertView.findViewById(R.id.tv_productname);
holder.rb_productrating=(RatingBar) convertView.findViewById(R.id.rb_productrating);
convertView.setTag(holder);
} else
{
holder = (ViewHolder) convertView.getTag();
}
FeedbackRowDetails row_pos = row.get(position);
holder.tv_slno.setText(String.valueOf(position + 1));
holder.tv_time.setText(row_pos.gettime());
holder.tv_productname.setText(row_pos.getproductsName());
holder.rb_productrating.setRating(Float.valueOf(row_pos.getrating()));
holder.rb_productrating.setOnRatingBarChangeListener(new OnRatingBarChangeListener()
{
public void onRatingChanged(RatingBar ratingBar, float rating,boolean fromUser)
{
FeedbackRowDetails row_pos = row.get(position);
int roundoff_rating = (int)Math.round(rating);
ratingBar.setRating(roundoff_rating);
row_pos.setrating(String.valueOf(roundoff_rating));
}
});
return convertView;
}
#Override
public int getCount() {
return row.size();
}
#Override
public Object getItem(int position) {
return row.get(position);
}
#Override
public long getItemId(int position) {
return row.indexOf(getItem(position));
}
}
Just wrap your codes present inside your onRatingChanged method with a simple if as shown below
if(fromUser) {
FeedbackRowDetails row_pos = row.get(position);
int roundoff_rating = (int) Math.round(rating);
ratingBar.setRating(roundoff_rating);
row_pos.setRating(String.valueOf(roundoff_rating));
}
Have tested it with emulator and it was working as expected. Hope this solves your problem
This problem solved with reference to link
public class FeedbackAdapter extends BaseAdapter {
static Context context;
List<FeedbackRowDetails> row;
ViewHolder holder;
public FeedbackAdapter(Context context,List<FeedbackRowDetails> row)
{
this.context = context;
this.row =row;
}
private class ViewHolder {
TextView tv_slno, tv_productname, tv_time;
RatingBar rb_productrating;
}
#Override
public View getView( final int position, View convertView, ViewGroup parent) {
LayoutInflater mInflater = (LayoutInflater) context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
if (convertView == null)
{
convertView = mInflater.inflate(R.layout.custom_feedback_row_format,parent, false);
holder = new ViewHolder();
holder.tv_slno = (TextView) convertView.findViewById(R.id.tv_slno);
holder.tv_time = (TextView) convertView.findViewById(R.id.tv_time);
holder.tv_productname = (TextView) convertView.findViewById(R.id.tv_productname);
holder.rb_productrating=(RatingBar) convertView.findViewById(R.id.rb_productrating);
convertView.setTag(holder);
} else
{
holder = (ViewHolder) convertView.getTag();
}
holder.rb_productrating.setOnRatingBarChangeListener(onRatingChangedListener(holder, position));
holder.rb_productrating.setTag(position);
holder.tv_slno.setText(String.valueOf(position + 1));
holder.tv_time.setText(getItem(position).gettime());
holder.tv_productname.setText(getItem(position).getproductsName());
float rating=Float.valueOf(getItem(position).getrating());
holder.rb_productrating.setRating(rating);
return convertView;
}
private RatingBar.OnRatingBarChangeListener onRatingChangedListener(final ViewHolder holder, final int position)
{
return new RatingBar.OnRatingBarChangeListener() {
#Override
public void onRatingChanged(RatingBar ratingBar, float rating, boolean b)
{
FeedbackRowDetails item = row.get(position);
int roundoff_rating = (int)Math.round(rating);
ratingBar.setRating(roundoff_rating);
item.setrating(String.valueOf(roundoff_rating));
}
};
}
#Override
public int getCount() {
return row.size();
}
#Override
public FeedbackRowDetails getItem(int position)
{
return row.get(position);
}
#Override
public long getItemId(int position) {
return row.indexOf(getItem(position));
}
}
Related
I want to convert Listview to RecyclerView in my app, I tried to convert code but stucked at getView method, can any one explain how to use this getView code in Recylcer view.
Adapter for ListView CardAdapter.java
public class CardAdapter extends ArrayAdapter<CardDataModel> {
private Context context;
List<CardDataModel> cards;
SharedPreference sharedPreference;
public CardAdapter(Context context, List<CardDataModel> cards) {
super(context, R.layout.card_list_item, cards);
this.context = context;
this.cards = cards;
sharedPreference = new SharedPreference();
}
private class ViewHolder {
TextView CardNameTxt;
TextView CardDescTxt;
TextView CardPriceTxt;
ImageView favoriteImg;
}
#Override
public int getCount() {
return cards.size();
}
#Override
public CardDataModel getItem(int position) {
return cards.get(position);
}
#Override
public long getItemId(int position) {
return 0;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder = null;
if (convertView == null) {
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.card_list_item, null);
holder = new ViewHolder();
holder.CardNameTxt = (TextView) convertView
.findViewById(R.id.txt_crd_name);
holder.CardDescTxt = (TextView) convertView
.findViewById(R.id.txt_crd_desc);
holder.CardPriceTxt = (TextView) convertView
.findViewById(R.id.txt_crd_no);
holder.favoriteImg = (ImageView) convertView
.findViewById(R.id.imgbtn_favorite);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
CardDataModel card = (CardDataModel) getItem(position);
holder.CardNameTxt.setText(card.getName());
holder.CardDescTxt.setText(card.getDescription());
holder.CardPriceTxt.setText(card.getPrice() + " ");
/*If a product exists in shared preferences then set heart_red drawable
* and set a tag*/
if (checkFavoriteItem(card)) {
holder.favoriteImg.setImageResource(R.drawable.heart_red);
holder.favoriteImg.setTag("red");
} else {
holder.favoriteImg.setImageResource(R.drawable.heart_grey);
holder.favoriteImg.setTag("grey");
}
return convertView;
}
public boolean checkFavoriteItem(CardDataModel checkCard) {
boolean check = false;
List<CardDataModel> favorites = sharedPreference.getFavorites(context);
if (favorites != null) {
for (CardDataModel card : favorites) {
if (card.equals(checkCard)) {
check = true;
break;
}
}
}
return check;
}
#Override
public void add(CardDataModel card) {
super.add(card);
cards.add(card);
notifyDataSetChanged();
}
#Override
public void remove(CardDataModel card) {
super.remove(card);
cards.remove(card);
notifyDataSetChanged();
}
}
converted somecode like this in RecyclerView Adapter ... CardRvAdapter.java
public class CardRvAdapter extends RecyclerView.Adapter<CardRvAdapter.MyViewHolder> {
private Context context;
List<CardDataModel> cards;
SharedPreference sharedPreference;
public CardRvAdapter(Context context, List<CardDataModel> cards) {
this.context = context;
this.cards = cards;
sharedPreference = new SharedPreference(); }
#Override
public int getItemCount() {
return cards.size();
}
#NonNull
#Override
public MyViewHolder onCreateViewHolder(#NonNull ViewGroup viewGroup, int i) {
// on create view holder code
View view;
LayoutInflater mInflater = LayoutInflater.from(context);
view = mInflater.inflate(R.layout.card_list_item, viewGroup,false);
return new MyViewHolder(view);
}
#Override
public void onBindViewHolder(#NonNull MyViewHolder myViewHolder, int i) {
//on bind view holder code
myViewHolder.CardPriceTxt.setText(cards.get(i).getPrice());
myViewHolder.CardNameTxt.setText(cards.get(i).getName());
myViewHolder.CardDescTxt.setText(cards.get(i).getDescription());
if (checkFavoriteItem(card)) {
myViewHolder.favoriteImg.setImageResource(R.drawable.heart_red);
myViewHolder.favoriteImg.setTag("red");
} else {
myViewHolder.favoriteImg.setImageResource(R.drawable.heart_grey);
myViewHolder.favoriteImg.setTag("grey");
} }
// checking for favotites in shared preferences
public boolean checkFavoriteItem(CardDataModel checkCard) {
boolean check = false;
List<CardDataModel> favorites = sharedPreference.getFavorites(context);
if (favorites != null) {
for (CardDataModel card : favorites) {
if (card.equals(checkCard)) {
check = true;
break;
}
}
}
return check;
}
#Override
public void add(CardDataModel card) {
super.add(card);
cards.add(card);
notifyDataSetChanged();
}
#Override
public void remove(CardDataModel card) {
super.remove(card);
cards.remove(card);
notifyDataSetChanged();
}
public class MyViewHolder extends RecyclerView.ViewHolder {
TextView CardNameTxt;
TextView CardDescTxt;
TextView CardPriceTxt;
ImageView favoriteImg;
public MyViewHolder(#NonNull View itemView) {
super(itemView);
this.CardDescTxt = (TextView) itemView.findViewById(R.id.txt_crd_desc);
this.CardNameTxt = (TextView) itemView.findViewById(R.id.txt_crd_name);
this.CardPriceTxt = (TextView) itemView.findViewById(R.id.txt_crd_no);
this.favoriteImg = (ImageView) itemView.findViewById(R.id.imgbtn_favorite);
}}}
The problem part..
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder = null;
if (convertView == null) {
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.card_list_item, null);
holder = new ViewHolder();
holder.CardNameTxt = (TextView) convertView
.findViewById(R.id.txt_crd_name);
holder.CardDescTxt = (TextView) convertView
.findViewById(R.id.txt_crd_desc);
holder.CardPriceTxt = (TextView) convertView
.findViewById(R.id.txt_crd_no);
holder.favoriteImg = (ImageView) convertView
.findViewById(R.id.imgbtn_favorite);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
CardDataModel card = (CardDataModel) getItem(position);
holder.CardNameTxt.setText(card.getName());
holder.CardDescTxt.setText(card.getDescription());
holder.CardPriceTxt.setText(card.getPrice() + " ");
/*If a product exists in shared preferences then set heart_red drawable
* and set a tag*/
if (checkFavoriteItem(card)) {
holder.favoriteImg.setImageResource(R.drawable.heart_red);
holder.favoriteImg.setTag("red");
} else {
holder.favoriteImg.setImageResource(R.drawable.heart_grey);
holder.favoriteImg.setTag("grey");
}
return convertView;
}
How to modify this code and where to add this checkFavItem, add , and remove methods..suggest me , i am new to android development.
Finishing RecyclerView Code
// specify the row layout file and click for each row
#Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(listItemLayout, parent, false);
ViewHolder myViewHolder = new ViewHolder(view);
return myViewHolder;
}
// load data in each row element
#Override
public void onBindViewHolder(final ViewHolder holder, final int listPosition) {
TextView item = holder.item;
item.setText(itemList.get(listPosition).getName());
}
when i was trying tutorial checkbox in listview theres some error on my adapter
public View getView(int position, View convertView, ViewGroup parent) {
ViewTag viewTag;
if (convertView == null) {
//取得listItem容器 view
convertView = myInflater.inflate(R.layout.list_item_pegawai, null);
//建構listItem內容view
viewTag = new ViewTag(
(TextView) convertView.findViewById(R.id.txt_namapegawai),
(CheckBox) convertView.findViewById(R.id.checkBox_pegawai));
//設置容器內容
convertView.setTag(viewTag);
} else {
viewTag = (ViewTag) convertView.getTag();
}
complete code
public class CustomAdapter extends BaseAdapter {
private Context context;
public static ArrayList<Model> modelArrayList;
public CustomAdapter(Context context, ArrayList<Model> modelArrayList) {
this.context = context;
CustomAdapter.modelArrayList = modelArrayList;
}
#Override
public int getViewTypeCount() {
return getCount();
}
#Override
public int getItemViewType(int position) {
return position;
}
#Override
public int getCount() {
return modelArrayList.size();
}
#Override
public Object getItem(int position) {
return modelArrayList.get(position);
}
#Override
public long getItemId(int position) {
return 0;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
final ViewHolder holder;
if (convertView == null) {
holder = new ViewHolder();
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.list_item_select, null, true);
holder.checkBox = convertView.findViewById(R.id.checkBox);
holder.tvName = convertView.findViewById(R.id.textView7);
holder.Tvnumber = convertView.findViewById(R.id.textView8);
convertView.setTag(holder);
} else {
// the getTag returns the viewHolder object set as a tag to the view
holder = (ViewHolder) convertView.getTag();
}
holder.tvName.setText(modelArrayList.get(position).getName());
holder.Tvnumber.setText(modelArrayList.get(position).getPhone());
holder.checkBox.setChecked(modelArrayList.get(position).getSelected());
holder.checkBox.setTag(R.integer.btnplusview, convertView);
holder.checkBox.setTag(position);
holder.checkBox.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
View tempview = (View) holder.checkBox.getTag(R.integer.btnplusview);
TextView tv = tempview.findViewById(R.id.textView7);
Integer pos = (Integer) holder.checkBox.getTag();
if (modelArrayList.get(pos).getSelected()) {
modelArrayList.get(pos).setSelected(false);
} else {
modelArrayList.get(pos).setSelected(true);
}
}
});
return convertView;
}
private class ViewHolder {
protected CheckBox checkBox;
private TextView tvName;
private TextView Tvnumber;
}
}
Rating bar is resets when we scroll down in android, I need to send the response of rating feedback to server but it will resets or not saved when i scroll down in listview in android.
public class FacultyListAdapter extends BaseAdapter {
private final Context context;
public FacultyListAdapter(Context context) {
this.context = context;
if (!facultylist.isEmpty())
courseEmptyLayout.setVisibility(LinearLayout.GONE);
}
#Override
public View getView(final int position, View convertView,
ViewGroup parent) {
final ViewHolder TabviewHolder;
if (convertView == null) {
TabviewHolder = new ViewHolder();
LayoutInflater inflater = getLayoutInflater();
convertView = inflater.inflate(R.layout.list_item_feedback,
parent, false);
TabviewHolder.FacultyName = (TextView) convertView.findViewById(R.id.FacultyName);//facultyname
TabviewHolder.rating = (RatingBar) convertView.findViewById(R.id.rating);//rating starts
TabviewHolder.Submit = (Button) convertView.findViewById(R.id.btnSubmit);
// Save the holder with the view
convertView.setTag(TabviewHolder);
} else {
TabviewHolder = (ViewHolder) convertView.getTag();
}
final Faculty mFac = facultylist.get(position);//*****************************NOTICE
TabviewHolder.FacultyName.setText(mFac.getEmployeename());
TabviewHolder.rating.setTag(position);
TabviewHolder.rating.setRating(mFac.getRatingStar());
// TabviewHolder.ModuleName.setText(mFac.getSubject());
TabviewHolder.rating.setOnRatingBarChangeListener(new RatingBar.OnRatingBarChangeListener() {
public void onRatingChanged(RatingBar ratingBar, float rating,
boolean fromUser) {
feedbackresult =String.valueOf(rating);
TabviewHolder.rating.setRating(Float.parseFloat(feedbackresult));
Log.d("feedback","feedback is: "+ feedbackresult);
}
});
return convertView;
}
/*private RatingBar.OnRatingBarChangeListener onRatingChangedListener(final ViewHolder holder, final int position) {
return new RatingBar.OnRatingBarChangeListener() {
#Override
public void onRatingChanged(RatingBar ratingBar, float v, boolean b) {
FacultyName item = getItem(position);
item.setRatingStar(v);
Log.i("Adapter", "star: " + v);
}
};
}*/
#Override
public int getCount() {
return facultylist.size();
}
#Override
public Object getItem(int position) {return facultylist.get(position);
}
#Override
public long getItemId(int position) {
return position;
}
}
Listview and recyclerview auto refresh (recreate) view based on your list passed to it when you scroll.
You have to store your rating to your List<> (i think it is facultylist) in which you contains all details.
When user click on rating you need to store rating to particular index. Then your listview show correct rating based on value in list.
refer this link Rating Bar in ListView Android
public class FeedbackAdapter extends BaseAdapter {
static Context context;
List<FeedbackRowDetails> row;
ViewHolder holder;
public FeedbackAdapter(Context context,List<FeedbackRowDetails> row)
{
this.context = context;
this.row =row;
}
private class ViewHolder {
TextView tv_slno, tv_productname, tv_time;
RatingBar rb_productrating;
}
#Override
public View getView( final int position, View convertView, ViewGroup parent) {
LayoutInflater mInflater = (LayoutInflater) context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
if (convertView == null)
{
convertView = mInflater.inflate(R.layout.custom_feedback_row_format,parent, false);
holder = new ViewHolder();
holder.tv_slno = (TextView) convertView.findViewById(R.id.tv_slno);
holder.tv_time = (TextView) convertView.findViewById(R.id.tv_time);
holder.tv_productname = (TextView) convertView.findViewById(R.id.tv_productname);
holder.rb_productrating=(RatingBar) convertView.findViewById(R.id.rb_productrating);
convertView.setTag(holder);
} else
{
holder = (ViewHolder) convertView.getTag();
}
holder.rb_productrating.setOnRatingBarChangeListener(onRatingChangedListener(holder, position));
holder.rb_productrating.setTag(position);
holder.tv_slno.setText(String.valueOf(position + 1));
holder.tv_time.setText(getItem(position).gettime());
holder.tv_productname.setText(getItem(position).getproductsName());
float rating=Float.valueOf(getItem(position).getrating());
holder.rb_productrating.setRating(rating);
return convertView;
}
private RatingBar.OnRatingBarChangeListener onRatingChangedListener(final ViewHolder holder, final int position)
{
return new RatingBar.OnRatingBarChangeListener() {
#Override
public void onRatingChanged(RatingBar ratingBar, float rating, boolean b)
{
FeedbackRowDetails item = row.get(position);
int roundoff_rating = (int)Math.round(rating);
ratingBar.setRating(roundoff_rating);
item.setrating(String.valueOf(roundoff_rating));
}
};
}
#Override
public int getCount() {
return row.size();
}
#Override
public FeedbackRowDetails getItem(int position)
{
return row.get(position);
}
#Override
public long getItemId(int position) {
return row.indexOf(getItem(position));
}
}
I have a Navigation Drawer, With a ListView and with a header. When I scorll the drawer up down the items are mixed, the type of the items. Why?
My DrawerAdapter.java:
public class DrawerAdapter extends BaseAdapter {
private Context context;
private List<DrawerItem> navDrawerItems;
DrawerItemClickListener drawerItemClickListener;
public DrawerAdapter(Context context, ArrayList<DrawerItem> navDrawerItems,DrawerItemClickListener drawerItemClickListener) {
this.context = context;
this.navDrawerItems = navDrawerItems;
this.drawerItemClickListener = drawerItemClickListener;
}
#Override
public int getCount() {
return navDrawerItems.size();
}
#Override
public Object getItem(int position) {
return navDrawerItems.get(position);
}
#Override
public long getItemId(int position) {
return position;
}
#Override
public boolean isEnabled(int position) {
return false;
}
static class ViewHolder {
ImageView imvIcon;
TextView textView;
LinearLayout layout;
}
#Override
public int getViewTypeCount() {
return 2;
}
#Override
public int getItemViewType(int position) {
return super.getItemViewType(position);
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
final DrawerItem mItem = navDrawerItems.get(position);
if(mItem.getType().equals(DrawerItem.TYPE_CLICKABLE))
{
if (convertView == null)
{
holder = new ViewHolder();
LayoutInflater inflater = (LayoutInflater) parent.getContext().getSystemService(
Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.drawer_list_item, parent, false);
holder.imvIcon = (ImageView) convertView.findViewById(R.id.item_icon);
holder.textView = (TextView) convertView.findViewById(R.id.item_text);
holder.layout = (LinearLayout) convertView.findViewById(R.id.drawer_one_layout);
convertView.setTag(holder);
}
else {
holder = (ViewHolder) convertView.getTag();
}
if(holder.imvIcon != null)
Picasso.with(parent.getContext()).load(mItem.getIcon()).into(holder.imvIcon);
if(holder.textView != null)
holder.textView.setText(mItem.getTitle());
if(holder.layout != null)
holder.layout.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
drawerItemClickListener.DrawerItemClicked(mItem);
}
});
}
else
{
if (convertView == null)
{
holder = new ViewHolder();
LayoutInflater inflater = (LayoutInflater) parent.getContext().getSystemService(
Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.drawer_list_item_two, parent, false);
holder.textView = (TextView) convertView.findViewById(R.id.item_text);
convertView.setTag(holder);
}
else {
holder = (ViewHolder) convertView.getTag();
}
holder.textView.setText(mItem.getTitle());
}
return convertView;
}}
And the Drawer Item :
public class DrawerItem {
public final static String TYPE_CLICKABLE = "clikc";
public final static String TYPE_HEADER = "header";
private String title, type;
private int icon;
public DrawerItem(String title, int icon, String type) {
this.title = title;
this.icon = icon;
this.type = type;
}
public String getTitle() {
return title;
}
public int getIcon() {
return icon;
}
public String getType() {return this.type;}}
Please help me. Thanks.
You are not clearly stating which item type your current view is, so the adapter doesn't know the viewtype and doesn't display correctly the items (e.g. it mixes them).
In your getItemViewType() you should be clear about the viewtype of the current item, and do something like this:
#Override
public int getItemViewType(int position) {
if(navDrawerItems.get(position).getType().equals(DrawerItem.TYPE_CLICKABLE))
return 0;
return 1;
}
Hi i am using checkbox in listview, but the checkbox get auto unchecked or checked when i scroll my list view.
public class MyContactsAdapter extends BaseAdapter {
private LayoutInflater inflater;
private List<Friend> mAllFriends;
public MyContactsAdapter(Context context,List<Friend> allFriends) {
inflater = LayoutInflater.from(context);
this.mAllFriends =allFriends;
}
#Override
public int getCount() {
if(mAllFriends==null)
{
return 0;
}else{
return mAllFriends.size();
}
}
#Override
public Object getItem(int position) {
return mAllFriends.get(position);
}
#Override
public long getItemId(int position) {
return position;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder mHolder;
if (convertView == null) {
convertView = inflater.inflate(R.layout.contact_list_item, null);
mHolder = new ViewHolder();
mHolder.mProFileImage = (ImageView) convertView
.findViewById(R.id.profleImage);
mHolder.mPersonName = (TextView) convertView
.findViewById(R.id.person_Name);
mHolder.mEmailId = (TextView) convertView
.findViewById(R.id.person_emailId);
mHolder.mSelectPerson = (CheckBox)convertView.findViewById(R.id.personSelect);
mHolder.mSelectAllLabel = (TextView)convertView.findViewById(R.id.personSelectAllLabel);
convertView.setTag(mHolder);
} else {
mHolder = (ViewHolder) convertView.getTag();
}
if(position==0)
{
mHolder.mProFileImage.setVisibility(View.GONE);
mHolder.mPersonName.setVisibility(View.GONE);
mHolder.mEmailId.setVisibility(View.GONE);
mHolder.mSelectAllLabel.setVisibility(View.VISIBLE);
}else{
mHolder.mProFileImage.setVisibility(View.VISIBLE);
mHolder.mPersonName.setVisibility(View.VISIBLE);
mHolder.mEmailId.setVisibility(View.VISIBLE);
mHolder.mSelectAllLabel.setVisibility(View.GONE);
}
mHolder.mProFileImage.setImageResource(R.drawable.ic_launcher);
mHolder.mPersonName.setText(""+mAllFriends.get(position).getName());
mHolder.mEmailId.setText(""+mAllFriends.get(position).getEmail());
mHolder.mSelectPerson.setTag(position);
mHolder.mSelectPerson.setChecked(mAllFriends.get(position).isSelected());
mHolder.mSelectPerson.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
#Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
mAllFriends.get((Integer) buttonView.getTag()).setSelected(isChecked);
}
});
return convertView;
}
private static class ViewHolder {
ImageView mProFileImage;
TextView mPersonName;
TextView mEmailId;
CheckBox mSelectPerson;
TextView mSelectAllLabel;
}
}