In my android applicattion i have a list view with custom adapter.The adapter has a textview and two buttons(plus & minus button) like in the image below :
when i click on the plus or minus button the textview value changes...but as soon as i scroll the listview the values are changed of all the textviews.
The code i used is as follows :
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
if(convertView==null)
{
viewHolder=new ViewHolder();//
convertView = inflater.inflate(R.layout.inventory_list_item, null);
viewHolder.txt_product_name = (TextView)convertView.findViewById(R.id.txt_product_name);
viewHolder.txt_product_units = (TextView)convertView.findViewById(R.id.txt_product_units);
viewHolder.txt_price = (TextView) convertView.findViewById(R.id.txt_price);
viewHolder.txt_qty = (TextView) convertView.findViewById(R.id.txt_qty);
viewHolder.btn_minus = (Button)convertView.findViewById(R.id.btn_minus);
viewHolder.btn_plus= (Button)convertView.findViewById(R.id.btn_plus);
convertView.setTag(viewHolder);
}
else
{
viewHolder = (ViewHolder) convertView.getTag();
}
viewHolder.btn_minus.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
LinearLayout ll = (LinearLayout) v.getParent();
TextView tv = (TextView) ll.getChildAt(1);
int qty = Integer.parseInt(tv.getText().toString());
if(qty == 0)
{
}
else
{
qty = qty - 1;
tv.setText(String.valueOf(qty));
}
}
});
viewHolder.btn_plus.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
LinearLayout ll = (LinearLayout) v.getParent();
TextView tv = (TextView) ll.getChildAt(1);
int qty = Integer.parseInt(tv.getText().toString());
qty = qty + 1;
tv.setText(String.valueOf(qty));
}
});
HashMap<String, String> map = new HashMap<String, String>();
map = data.get(position);
viewHolder.txt_product_name.setText(map.get("ProductName"));
viewHolder.txt_price.setText(map.get("ProductPrice"));
viewHolder.txt_product_units.setText(map.get("ProductUnits"));
return convertView;
}
How do i address this issue?
Please help ! thanks in advance !
Try defining TextView tv inside viewHolder instead of inside click listener
ViewHolder{
TextView tv;
}
Do something like you have done for txt_product_name TextView
You need to use a model class for that . Create getter setter for each element in your list view Whether is String int or status of open and close .And Pass it to constructor of your adapter class .If you already have a model class then add these parameters to it . And change the property of text change on button click And call notifyDataSetChanged() after it . then you just need if-else in your getView() to change the text .Try it and let me know if you still face some problem.
I have created demo according your scenario ,what i did inside onClick i have updated my data and called notifyDataSetChanged();
whatever you did is very long and heavy process;make it simple .just update your data and called notifyDataSetChanged();if you need sample i can provide you my sample
don't update manually the field of textview .always update the data and get updated data and set to textview
Firstly you can't update the plus(+) and minus(-) values in your listview directly as your tried. Because your not handling any position in your code. So it seams if you change one item count (plus or minus) it will effect on the other items as well (or) else it will lose the data after scrolling..
So to achieve your task, you need to follow these steps.
Firstly you need to create a data structure, which holds the positions of your items and count of your items in the list view. Suppose third item in your list view having 5 count (plus values) we can hold both the position and count as well in this data structure.
So, i am taking a HashMap , where key is String.valueOf(position) and Value is count int. like below
HashMap< String,Integers > countDetails= new HashMap< String,Integers >;
You know the keys since it will be from position "0" to listitem.length. Using the key you can get the count values(probably to hold your item cont details for each and every list item).
Why Hashmap: because everytime you change count the new value will be overriden. (Only one unique key is maintained in hashmap).
Usage:: if the user click's the first item minus (-) or plus (+) button you need to hold that count and need to store in the hashmap with the position and count. for example (position = 0, count = 3) --> - clicked on 1st row--> plus (+) items for 3 times like that.
after clicking plus(+) and (-) values in your list item call the notifyDataChanged() in your list so, that it will update the data in listview.
So, this is the idea how you can achieve your implementation, here i am giving a sample code for it .
class AdapterClass extends ArrayAdapter<String> {
HashMap<String,Integers> countDetails = new HashMap<String,Integers>;
// you can use/ declare all your remaining data product here
public AdapterClass(Context c, String[] items, int imgs[]) {
// TODO Auto-generated constructor stub
super(c, R.layout.rowlayout, R.id.quantity, items);
this.context = c;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
if(convertView==null)
{
viewHolder=new ViewHolder();//
convertView = inflater.inflate(R.layout.inventory_list_item, null);
viewHolder.txt_product_name = (TextView)convertView.findViewById(R.id.txt_product_name);
viewHolder.txt_product_units = (TextView)convertView.findViewById(R.id.txt_product_units);
viewHolder.txt_price = (TextView) convertView.findViewById(R.id.txt_price);
viewHolder.txt_qty = (TextView) convertView.findViewById(R.id.txt_qty);
viewHolder.btn_minus = (Button)convertView.findViewById(R.id.btn_minus);
viewHolder.btn_plus= (Button)convertView.findViewById(R.id.btn_plus);
convertView.setTag(viewHolder);
}
else
{
viewHolder = (ViewHolder) convertView.getTag();
}
HashMap<String, String> map = new HashMap<String, String>();
map = data.get(position);
viewHolder.txt_product_name.setText(map.get("ProductName"));
viewHolder.txt_price.setText(map.get("ProductPrice"));
viewHolder.txt_product_units.setText(map.get("ProductUnits"));
viewHolder.btn_minus.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
int pos=position;
HashMap<String,Integers> tmpDetails = new HashMap<String,Integers>;
tmpDetails=countDetails.get(pos);
int count=tmpDetails.get(pos); // probably your getting the previous count for the item
if(count == 0)
{
}
else
{
count = count - 1;
holder.txt_qty.setText(count.toString());
}
countDetails.put(holder.uniqueKey,count); //Key -> String.valueOf(position) and Value -> int count
}
});
viewHolder.btn_plus.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
int pos=position;
HashMap<String,Integers> tmpDetails = new HashMap<String,Integers>;
tmpDetails=countDetails.get(pos);
int count=tmpDetails.get(pos); // probably your getting the previous count for the item
if(count == 0)
{
}
else
{
count = count + 1;
holder.txt_qty.setText(count.toString());
}
countDetails.put(holder.uniqueKey,count); //Key -> String.valueOf(position) and Value -> int count
}
});
return row;
}
}
p.s. I have typed in editor, there might be some compile time error. Also you can store objects of each row against the key so that when you get the count, you can get any other reference too..
Related
Whatever I searched so far is about getting the list view data by placing the button in each row, But what I want to achieve is to pick the listview content by placing the button outside the list.
I have created an editable listview where user will enter the value and this value will be multiplied by one of the columns already present in the list and the result will be set in another textview.
Now on clicking the button (which is given below the list)I want to perform the following two things.
I want to get only those rows where user has entered the values in the textboxes. and
the values of the editTexts (name and address) which are given above the listview. and saves them to sqlite.
I don't know how to do this, any help would be greatly appreciated. Sorry if I'm not clear.
Below is the code of my listview adapter
#Override
public View getView( final int position, View convertView, ViewGroup parent) {
final ViewHolder holder;
if (convertView == null) {
convertView = inflater.inflate(R.layout.productslistviewadapter, parent, false);
holder = new ViewHolder();
holder.tvdrCode = (TextView) convertView.findViewById(R.id.tvname);
holder.tvDrName = (TextView) convertView.findViewById(R.id.tvprodpack);
holder.tvterrcode= (TextView) convertView.findViewById(R.id.textView3);
holder.caption = (EditText)convertView.findViewById(R.id.editText1);
holder.tvValue = (TextView) convertView.findViewById(R.id.value);
holder.tvValue.setVisibility(View.GONE);
convertView.setTag(holder);
}
else {
holder = (ViewHolder) convertView.getTag();
}
Products p = prodList.get(position);
holder.tvdrCode.setText(p.getDocCode());
holder.tvDrName.setText(p.getDocName());
holder.tvterrcode.setText(p.getAdr());
//for editText
holder.caption.setTag(position);
holder.caption.setText(p.getCaption());
int tag_position=(Integer) holder.caption.getTag();
holder.caption.setId(tag_position);
holder.caption.setOnFocusChangeListener(new View.OnFocusChangeListener() {
public void onFocusChange(View v, boolean hasFocus) {
if (!hasFocus) {
/*
* When focus is lost save the entered value for
* later use
*/
int position2;
position2 = holder.caption.getId();
position2 = holder.tvValue.getId();
final EditText Caption = (EditText) holder.caption;
final TextView TvValue = (TextView) holder.tvValue;
if(Caption.getText().toString().length()>0)
{
prodList.get(position2).setCaption(Caption.getText().toString());
String prodpack = prodList.get(position).getDocName().toString();
String prodname = prodList.get(position).getDocCode().toString();
String quantity = prodList.get(position2).getCaption()
int value = Integer.parseInt(prodpack) * Integer.parseInt(quantity);
holder.tvValue.setText(Integer.toString(value));
holder.tvValue.setVisibility(View.VISIBLE);
}
else{
Log.e("enter some value", "yes");
}
}
}
});
Try the below code snippet on the button click
for (int i = 0; i < listView.getAdapter().getCount(); i++) {
Products pold = (Products) listView.getAdapter().getItem(i);
Products pnew = prodlist.get(i);
if(pold.getCaption() !=null)
{
if(pold.getCaption() != pnew.getCaption().toString())
{
//Call sqlite save here
Log.d("yes", "yes");
}
else {
Log.d("no", "no");
}
}
Hope this helps
For listview ...as it has edit text..set on text change listener on edit text...and keep a hasmap to store the pos of these records...along with value entered , so as and when user starts typing...put check if editext is empty or unchanged ...then don't add it to list.
As when user press save ...get name and address value...also u get values from hashmap. I hope clear enough to explain you.
Here I am working on a application where I have to use GridView to display some images according to customers requirement.
In that GridView I am displaying 2 rows and 2 columns at a time, So that 4 images can be visible at a time. Now user want to do some changes and want me create a EditText in which he can enter the number and according to that number, GridView should change its column and rows .
Is it possible as I have gone through many online examples and what all I got is change the GridView at run time but with the fixed predefined number of rows and columns. But I didn't find any example like change the GridView from EditText at run time.
and type of help will be appreciable.
As I mentioned in the comment you can use custom baseadapter for your gridview and take the number of images as an argument in the constructor of the adapter class. Below is the code snippet that you can use to achieve this.
Custom BaseAdapter
public class Adapter extends BaseAdapter {
private final Context context;
private final LayoutInflater inflater;
private final int numbers;
public Adapter(Context context, int numberOfImages) {
this.context = context;
this.numbers = numberOfImages;
this.inflater = (LayoutInflater) this.context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
#Override
public int getCount() {
//You need to return the numberOfImages here for
//the adapter to determine how many view you need to create.
return numbers;
}
private class viewHolder {
ImageView image;
TextView image_desc;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
viewHolder holder;
if (convertView == null) {
convertView = inflater.inflate(R.layout.grid_item, null);
holder = new viewHolder();
holder.image = (ImageView) convertView.findViewById(R.id.image);
holder.image_desc = (TextView) convertView
.findViewById(R.id.img_desc);
convertView.setTag(holder);
}
holder = (viewHolder) convertView.getTag();
if (position % 2 == 0) {
holder.image.setImageResource(R.drawable.ic_action_add_person);
holder.image_desc.setText("change");
}
return convertView;
}
#Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return null;
}
#Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return 0;
}
}
Your main activity: In this activity you need to ask the user to enter the number of images they want to see. I have not added any kind of validation or error message when user does not enter a value but instead I have catched the possible error and used it to assign default value. You can apply other kind of logics here according to your requirement.
public class MainActivity extends Activity implements OnClickListener {
EditText text;
Button button;
int number;
private static final String NUMBER_OF_IMAGES = "numbers";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
text = (EditText) findViewById(R.id.text);
button = (Button) findViewById(R.id.button);
button.setOnClickListener(this);
}
#Override
public void onClick(View v) {
try {
number = Integer.parseInt(text.getText().toString());
// if user enters 0 or negative number then the default value is set
// to 2
if (number < 1) {
number = 2;
}
} catch (Exception e) {
e.printStackTrace();
// if user doesn't enter anything then code will catch
// classCastException and assign 2 as default value here
number = 2;
}
// start this intent by putting this number in the bundle
Intent i = new Intent(getApplicationContext(), SecondActivity.class);
Bundle bundle = new Bundle();
bundle.putInt(NUMBER_OF_IMAGES, number);
i.putExtras(bundle);
startActivity(i);
}
}
Second Activity: this is the activity where you define and initialise your gridview and adapter. make sure you retrieve the bundle from previous activity and retrieve the number entered by user properly.
public class SecondActivity extends Activity {
GridView grid;
Adapter adapter;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.grids);
Bundle bundle = getIntent().getExtras();
int numbers = bundle.getInt(MainActivity.NUMBER_OF_IMAGES);
grid = (GridView) findViewById(R.id.gridview);
// depending upon your requirement you can also add logic here to set
// the number of columns based on the number entered by the user
setColumns(numbers);
adapter = new Adapter(getApplicationContext(), numbers);
grid.setAdapter(adapter);
}
#Override
protected void onResume() {
super.onResume();
adapter.notifyDataSetChanged();
}
/**
* Method to set the number of columns depending upon user input for desired
* grids. other attributes for the grid view can also be set her such as
* width, height, background etc.
*
* #param number
*/
public void setColumns(int number) {
if (number > 0 && number < 10) {
grid.setNumColumns(2);
} else if (number >= 10 && number < 20) {
grid.setNumColumns(4);
} else {
grid.setNumColumns(5);
}
}
}
NOTE: This is not highly optimised code for performance but just provides an example of how the required functionality can be achieved.
Based on number of rows and columns entered by ueser you can calculate number of items to show, pass that much no of item to your adapter and for setting column number You can try gridView.setNumColumns(numColumns);. Number of rows will be adjusted accordingly.
I have a listview with number and an image buton with each number. I want to make call on button click to the number in the row. my getview method is
#Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
View rowView = convertView;
ContactStockView sv = null;
if (rowView == null) {
// Get a new instance of the row layout view
LayoutInflater inflater = activity.getLayoutInflater();
rowView = inflater.inflate(
R.layout.activity_row, null);
// Hold the view objects in an object,
// so they don't need to be re-fetched
sv = new ContactStockView();
sv.name = (TextView) rowView.findViewById(R.id.textacti_row1);
sv.number = (TextView) rowView.findViewById(R.id.textacti_row2);
sv.btncall=(ImageButton)rowView.findViewById(R.id.imgbtn_call);
//sv.btncall.setOnClickListener((OnClickListener) activity);
rowView.setTag(sv);
//ImageButton btn=(ImageButton)convertView.findViewById(R.id.btn_call);
/* */
} else {
sv = (ContactStockView) rowView.getTag();
}
// Transfer the stock data from the data object
// to the view objects
ContactStock currentStock = (ContactStock) stocks.get(position);
sv.name.setText(currentStock.getName());
number=currentStock.getNumber();
sv.number.setText(number);
//ImageButton btn=(ImageButton)rowView.findViewById(R.id.imgbtn_call);
sv.btncall.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
//Toast.makeText( activity, number, Toast.LENGTH_SHORT).show();
String phoneCallUri = "tel:"+number;
Intent phoneCallIntent = new Intent(Intent.ACTION_CALL);
phoneCallIntent.setData(Uri.parse(phoneCallUri));
activity.startActivity(phoneCallIntent);
}
});
/* btn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
//Toast.makeText( activity, "abc", Toast.LENGTH_SHORT).show();
/*}
});*/
// TODO Auto-generated method stub
return rowView;
}
protected static class ContactStockView {
protected TextView name;
protected TextView number;
protected ImageButton btncall;
}
My log cat on call is
you should declare the string number in get view method not outside it. change
number=currentStock.getNumber();
to
final String number=currentStock.getNumber();
and delete the string(ie,number) from outside getview method
You can't findout the problem that way. You have to debug your getView method.
Do that by
1) double click on the first line of the method on the left of the outer frame to see a small point thay represents a breakpoint.
2) Right click on the project and click Debug as Android application.
3) Using the button F6 (in Eclipse) start moving steps untill you find the specific line you code produce error.
4) Now when you know the line it's easier to find out what happened.
attach the number to the view with setTag, then retrieve it in the click listener. you also don't need a new listener every time, define that once outside the function...
sv.btncall.setTag(number);
then in the onclick listener...
new View.OnClickListener() {
#Override
public void onClick(View v) {
String number = (String) v.getTag();
String phoneCallUri = "tel:"+number;
Intent phoneCallIntent = new Intent(Intent.ACTION_CALL);
phoneCallIntent.setData(Uri.parse(phoneCallUri));
activity.startActivity(phoneCallIntent);
}
}
// Adding menuItems to ListView
mylist=(ListView)findViewById(R.id.lstshowcatalogue);
ListAdapter adapter=new LazyAdapter(this, menuItems,getApplicationContext());
mylist.setAdapter(adapter);
mylist.setOnItemClickListener(new OnItemClickListener(){
#Override
public void onItemClick(AdapterView<?> Parent, View view, int position,
long id) {
// TODO Auto-generated method stub
if(position>=0)
{
TextView c = (TextView) view.findViewById(R.id.txtlargeimage);
largeimage = c.getText().toString();
ImageView thumb_image=(ImageView)view.findViewById(R.id.ivcatalouge); // thumb image
thumb_image.setOnClickListener(new OnClickListener(){
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
if(largeimage.length()>0)
{
Intent i=new Intent();
i.setClass(getApplicationContext(), FrmShowSingleImage.class);
i.putExtra("largeimage", largeimage);
startActivity(i);
//Toast.makeText(getApplicationContext(), largeimage, Toast.LENGTH_SHORT).show();
largeimage="";
}
}});
//Toast.makeText(getApplicationContext(), largeimage, Toast.LENGTH_SHORT).show();
}
}});
I want to open a new activity on thumb image onclick. It works fine when First Select item. If I click thumb image without selecting item it getting old value
Here is my updated listview adapter
public View getView(int position, View convertView, ViewGroup parent) {
View vi=convertView;
if(convertView==null)
vi = inflater.inflate(R.layout.list_item, null);
TextView name = (TextView)vi.findViewById(R.id.name); // name
TextView desc = (TextView)vi.findViewById(R.id.desciption); // collection
TextView cost = (TextView)vi.findViewById(R.id.cost); // cost
TextView category = (TextView)vi.findViewById(R.id.txtcategory); // cost
TextView spec = (TextView)vi.findViewById(R.id.txtspec); // cost
TextView largeimg = (TextView)vi.findViewById(R.id.txtlargeimage); // cost
ImageView thumb_image=(ImageView)vi.findViewById(R.id.ivcatalouge); // thumb image
thumb_image.setOnClickListener(new OnClickListener(){
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
TextView c = (TextView) v.findViewById(R.id.txtlargeimage);
Intent i=new Intent();
i.setClass(mCtx, FrmShowSingleImage.class);
i.putExtra("largeimage", c.getText());
mCtx.startActivity(i);
}});
HashMap<String, String> song = new HashMap<String, String>();
song = data.get(position);
// Setting all values in listview
name.setText(song.get(FrmShowCatlogue.KEY_MODEL));
desc.setText(song.get(FrmShowCatlogue.KEY_COLLECTION));
cost.setText(song.get( FrmShowCatlogue.KEY_MRP));
category.setText(song.get( FrmShowCatlogue.KEY_CATEGORY));
spec.setText(song.get( FrmShowCatlogue.KEY_SPEC));
largeimg.setText(song.get( FrmShowCatlogue.KEY_LARGE));
largeimg.setVisibility(View.GONE);
try
{
String filename=song.get(FrmShowCatlogue.KEY_IMAGES.toString());
filename="thumbs/" + filename;
// get input stream
InputStream ims = mCtx.getAssets().open(filename);
// load image as Drawable
Drawable d = Drawable.createFromStream(ims, null);
// set image to ImageView
thumb_image.setImageDrawable(d);
}
catch(IOException ex)
{
//thumb_image.setVisibility(View.GONE);
}
return vi;
}
Now I am getting null pointer exception on thumb click.
I have removed thumb_image onclick from SetOnItemClickListener of listview
If your list item click doent get recognized,it is because your custom list item has many clickable items(imagebutton,button...) in it. make android:focusable=false for those items and your listview click will be allright.
then as JaredLua said you should add the onClickLisener() in the adapter since its for the thumb_image only and not for the listitem as a whole
I think maybe you should put thumb_image.setOnClickListener(...) into your Adapter's getView method, so correct largeimage will be set to thumb_image's click event when corresponding item is shown.
I have use this from Here.. :)
From this three link you can get clear idea,,Hope this help.
See Here
If you want to use Image Button in your list view
Refere this last :)
Currently, I've been involved in an android app development related to online foodItem ordering. I've a listView with following schema:
itemName1 itemPrice1 checkBox
itemName2 itemPrice2 checkBox
itemName3 itemPrice3 checkBox
.
.
.
GetYourCart[Button]
My task is to keep track of each of the selected itemNames with price and total price when the user presses the button. I've used the SparseBooleanArray sbArray = myMenulist.getCheckedItemPositions(); but it's not showing any result.
How can I implement this? I've gone through several questions asked in stackoverflow and other online tutorials but can't get it.
Edited: Here is the code for selected items that I used to check the result:
btnyourCart.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
String selected = "";
int cntChoice = myMenulist.getCount();
SparseBooleanArray sbArray = myMenulist.getCheckedItemPositions();
for(int i=0;i<cntChoice;i++){
if(sbArray.get(i)) {
selected += myMenulist.getItemAtPosition(i).toString() + "\n";
}
}
Log.e("menu","Items "+selected);
Toast.makeText(getApplicationContext(), selected, Toast.LENGTH_SHORT).show();
}
});
Thanks in advance!
int total=0;
btnyourCart.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
String selected = "";
int cntChoice = myMenulist.getCount();
SparseBooleanArray sbArray = myMenulist.getCheckedItemPositions();
for(int i=0;i<cntChoice;i++){
if(sbArray.get(i)) {
selected += myMenulist.getItemAtPosition(i).toString() + "\n";
total+=myMenulist.get(i).price;
}
}
Log.e("menu","Items "+selected);
Toast.makeText(getApplicationContext(), selected, Toast.LENGTH_SHORT).show();
}
});
Now on button click event get total.
button.setOnClickListenernew View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
Toast.makeText(
this,
""+total,
Toast.LENGTH_LONG).show();
}
});
you need to do in your custom adapter in getView() method to keep checkbox value in list position and store that value in the array. This will keep checkbox value with its position.
#Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = null;
if(convertView == null){
LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = inflater.inflate(R.layout.list_layout, null);
final ViewHolder viewHolder = new ViewHolder();
viewHolder.checkBox = (CheckBox) view.findViewById(R.id.del_many_task_chk);
viewHolder.checkBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
#Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
Model element = (Model) viewHolder.checkBox.getTag();
element.isChecked = buttonView.isChecked();
}
});
view.setTag(viewHolder);
viewHolder.checkBox.setTag(list.get(position));
}else{
view = convertView;
((ViewHolder)view.getTag()).checkBox.setTag(list.get(position));
}
ViewHolder holder = (ViewHolder) view.getTag();
holder.checkBox.setChecked(list.get(position).isChecked);
return view;
}
Now when need to know which check box are checked or not then you need to go through your list item using iterator. To get the checked and unchecked item based on checkbox value.
for(int i=0;i<list.size();i++){
if(all_task_list.get(i).isChecked){
// to do things for checked item
}else{
// to do things for uncheck item
}
}