Android - Having problem while deleting items from ListView? - android

I have a ListView in my app which has a custom adapter. I have a ImageView, a CheckBox and a TextView in my list view and i have one button in my app which should delete Checked items from the list on onClick event but the problem is - It does not matter which items i am selecting but it's always deleting the items from the botton of the list.
here is my custom adapter's code -
public class IconAdapter extends BaseAdapter
{
private Activity activity;
private Object[] data;
private ArrayList<HashMap<String,String>> listItems;
public static LayoutInflater inflater = null;
private PackageManager pm;
public ArrayList<Boolean> itemChecked = new ArrayList<Boolean>();
private ArrayList<String> itemSelected = new ArrayList<String>();
private ArrayList<TextView> ctv = new ArrayList<TextView>();
private int posi;
private String pkg;
public IconAdapter(Activity a, ArrayList<HashMap<String,String>> items)
{
activity = a;
listItems = items;
data = items.toArray();
inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
pm = a.getPackageManager();
for(int i = 0; i < items.size(); i++)
{
itemChecked.add(i,false);
}
for(int i = 0; i < items.size(); i++)
{
itemSelected.add(i," ");
}
}
public int getCount() {
return listItems.size();
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
public static class ViewHolder{
public TextView textView;
public ImageView imageView;
public CheckBox checkBox;
}
public View getView(final int position, View convertView, ViewGroup parent)
{
View row = convertView;
ViewHolder holder;
if(row==null)
{
row = inflater.inflate(R.layout.item, parent, false);
holder = new ViewHolder();
holder.textView = (TextView)row.findViewById(R.id.text1);
holder.imageView = (ImageView)row.findViewById(R.id.image);
holder.checkBox = (CheckBox)row.findViewById(R.id.check);
row.setTag(holder);
}
else
{
holder = (ViewHolder) row.getTag();
}
String s = data[position].toString();
String[] tokens = s.split(",");
String[] mToken = tokens[0].split("=");
String taskName = mToken[1];
String[] mTokens = tokens[1].split("=");
final String pkgName = mTokens[1].substring(0, (mTokens[1].length() - 1));
holder.textView.setText(taskName);
holder.textView.setTag(pkgName);
holder.checkBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton button, boolean b) {
if (b)
{
itemChecked.set(position, true);
itemSelected.set(position, pkgName);
}
else
{
itemChecked.set(position, false);
}
}
});
holder.checkBox.setChecked(itemChecked.get(position));
try{
Drawable icon = pm.getApplicationIcon(pkgName);
holder.imageView.setImageDrawable(icon);
}
catch (PackageManager.NameNotFoundException ne)
{
}
return row;
}
public String getPkgName(int position)
{
return itemSelected.get(position);
}
public void setItemChecked(boolean isChecked)
{
}
}
nd here is my onClick code -
public void onClick(View view)
{
int size = icon.getCount();
for(int i = size-1; i >= 0; i--)
{
if(icon.itemChecked.get(i))
{
list.remove(i);
}
}
icon.notifyDataSetChanged();
}
please help!!!!!
And when i removed notifyDataSetChanged from onClick and reload the list manually again its working exactly i want it to work so there is some problem in NotyfyDataSetChanged. Please help.

You can use notifyDataSetChanged method of your adapter, but keep in mind some points that are stated here (see accepted answer) notifyDataSetChanged example

did you put a log statement in onCheckedChanged method and see what position is being set ? My guess is that you shouldn't use the position argument in that manner. One way to do so could be to use holder.checkBox.setTag(new Integer(position)) and in the onCheckedChanged method use int posClicked = ((Integer)button.getTag()).intValue() and then use this instead of position

Related

android arraylist won't refresh on runnnig app

