Android convertView - android

i have used horizontal listview like this with Baseadapter.
private class ListViewItemClickListener implements
AdapterView.OnItemClickListener {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {
if (imageview != null) {
previousImage = (ImageView) imageview
.findViewById(R.id.imageView);
previousImage.setSelected(false);
TextView previousTitle = (TextView) textview
.findViewById(R.id.title);
previousTitle.setTextColor(Color.parseColor("#33D6AD"));
previousTitle.setTextSize(TypedValue.COMPLEX_UNIT_SP, 13);
}
selected_image = (ImageView) view.findViewById(R.id.imageView);
selected_image.setSelected(true);
selected_text = (TextView) view.findViewById(R.id.title);
selected_text.setTextColor(Color.parseColor("#368AFF"));
selected_text.setTextSize(TypedValue.COMPLEX_UNIT_SP, 16);
select_position = position;
imageview = selected_image;
textview = selected_text;
}
}
private static String[] dataObjects = new String[] { "그랜드 캐니언",
"그레이트 베리어 리프", "디즈니 월드", "뉴질랜드 남섬", "케이프 타운", "암리차르의 황금사원",
"라스베가스", "시드니", "뉴욕", "타지마할" };
private BaseAdapter mAdapter = new BaseAdapter() {
#Override
public int getCount() {
return dataObjects.length;
}
#Override
public Object getItem(int position) {
return null;
}
#Override
public long getItemId(int position) {
return 0;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
convertView = LayoutInflater.from(parent.getContext()).inflate(
R.layout.listitem, null);
}
TextView title = (TextView) convertView.findViewById(R.id.title);
title.setText(dataObjects[position]);
return convertView;
}
};
and i want to change textcolor if one item is clicked. but whenever i click one item in the listview, two item's color are changing right now. and distance between those two item is always 5. I am using convertView on the getView code. and textcolor change code is in clicklistener method. can i solve this with setTag, getTag. and if it is, how can i solve this?

Put this code in your adapter class :
private int selectedPos = -1;
public void setSelectedPosition(int pos){
selectedPos = pos;
notifyDataSetChanged();
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
convertView = LayoutInflater.from(parent.getContext()).inflate(
R.layout.listitem, null);
}
TextView title = (TextView) convertView.findViewById(R.id.title);
title.setText(dataObjects[position]);
if (selectedPos == position) {
title.setTextColor(Color.parseColor("#368AFF"));
title.setTextSize(TypedValue.COMPLEX_UNIT_SP, 16);
} else {
title.setTextColor(Color.parseColor("#000000"));
}
return convertView;
}
And on item click, call method to set current position:
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {
adapter.setSelectedPosition(pos);
}

Try out as below:
private class ListViewItemClickListener implements
AdapterView.OnItemClickListener {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {
mPager.setCurrentItem(position);
selected_image = (ImageView) view.findViewById(R.id.imageView);
selected_image.setSelected(true);
selected_text = (TextView) view.findViewById(R.id.title);
selected_text.setTextColor(Color.parseColor("#368AFF"));
selected_text.setTextSize(TypedValue.COMPLEX_UNIT_SP, 16);
select_position = position;
imageview = selected_image;
textview = selected_text;
view.setTag((Integer) position);
}
}

Try this
convertView.setOnClickListener
instead of
onItemClick

Related

how to add listener to a spinner inside listview adapter in android