my app consist of a main activity with 3 fragments and I have an arraylist of boolean type in the second fragment of grid adapter to check the states of checkbox in every position so an action could be done in the first fragment.
the issue is that the arreylist never updates and it keeps the same data values
my code is below
public class GridAdapter extends BaseAdapter {
private ArrayList<GridWord> list;
private Context context;
private ArrayList<Boolean> checkBoxState;
public boolean status;
GridAdapter (Context context) {
this.context = context;
checkBoxState = new ArrayList<Boolean>();
for (int y = 0; y < 14; y++){
checkBoxState.add(y, false);
}
}
#Override
public int getCount() {
return list.size();
}
#Override
public Object getItem(int position) {
return list.get(position);
}
#Override
public long getItemId(int i) {
return i;
}
class ViewHolder {
ImageView logoImage;
TextView textName;
CheckBox checkBox;
ViewHolder (View v){
logoImage = v.findViewById(R.id.grid_image);
textName = v.findViewById(R.id.grid_text);
checkBox = v.findViewById(R.id.grid_checbox);
}
}
#Override
public View getView(final int position, View convertView, ViewGroup parent) {
View row = convertView;
ViewHolder holder = null;
if (row == null){
LayoutInflater inflater = (LayoutInflater) context.getSystemService(context.LAYOUT_INFLATER_SERVICE);
row = inflater.inflate(R.layout.grid_item,parent,false);
holder = new ViewHolder(row);
row.setTag(holder);
}
else {
holder = (ViewHolder) row.getTag();
}
final GridWord temp = list.get(position);
holder.logoImage.setImageResource(temp.logo);
holder.textName.setText((CharSequence) temp.name);
final ViewHolder finalHolder = holder;
finalHolder.checkBox.setId(position);
row.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
status = true;
if(((finalHolder.checkBox.isChecked()))) {
checkCheckBox(position, false);
finalHolder.checkBox.setChecked(checkBoxState.get(position));
}
else {
checkCheckBox(position, true);
finalHolder.checkBox.setChecked(checkBoxState.get(position));
}
}
});
finalHolder.checkBox.setChecked(checkBoxState.get(position));
return row;
}
public ArrayList<Boolean> getCheckBoxState(){
return checkBoxState;
}
public void checkCheckBox(int position, boolean value) {
if (value)
checkBoxState.set(position, true);
else
checkBoxState.set(position, false);
notifyDataSetChanged();
}
}
#Override
public void setUserVisibleHint(boolean isVisibleToUser) {
super.setUserVisibleHint(isVisibleToUser);
isVisible = isVisibleToUser;
if (isVisible && isStarted) {
checkList.clear();
checkList = gridAdapter.getCheckBoxState();
for (int x = 0; x < checkList.size(); x++) {
if (checkList.get(x)) {
// some code
}
}
adapter.notifyDataSetChanged();
}
}
I would suggest you to have this arraylist in you activity holding this 3 fragments. Try updating this Arraylist from your Second fragment.
This way, whenever you want to read the values in First Fragment, you can read them from this global arraylist and hence so you have single instance of your arraylist.

Adding items into ListView in Fragments creates duplicates