public class XpressGoldLoanAdapter extends ArrayAdapter<TransactionDetailsUserData> {
private List<TransactionDetailsUserData>list;
private Context context;
String securityNo;
public XpressGoldLoanAdapter( List<TransactionDetailsUserData> list, Context ctx) {
super(ctx, R.layout.reminderinflater, list);
this.list = list;
this.context = ctx;
}
#Override
public int getCount() {
return list.size();
}
#Override
public TransactionDetailsUserData getItem(int position) {
return list.get(position);
}
#Override
public long getItemId(int position) {
return list.indexOf(getItem(position));
}
private class ViewHolder{
TextView tv_securityNo;
Spinner spin_securityType,spin_security,spin_purityconfirmed ;
LinearLayout sublayout;
EditText ed_numbers,ed_grossWeight,ed_netWeight,ed_rate_perGram,ed_branchMarginRate,ed_amount;
Button btn_savesecurity;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = convertView;
Spinner spin_securityType,spin_security,spin_purityconfirmed;
TextView tv_securityNo;
EditText ed_numbers,ed_grossWeight,ed_netWeight,ed_rate_perGram,ed_branchMarginRate,ed_amount;
LinearLayout sublayout;
Button btn_savesecurity;
ViewHolder holder = new ViewHolder();
if (convertView == null) {
LayoutInflater inflater =(LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = inflater.inflate(R.layout.expressloanitem,null);
spin_securityType =(Spinner) view.findViewById(R.id.spin_securityType);
spin_security =(Spinner) view.findViewById(R.id.spin_security);
spin_purityconfirmed =(Spinner) view.findViewById(R.id.spin_purityconfirmed);
tv_securityNo =(TextView)view.findViewById(R.id.tv_securityNo);
ed_numbers =(EditText)view.findViewById(R.id.ed_numbers);
ed_grossWeight =(EditText)view.findViewById(R.id.ed_grossWeight);
ed_netWeight =(EditText)view.findViewById(R.id.ed_netWeight);
ed_rate_perGram =(EditText)view.findViewById(R.id.ed_rate_perGram);
ed_branchMarginRate =(EditText)view.findViewById(R.id.ed_branchMarginRate);
ed_amount =(EditText)view.findViewById(R.id.ed_amount);
sublayout =(LinearLayout)view.findViewById(R.id.sublayout);
btn_savesecurity =(Button) view.findViewById(R.id.btn_savesecurity);
holder.spin_securityType = spin_securityType;
holder.spin_security = spin_security;
holder.spin_purityconfirmed = spin_purityconfirmed;
holder.tv_securityNo = tv_securityNo;
holder.ed_numbers = ed_numbers;
holder.ed_grossWeight = ed_grossWeight;
holder.ed_netWeight = ed_netWeight;
holder.ed_rate_perGram = ed_rate_perGram;
holder.ed_branchMarginRate = ed_branchMarginRate;
holder.ed_amount = ed_amount;
holder.sublayout = sublayout;
holder.btn_savesecurity = btn_savesecurity;
view.setTag(holder);
}
else{
holder =(ViewHolder) view.getTag();
}
TransactionDetailsUserData pojo = enqList.get(position);
securityNo = pojo.getSecurityCount();
Log.d("securityNo",securityNo);
holder.tv_securityNo.setText(securityNo);
SpinnerLogoAdapter spinnerAdapter3=new SpinnerLogoAdapter(XpressGoldLoan.this.getApplicationContext(),securityTpeIcons,securityTpeitems);
holder.spin_securityType.setAdapter(spinnerAdapter3);
SpinnerLogoAdapter spinnerAdapter4=new SpinnerLogoAdapter(XpressGoldLoan.this.getApplicationContext(),securityIcons,securityitems);
holder.spin_security.setAdapter(spinnerAdapter4);
SpinnerLogoAdapter spinnerAdapter5=new SpinnerLogoAdapter(XpressGoldLoan.this.getApplicationContext(),purityIcons,purityitems);
holder.spin_purityconfirmed.setAdapter(spinnerAdapter5);
//spinner security type
holder.spin_securityType.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
#Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
}
#Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
//save security
holder.btn_savesecurity.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
}
});
return view;
}
}
This is my adpater of listview.when itry to add spinner.getSelectedItem() inside the listener its showing some errors.App crashes inside onItemSelected of spinner .please find a solution.I just only need to get the selected item from spinner.I dont have much to elaborate my question since it is simple to understand.Please help
Change your holder to be final (as the error tells you to)
final ViewHolder holder;
if (convertView == null) {
holder = new ViewHolder()
... //the rest of code here stays the same
} else {
holder =(ViewHolder) view.getTag();
}
add this line in onItemselectedListener
holder.spin_securityType.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
#Override
public void onItemSelected(final AdapterView<?> parent,final View view,final int position,final long id) {
getSelectedItem(parent, view, position, id);
}
#Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
Write one more method in XpressGoldLoanAdapter class which does task for you.
final void getSelectedItem(AdapterView<?> parent, View view, int position, long id) {
String selectedItem = holder.spin_securityType.getSelectedItem().toString();
// do your task here
}
i solved it trying this code since securityTpeitems[] is a string array and i have taken position from the spinner.
String selectedSecType = securityTpeitems[position].toString();

ListView setOnItemClicklistener NullPointerException

public class CustomAdapter extends ArrayAdapter<Plan> implements View.OnClickListener {
private ArrayList<Plan> planArrayList;
int position;
Context context;
private static class ViewHolder{
TextView workType;
TextView zone;
TextView division;
TextView station;
TextView Msg;
}
public CustomAdapter(ArrayList<Plan> plan,Context context){
super(context,R.layout.plan_list,plan);
this.planArrayList=plan;
this.context=context;
}
#Override
public void onClick(View v) {
}
private int lastPosition = -1;
#NonNull
#Override
public View getView(int position, #Nullable View convertView, #NonNull ViewGroup parent) {
Plan plans = getItem(position);
ViewHolder viewHolder;
final View result;
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
if (convertView == null){
viewHolder = new ViewHolder();
//LayoutInflater inflater = LayoutInflater.from(getContext());
convertView = inflater.inflate(R.layout.plan_list,parent,false);
viewHolder.workType = (TextView) convertView.findViewById(R.id.plan_worktype);
viewHolder.zone = (TextView) convertView.findViewById(R.id.plan_zone);
viewHolder.division = (TextView) convertView.findViewById(R.id.plan_division);
viewHolder.station = (TextView) convertView.findViewById(R.id.plan_station);
viewHolder.Msg = (TextView) convertView.findViewById(R.id.)
result=convertView;
convertView.setTag(viewHolder);
}else {
viewHolder = (ViewHolder) convertView.getTag();
result = convertView;
}
Animation animation = AnimationUtils.loadAnimation(context, (position > lastPosition) ? R.anim.up_from_bottom : R.anim.down_from_top);
result.startAnimation(animation);
Plan plan = planArrayList.get(position);
lastPosition = position;
viewHolder.workType.setText(plans.getWorkType());
viewHolder.zone.setText(plans.getZone());
viewHolder.division.setText(plans.getDiv());
viewHolder.station.setText(plans.getSTA());
viewHolder.workType.setText(plan.getWorkType());
viewHolder.zone.setText(plan.getZone());
viewHolder.division.setText(plan.getDiv());
viewHolder.station.setText(plan.getSTA());
if (this.position == position){
View view2 = inflater.inflate(R.layout.list_dialog,null);
TextView worktype= (TextView) view2.findViewById(R.id.dlg_worktype);
TextView zone = (TextView) view2.findViewById(R.id.dlg_zone);
TextView div = (TextView) view2.findViewById(R.id.dlg_division);
TextView sta = (TextView) view2.findViewById(R.id.dlg_station);
TextView msg = (TextView) view2.findViewById(R.id.dlg_msg);
worktype.setText(plan.getWorkType());
zone.setText(plan.getZone());
div.setText(plan.getDiv());
sta.setText(plan.getSTA());
msg.setText(plan.getMsg());
return view2;
}
return convertView;
}
public void selectedItem(int position){
this.position=position;
}
}
When I called setOnItemClickListener on listView item those item values need to display in dialog box.
By the above code I'm getting java.lang.NullPointerException: Attempt to read from field 'android.widget.TextView com.example.nsurekha.entry_ex.CustomAdapter$ViewHolder.workType' on a null object reference
If you want to use onClick on listView
list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
// TODO Auto-generated method stub
String title=adapter.getItem(arg2).getTitle();
String description=adapter.getItem(arg2).getDescription();
String addedby=adapter.getItem(arg2).getAddedby();
}
});
Now you can easily show dialogbox with the desired data. Hope it works for you.