This question has been asked so many times, but none of the solutions solved my issue.
I have an activity with two fragments with a viewpager, And each fragment has a listview. Upon moving between tabs my listview's items are repeating.
here is the adapter code.
public class ComboMenuAdapter extends BaseAdapter {
private Context mContext;
private MenuHolder mMenuHolder;
private ArrayList<Integer> index;
public ComboMenuAdapter(Context mContext, ArrayList<Integer> index) {
this.index = index;
this.mContext = mContext;
}
#Override
public int getCount() {
return index.size();
}
#Override
public MenuHolder getItem(int position) {
return DataHandler.getInstance().getData(index.get(position));
}
#Override
public long getItemId(int position) {
return position;
}
private class Holder {
ImageView image;
TextView price, liters, itemnametxt, mAdd_txt, minus, plus, counter;
}
#Override
public View getView(final int position, View convertView, ViewGroup parent) {
final Holder mHolder;
View v = convertView;
if (v == null) {
LayoutInflater vi = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v= vi.inflate(R.layout.combo_meals_adapter, null);
mHolder = new Holder();
mHolder.price = (TextView) v.findViewById(R.id.price);
mHolder.itemnametxt = (TextView) v.findViewById(R.id.itemnametxt);
mHolder.image = (ImageView) v.findViewById(R.id.image);
mHolder.liters = (TextView) v.findViewById(R.id.ml);
mHolder.mAdd_txt = (TextView) v.findViewById(R.id.addtxt);
mHolder.minus = (TextView) v.findViewById(R.id.minus);
mHolder.counter = (TextView) v.findViewById(R.id.count);
mHolder.plus = (TextView) v.findViewById(R.id.plus);
v.setTag(mHolder);
} else {
mHolder = (Holder) v.getTag();
}
mMenuHolder = getItem(position);
mHolder.itemnametxt.setText(mMenuHolder.getItemname());
mHolder.image.setImageResource(R.mipmap.ic_launcher);
mHolder.price.setText(mMenuHolder.getItemprice());
mHolder.counter.setText(mMenuHolder.getItemCount());
return v;
}
}
I am unable to find the mistake, please help me, Thank you in advance.
Here, I am storing the data using DataHandler Class
public class DataHandler {
ArrayList<MenuHolder> listOfItemsFromJson = new ArrayList<MenuHolder>();
private static DataHandler mInstance = null;
static public DataHandler getInstance() {
if (null == mInstance) {
mInstance = new DataHandler();
}
return mInstance;
}
public DataHandler() {
listOfItemsFromJson = new ArrayList<>();
}
public ArrayList<MenuHolder> getListOfItemsFromJson() {
return listOfItemsFromJson;
}
public void clearList() {
listOfItemsFromJson.clear();
}
public void addData(MenuHolder holder) {
listOfItemsFromJson.add(holder);
}
public MenuHolder getData(int position) {
return listOfItemsFromJson.get(position);
}
public void removeData(int position) {
listOfItemsFromJson.remove(getData(position));
}
public void modifyData(MenuHolder holder, int position) {
listOfItemsFromJson.set(position, holder);
}
public int size() {
return listOfItemsFromJson.size();
}
}
Upon onCreateView(), I am placing the data
for (int i = 0; i < DataHandler.getInstance().size(); i++) {
if (DataHandler.getInstance().getData(i).isCombo()) {
DataHandler.getInstance().removeData(i);
}
}
for (int i = 0; i < 3; i++) {
MenuHolder mMenuHolder = new MenuHolder();
mMenuHolder.setItemname(itemNames[i]);
mMenuHolder.setImageName("#mipmap/ic_launcher");
mMenuHolder.setItemCount("0");
mMenuHolder.setItemprice("500");
mMenuHolder.setUserSeleted(false);
mMenuHolder.setCombo(true);
mMenuHolder.setDrinks(false);
mMenuHolder.setBiryani(false);
DataHandler.getInstance().addData(mMenuHolder);
}
index.clear();
for (int i = 0; i < DataHandler.getInstance().size(); i++) {
if (DataHandler.getInstance().getListOfItemsFromJson().get(i).isCombo()) {
index.add(i);
}
}
mCombosAdapter = new ComboMenuAdapter(getActivity(), index);
mlistView.setVisibility(View.VISIBLE);
mlistView.setAdapter(mCombosAdapter);
mlistView.setOnItemClickListener(this);
mMenuHolder = getItem(position);
should be retrieved before setting the data. Move it outside the if/else logic before.
mMenuHolder = getItem(position);
mHolder.itemnametxt.setText(mMenuHolder.getItemname());
mHolder.image.setImageResource(R.mipmap.ic_launcher);
mHolder.price.setText(mMenuHolder.getItemprice());
mHolder.counter.setText(mMenuHolder.getItemCount());
you want to retrieve the item at position before filling up your view
Make sure you clear your adapter before adding new objects to it:
if (!someAdapter.isEmpty())
someAdapter.clear();
someAdapter.addAll(new ArrarList(arrayListContainingUpdatedStuff));
No need for a new adapter allocation, you might lose you reference to the old one and the list might go blank.
Hope this helps.
for this code you get Repeating data may be
for (int i = 0; i < 3; i++)
{
MenuHolder mMenuHolder = new MenuHolder();
mMenuHolder.setItemname(itemNames[i]);
mMenuHolder.setImageName("#mipmap/ic_launcher");
mMenuHolder.setItemCount("0");
mMenuHolder.setItemprice("500");
mMenuHolder.setUserSeleted(false);
mMenuHolder.setCombo(true);
mMenuHolder.setDrinks(false);
mMenuHolder.setBiryani(false);
DataHandler.getInstance().addData(mMenuHolder);
}

Android - Gridview, custom layout onclicklistener

I have a GridView with two TextViews inside it, When the GridView is populated, an OnClickListener is set which returns the position of the item that was selected. I want to trigger a method when one of the TextViews is selected.
Is this possible? If yes, how do I set this up?
EDIT 3:
Inside my activity whch populated the GridView: I retrieve a String-Array from my Strings.xml, a for loop examines each item inside the Array and searches for a condition based on the Item's name inside the SharedPreferences, this for loop is solely for counting how many "true" conditions there are, so it retrieves a int saved inside the count. Then a new String[] is created, this required an exact length to be given before items can be added to it, so I check count if it's more than 0, it will give the String[] a length of count and then another for loop will add each true to the String[] list that we just created. If count is 0 (no true conditions found in the first for loop) then only 1 Item is added to the String[] and is given the value "No Favourites Added".
Then you have the GridView's OnItemClickListener().
String s[] = getResources().getStringArray(R.array.FullList);
int count = 0;
for(int i = 0; i < s.length; i++) {
SharedPreferences sP = getActivity().getSharedPreferences("fav", MODE_PRIVATE);
Boolean b = sP.getBoolean(s[i], false);
if (b == true) {
count++;
}
}
String[] newList;
if (count > 0) {
newList = new String[count];
count = 0;
for(int i = 0; i < s.length; i++) {
SharedPreferences sP = getActivity().getSharedPreferences("fav", MODE_PRIVATE);
Boolean b = sP.getBoolean(s[i], false);
if (b == true) {
newList[count] = s[i];
count++;
}
}
} else {
newList = new String[1];
newList[0] = "No favourites added";
}
GridView FavGV = (GridView) getActivity().findViewById(R.id.sexp_fav);
FavGV.setAdapter(new Tab01_FavAdapter(getActivity(), newList));
FavGV.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView arg0,
View arg1, int position, long arg3) {
//Intent i = new Intent(getActivity(), PosPreview_Gestures.class);
//i.putExtra("position", position);
//startActivity(i);
}
});
So that's the code inside the Activity which populates the GridView. The Adapter in it's original, functioning form: This simply populates the GridView with Favourite Items (their names from the String[]) and adds a TextView with "Remove" which when pressed, shows a Toast: "Remove".
public class Tab01_FavAdapter extends BaseAdapter {
private Context mContext;
private LayoutInflater mInflator;
String mEntries[];
public Tab01_FavAdapter (Context c, String[] entries) {
mContext = c;
mInflator = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
mEntries = entries;
}
#Override
public int getCount() {
return mEntries.length;
}
#Override
public Object getItem(int position) {
return position;
}
#Override
public long getItemId(int position) {
return position;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
if(convertView == null) {
convertView = mInflator.inflate(R.layout.favitemlayout, parent, false);
}
TextView tx = (TextView) convertView.findViewById(R.id.favgridremoveitem);
OnClickListener oCL = new OnClickListener() {
#Override
public void onClick(View v) {
Toast.makeText(mContext,"Remove",Toast.LENGTH_SHORT).show();
}
};
tx.setOnClickListener(oCL);
return convertView;
}
}
I am assuming that you are using a custom adapter for populating this GridView, and passing the Context as an argument to the constructor.
In the custom adapter, you should add onClickListeners to the TextViews. Using the context, you can call methods from your activity:
((CallingActivityName)context).methodYouWishToCall(parameters);
This would go inside the onClickListeners.
Edit: Added some code:
public class MyGridAdapter extends BaseAdapter {
private final List<MyObjectClass> mEntries;
private final LayoutInflater mInflater;
private final Context mContext;
public static class ViewHolder {
public TextView tx;
}
public MyGridAdapter(CallingActivityName context, List<MyObjectClass> entries) {
super();
mEntries = entries;
mContext = context;
mInflater = (LayoutInflater) mContext
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
#Override
public int getCount() {
return mEntries.size();
}
#Override
public Object getItem(int position) {
return mEntries.get(position);
}
#Override
public View getView(final int position, View convertView, ViewGroup parent) {
final ViewHolder holder;
if (convertView == null) {
convertView = mInflator.inflate(R.layout.favitemlayout, parent, false);
holder = new ViewHolder();
holder.tx = (TextView) convertView
.findViewById(R.id.favgridremoveitem);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
final MyObjectClass info = mEntries.get(position);
holder.tx.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
((CallingActivityName)mContext).favRemove(info);
notifyDataSetChanged();
}
});
return convertView;
}
}
So, CallingActivityName is the name of the Activity where you initiate the adapter and where the method you need to call resides. info is the object held at position position of the gridview. MyObjectClass is the class name of the objects in the List mEntries.