ArrayAdapter getView doesn't return first item

In getView method when the view type is vTypeItem it should return all the item from my array list but it returns all except the first one,and because of this the ListView displays all item except the first one
public class DrawerAdapter extends ArrayAdapter<DrawerCustomList> {
private static final int vTypeHeader = 0;
private static final int vTypeItem = 1;
ArrayList<DrawerCustomList> mList = new ArrayList<>();
public DrawerAdapter(Context context, ArrayList<DrawerCustomList> list) {
super(context,0,list);
mList = list;
}
#Override
public int getItemViewType(int position) {
return (position==0)?vTypeHeader:vTypeItem;
}
#Override
public int getViewTypeCount() {
return 2;
}
#Override
public int getCount() {
return mList.size();
}
#NonNull
#Override
public View getView(int position, View convertView, ViewGroup parent) {
int type = getItemViewType(position);
View v = convertView;
MyViewHolder mViewHolder = null;
if (v==null){
if(type==vTypeItem){
v = LayoutInflater.from(getContext()).inflate(R.layout.drawer_single_item,parent,false);
mViewHolder= new MyViewHolder(v,type);
DrawerCustomList val = mList.get(position);
mViewHolder.itemImage.setImageResource(val.getmListImage());
mViewHolder.itemName.setText(val.getmListName());
}else {
v = LayoutInflater.from(getContext()).inflate(R.layout.drawer_header_layout,parent,false);
mViewHolder= new MyViewHolder(v,type);
}
}
v.setTag(mViewHolder);
return v;
}
public static class MyViewHolder{
TextView itemName,headerName,headerEmail;
CircleImageView headerPicture;
ImageView itemImage;
public MyViewHolder(View v,int type){
if(type==vTypeHeader){
headerName = (TextView)v.findViewById(R.id.drawerHeaderName);
headerEmail = (TextView)v.findViewById(R.id.drawerHeaderEmail);
headerPicture = (CircleImageView)v.findViewById(R.id.drawerCircleImageView);
}else {
itemName = (TextView) v.findViewById(R.id.drawerItemName);
itemImage = (ImageView)v.findViewById(R.id.drawerItemImage);
}
}
}
}
Seems like you're not accounting for the header view in the getCount() method.
First change the latter to:
#Override
public int getCount() {
return mList.size() + 1; // accounting for the header
}
Now keep in mind that in the current version of your getView() method, if position == 0 you'll display the header, which is correct. If position == 1 though, you'll do
....
if(type==vTypeItem){
v = LayoutInflater.from(getContext()).inflate(R.layout.drawer_single_item,parent,false);
mViewHolder= new MyViewHolder(v,type);
DrawerCustomList val = mList.get(position);
Notice how mList.get(position) will actually get the second item in the list (with index 1), instead of the first one, which is what you need. So change this line to ...mList.get(position - 1) and your problem should be solved.
I changed your code as below, seems to be working fine. Here I have added drawer_single_item layout's drawerItemName,drawerItemImage control in drawer_header_layout.
Do the following changes in getView method.
#NonNull
#Override
public View getView(int position, View convertView, ViewGroup parent) {
int type = getItemViewType(position);
View v = convertView;
MyViewHolder mViewHolder = null;
if(type==vTypeItem){
v = LayoutInflater.from(getContext()).inflate(R.layout.drawer_single_item,parent,false);
mViewHolder= new MyViewHolder(v,type);
DrawerCustomList val = mList.get(position);
mViewHolder.itemImage.setImageResource(val.getmListImage());
mViewHolder.itemName.setText(val.getmListName());
}else {
v = LayoutInflater.from(getContext()).inflate(R.layout.drawer_header_layout,parent,false);
mViewHolder= new MyViewHolder(v,type);
DrawerCustomList val = mList.get(position);
mViewHolder.itemImage.setImageResource(val.getmListImage());
mViewHolder.itemName.setText(val.getmListName());
}
v.setTag(mViewHolder);
return v;
}
Change your MyViewHolder to this:
public static class MyViewHolder{
TextView itemName,headerName,headerEmail;
CircleImageView headerPicture;
ImageView itemImage;
public MyViewHolder(View v,int type){
if(type==vTypeHeader){
headerName = (TextView)v.findViewById(R.id.drawerHeaderName);
headerEmail = (TextView)v.findViewById(R.id.drawerHeaderEmail);
headerPicture = (CircleImageView)v.findViewById(R.id.drawerCircleImageView);
itemName = (TextView) v.findViewById(R.id.drawerItemName);
itemImage = (ImageView)v.findViewById(R.id.drawerItemImage);
}else {
itemName = (TextView) v.findViewById(R.id.drawerItemName);
itemImage = (ImageView)v.findViewById(R.id.drawerItemImage);
}
}
}
Hope this helps.

Dynamically change custom list item background

I am creating a custom list view with favorite functionality, but I don't know how to change favorite image background on click. When I simply change the background of favorite icon than it automatically change background of another favorite image background at the time of scrolling. Please check below code :
public class CustomArrayAdapter extends BaseAdapter {
private Activity activity;
private LayoutInflater inflater = null;
ArrayList<Customlist> list;
DecimalFormat formatter = new DecimalFormat("#,##,###");
public CustomArrayAdapter(Activity a, ArrayList<Customlist> list) {
activity = a;
inflater = (LayoutInflater) activity
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
this.list = list;
}
public int getCount() {
return list.size();
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
#Override
public View getView(final int position, View convertView,
final ViewGroup parent) {
TextView txt_unit, txt_state, txt_price, term_left, customr;
TextView install_date;
final ImageView fav;
View view = convertView;
if (convertView == null)
view = inflater.inflate(R.layout.list_item, null);
customr = (TextView) view.findViewById(R.id.customr);
txt_state = (TextView) view.findViewById(R.id.txt_state);
install_date = (TextView) view.findViewById(R.id.install_date);
term_left = (TextView) view.findViewById(R.id.term_left);
txt_price = (TextView) view.findViewById(R.id.txt_price);
fav = (ImageView) view.findViewById(R.id.fav);
txt_unit = (TextView) view.findViewById(R.id.txt_unit);
fav.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
// fav = (ImageView)v.findViewById(R)
fav.setBackgroundResource(R.drawable.favourite_select);
Toast.makeText(activity, "click", 1).show();
}
});
// set values
customr.setText(list.get(position).getCUSTOMER());
txt_state.setText(list.get(position).getSTATE_NAME());
install_date.setText(list.get(position).getINSTALL_DATE());
term_left.setText(list.get(position).getTREM_LEFT());
String price = formatter.format(Integer.parseInt(list.get(position)
.getRUPEES()));
return view;
}
}
First, you need to implement the adapter on ViewHolder pattern:
#Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
ViewHoldler holder = null;
if (convertView == null) {
convertView = LayoutInflater.from(ctx).inflate(
R.layout.frag_home_gridview_item, null, false);
holder = new ViewHoldler();
holder.iv = (ImageView) convertView
.findViewById(R.id.gridview_item_label);
holder.tv = (TextView) convertView
.findViewById(R.id.gridview_item_name);
convertView.setTag(holder);
} else {
holder = (ViewHoldler) convertView.getTag();
}
holder.tv.setText(getItem(position));
holder.iv.setImageResource(this.ids[position]);
return convertView;
}
private class ViewHoldler {
ImageView iv;
TextView tv;
}
Second, use partial refreshment mechanism to change the target View's background:
private void refreshPartially(int position){
int firstVisiblePosition = listview.getFirstVisiblePosition();
int lastVisiblePosition = listview.getLastVisiblePosition();
if(position>=firstVisiblePosition && position<=lastVisiblePosition){
View view = listview.getChildAt(position - firstVisiblePosition);
if(view.getTag() instanceof ViewHolder){
ViewHolder vh = (ViewHolder)view.getTag();
//holder.play.setBackgroundResource(resId);//Do something here.
...
}
}
}
Third, add AdapterView.OnItemClickListener to your ListView:
mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
refreshPartially(position);
}
});
You need to implement the adapter on ViewHolder pattern:
http://www.vogella.com/tutorials/AndroidListView/article.html

Custom ListView onClick change Image, notifyDataSetInvalidated not working after restart activity

I'm creating a listview that contains an image and text. notifyDataSetInvalidated() works when I started the activity for the 1st time, the image did change after onclick. However, when I restart the activity, the notifyDataSetInvalidated() is not working and the image doesn't change. These are the codes that I wrote.
listview.activity
#Override
public void onLayoutInflated(WatchViewStub stub) {
listView = (ListView)stub.findViewById(R.id.setting_item_listview);
launcherSwitch = (Switch) stub.findViewById(R.id.Launcher_switch);
adapter = new CustomListItem(WOMSettingActivity.this,
WOMSettingActivity.this.getResources().getStringArray(R.array.setting_item),imageId,app);
listView.setAdapter(adapter);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
ImageView imageView = (ImageView)view.findViewById(R.id.img);
imageView.setImageResource(R.drawable.icon_black);
for(int i = 0; i < imageId.length;i++){
if(position == i){
checkState[i] = true;
}else{
checkState[i] = false;
}
}
adapter.notifyDataSetInvalidated();
}
});
}
CustomListItem
#Override
public View getView(final int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = context.getLayoutInflater();
final ViewHolder holder;
if(convertView==null){
convertView = inflater.inflate(R.layout.settingtextlayout,null);
holder = new ViewHolder();
holder.txtTitle = (TextView) convertView.findViewById(R.id.listview_item_text);
holder.imageView = (ImageView) convertView.findViewById(R.id.img);
convertView.setTag(holder);
}else{
holder = (ViewHolder)convertView.getTag();
}
holder.txtTitle.setText(launcherPosition[position]);
if(checkstate[position]){
holder.imageView.setImageResource(R.drawable.icon_black);
}else{
holder.imageView.setImageResource(R.drawable.ic_launcher);
}
return convertView;
}
Please show me where did I did wrongly.
thank you
Try calling
notifyDataSetChanged(); //Notifies the attached observers that the underlying data has been changed and any View reflecting the data set should refresh itself.
instead of
notifyDataSetInvalidated(); //Notifies the attached observers that the underlying data is no longer valid or available.
Refer : http://developer.android.com/reference/android/widget/BaseAdapter.html
Created another class and did some correction.
listview.activity
public void onLayoutInflated(WatchViewStub stub) {
listView = (ListView)stub.findViewById(R.id.setting_item_listview);
launcherSwitch = (Switch) stub.findViewById(R.id.Launcher_switch);
adapter = new CustomListItem(WOMSettingActivity.this,list,app);
Log.d(TAG,"adapter : " + adapter.getCount());
listView.setAdapter(adapter);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
for(int i = 0;i<adapter.getCount();i++){
if(position == i){
adapter.getItem(position).setChecked(true);
}else{
adapter.getItem(position).setChecked(false);
}
}
adapter.notifyDataSetChanged();
}
});
}
class
public class setting(){
private String Position;
private boolean checked;
public setting(String Position, boolean checked){
this.Position = Position;
this.checked = checked;
}
// Getter and setter
}
list class extend setting
#Override
public View getView(final int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = context.getLayoutInflater();
final ViewHolder holder;
if(convertView==null){
convertView = inflater.inflate(R.layout.settingtextlayout,null);
holder = new ViewHolder();
holder.txtTitle = (TextView) convertView.findViewById(R.id.listview_item_text);
holder.imageView = (ImageView) convertView.findViewById(R.id.img);
convertView.setTag(holder);
}else{
holder = (ViewHolder)convertView.getTag();
}
holder.txtTitle.setText(getItem(position).getPosition());
if(getItem(position).isChecked()){
holder.imageView.setImageResource(R.drawable.icon_red);
}else{
holder.imageView.setImageResource(R.drawable.icon_black);
}
return convertView;
}
notifyDataSetChanged() is working fine now.

Categories

Resources