Checking all the check boxes

I want to implement a scenario-
There is present a checkbox on the top of the screen and there is a custom listview with checkboxes below that top checkbox.
I want that one someone checks that checkbox all the listview checkboxes should be checked and vice versa.
public class GroupMemberListAdapter extends BaseAdapter {
private LayoutInflater inflater = null;
Context Mycontext;
public GroupMemberListAdapter(Context context) {
Mycontext = context;
inflater = LayoutInflater.from(context);
}
public int getCount() {
return broadcastList.size();
}
public Object getItem(int paramInt) {
return paramInt;
}
public long getItemId(int paramInt) {
return paramInt;
}
public View getView(int position, View convertView, ViewGroup parent) {
EventViewHolder holder;
if (convertView == null) {
convertView = inflater.inflate(R.layout.contactcustomlayout,
null);
holder = new EventViewHolder();
holder.mtvGroupMemberName = (TextView) convertView
.findViewById(R.id.tvGroupMemberName);
holder.checkbox_group_member = (CheckBox)convertView.findViewById(R.id.checkBox_GroupMember);
/*holder.mtvGroupMemberAbout = (TextView) convertView
.findViewById(R.id.tvGroupMemberAbout);*/
convertView.setTag(holder);
} else {
holder = (EventViewHolder) convertView.getTag();
}
holder.mtvGroupMemberName.setText(""+broadcastList.get(position));
//holder.mtvGroupMemberAbout.setText(""+data.get(position));
return convertView;
}
public class EventViewHolder {
private TextView mtvGroupMemberName;
private TextView mtvGroupMemberAbout;
private CheckBox checkbox_group_member;
}
}
checkBox_selectAll.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
checkAllBoxes();
}
});
private void checkAllBoxes(){
int size = mlvGroupBroadContact.getAdapter().getCount();
System.out.println("Size of the list is:"+size);
}
How can I check all the list view boxes???
If your ListView's choice mode is CHOICE_MODE_MULTIPLE or CHOICE_MODE_SINGLE:
private void deselectAll() {
getListView().clearChoices();
//--as of GingerBread, clearChoices() alone is not sufficient--
//--we'd have to manually un-check visible items--
for (int i = 0; i < getListView().getChildCount(); i++) {
View c = getListView().getChildAt(i);
if (c instanceof Checkable) {
((Checkable) c).setChecked(false);
}
}
}
private void selectAll() {
SparseBooleanArray sba = getListView().getCheckedItemPositions();
for (int i = 0; i < getAdapter().getCount(); i++) {
sba.put(i, true);
}
for (int i = 0; i < getListView().getChildCount(); i++) {
View c = getListView().getChildAt(i);
if (c instanceof Checkable) {
((Checkable) c).setChecked(true);
}
}
}
Replace getListView() and getAdapter() with your ListView and its Adapter instances.
you can use the below code to check all checkboxes in the listview
private void checkAllBoxes(){
int size = mlvGroupBroadContact.getAdapter().getCount();
System.out.println("Size of the list is:"+size);
CheckBox chk;
for(int i=0;i<size;i++)
{
chk= ((CheckBox)jobList.getChildAt(i).findViewById(R.id.chk));
chk.setChecked(true);
}
}
Update a Boolean variable in your adapter class from on checkBox_selectAll click listner.
and call view.getAdapter.notifyDataSetChanged();
In getView based on this variable set it state checked or unchecked.

Android - Unable to check all the CheckBoxes in a custom listview because of recycling issue?

I have a custom listview adapter with a imageview, textview and a checkbox. and i also have a button and a checkbox in my main layout(not in listview).
What here i want is to check all these listview checkboxes at once when i check my main layout's checkbox.
And i am saving the state of these checkbox in boolean type arraylist so i am able to check these checkboxes when i check one by one but so far i did not find a single way to check all these checkbox at once which i can use in my main layout's checkbox's OnCheckedChanged event.
i tried few techniques but because of ListView's recycling procedure it checks only those items which are currently visible and as i scroll down to my list, all the above items set to unchecked and some random items got checked.
how to get over this recycle thing and how to check all these checkboxes at once???? any advise? solution? idea?
here is a code of my Custom Adapter : -
public class IconAdapter extends BaseAdapter
{
private Activity activity;
private Object[] data;
private ArrayList<HashMap<String,String>> listItems;
public static LayoutInflater inflater = null;
private PackageManager pm;
private ArrayList<Boolean> itemChecked = new ArrayList<Boolean>();
private ArrayList<String> itemSelected = new ArrayList<String>();
private ArrayList<CheckBox> ctv = new ArrayList<CheckBox>();
public IconAdapter(Activity a, ArrayList<HashMap<String,String>> items)
{
activity = a;
listItems = items;
data = items.toArray();
inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
pm = a.getPackageManager();
for(int i = 0; i < items.size(); i++)
{
itemChecked.add(i,false);
}
for(int i = 0; i < items.size(); i++)
{
itemSelected.add(i," ");
}
}
public int getCount() {
return listItems.size();
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
public static class ViewHolder{
public TextView textView;
public ImageView imageView;
public CheckBox checkBox;
}
public View getView(final int position, View convertView, ViewGroup parent)
{
View row = convertView;
ViewHolder holder;
if(convertView==null)
{
row = inflater.inflate(R.layout.item, parent, false);
holder = new ViewHolder();
holder.textView = (TextView)row.findViewById(R.id.text1);
holder.checkBox = (CheckBox)row.findViewById(R.id.check);
holder.imageView = (ImageView)row.findViewById(R.id.image);
holder.checkBox.setTag(position);
row.setTag(holder);
}
else
{
holder = (ViewHolder)row.getTag();
}
String s = data[position].toString();
String[] tokens = s.split(",");
String[] mToken = tokens[0].split("=");
String taskName = mToken[1];
String[] mTokens = tokens[1].split("=");
final String pkgName = mTokens[1].substring(0, (mTokens[1].length() - 1));
holder.textView.setText(taskName);
ctv.add(holder.checkBox);
holder.checkBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton button, boolean b) {
//int posClicked = ((Integer)button.getTag());
if(b)
{
itemChecked.set(position, true);
itemSelected.set(position, pkgName);
}
else
{
itemChecked.set(position,false);
}
}
});
holder.checkBox.setChecked(itemChecked.get(position));
try{
Drawable icon = pm.getApplicationIcon(pkgName);
holder.imageView.setImageDrawable(icon);
}
catch (PackageManager.NameNotFoundException ne)
{
}
row.setId(position);
return row;
}
public boolean isChecked(int position)
{
return itemChecked.get(position);
}
public String getPkgName(int position)
{
return itemSelected.get(position);
}
public void removeItem(int position)
{
listItems.remove(position);
}
public void setItemChecked(boolean isChecked)
{
if(isChecked)
{
for(int i = 0; i < ctv.size(); i++)
{
ctv.get(i).setChecked(true);
}
}
else
{
for(int i = 0; i < ctv.size(); i++)
{
ctv.get(i).setChecked(false);
}
}
}
as you can see in the end of this adapter i made a function setItemChecked() but this function is also a victim of recycle process as its only checking the visible item and as i scroll down it starts misbehaving.
any help would be great.
Thanks.
This morning I read an answer of an issue like this, and they recommend we put holder.checkBox.setChecked(itemChecked.get(position)); before holder.checkBox.setOnCheckedChangeListener
So, getView function will be rewritten like this:
public View getView(....)
{
...
holder.checkBox.setChecked(itemChecked.get(position));///move to here
holder.checkBox.setOnCheckedChangeListener(...);
...
)
Yeah, this recycling is a pain.
Here's what I did:
http://dev.kafol.net/2011/11/android-checkbox-listview-un-check-all.html
I'm still having some issues with SharedPreferences, as allthough I have managed to get all the checkboxes checked or unchecked, it still doesn't save the state to sharedpreferences.

Categories

Resources