How to refresh the disabled ListView - android

I need help to refresh the ListView of disabled item. I've read a few articles, I gotta say I have no idea how to refresh the disabled item, therefore if you can give me a hand and post with that additional desired code, it would be more than appreciated.
Thanks in advance!
I have this code in my Activity:
adapter = new CustomAdapter(PendingOrdersActitvity.this, itemsList1);
listView.setAdapter(adapter);
adapter.notifyDataSetChanged();
listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
#Override
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
for (int i = 0; i <itemsList1.size(); i++) {
if(i == position){
view.setEnabled(false);
view.setClickable(false);
view.setBackgroundColor(Color.parseColor("#DCDBDB"));
ItemsBean bean = new ItemsBean();
bean.setInvNo(itemsList1.get(position).getInvNo());
bean.setItemnNameDisplay(itemsList1.get(position).getItemnNameDisplay());
bean.setQuantityDisplay(itemsList1.get(position).getQuantityDisplay());
bean.setProdnum(itemsList1.get(position).getProdnum());
newlist.add(bean);
adapter.getmethod(position);
}
}
insertintodatabase(newlist);
newlist.clear();
adapter.notifyDataSetChanged();
return true;
}
});
This is my custom Adapter class I don't know where is fault but i need help to complete the project as am new to android
public class CustomAdapter extends BaseAdapter {
Context ctx;
private int pos;
LayoutInflater inflator;
ArrayList<ItemsBean> newList = new ArrayList<ItemsBean>();
ArrayList<ItemsBean> newListitems = new ArrayList<ItemsBean>();
ArrayList<String> childList = new ArrayList<String>();
ArrayList<String> qtychildList = new ArrayList<String>();
String parentobjid=null;
PendingOrdersActitvity myactivity;
public CustomAdapter(PendingOrdersActitvity kdsActitvity, ArrayList<ItemsBean> invoiceDataList) {
this.ctx = kdsActitvity;
this.newList = invoiceDataList;
this.inflator = (LayoutInflater) ctx.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
pos = -1;
}
public int getCount() {
return newList.size();
}
public void getmethod(int pos1) {
pos = pos1;
}
#Override
public Object getItem(int position) {
return null;
}
#Override
public long getItemId(int position) {
return 0;
}
public static class ViewHolder {
TextView qty, name, childText, qtyChild;
}
#SuppressLint("NewApi") #Override
public View getView(final int position, View convertView, ViewGroup parent) {
ViewHolder holder;
String item = null, qty = null;
if (convertView == null) {
holder = new ViewHolder();
convertView = inflator.inflate(R.layout.invoicelistadapter, null);
holder.qty = (TextView) convertView.findViewById(R.id.qty);
holder.name = (TextView) convertView.findViewById(R.id.item);
holder.childText = (TextView) convertView
.findViewById(R.id.childitem);
holder.qtyChild = (TextView) convertView
.findViewById(R.id.qtychild);
convertView.setTag(holder);
} else {
if(pos!=-1 && pos==position)
{
convertView.setEnabled(false);
convertView.setClickable(false);
convertView.setBackgroundColor(Color.parseColor("#DCDBDB"));
}
holder = (ViewHolder) convertView.getTag();
}
//holder.qty.setText(String.valueOf(newList.get(position).getQuantityDisplay()));
parentobjid=newList.get(position).getParentobjectid();
if(!parentobjid.isEmpty())
{
holder.name.setText(" " +newList.get(position).getItemnNameDisplay());
holder.name.setTextColor(Color.parseColor("#CC0000"));
holder.qty.setText(" "+String.valueOf(newList.get(position).getQuantityDisplay()));
holder.qty.setTextColor(Color.parseColor("#CC0000"));
} else {
holder.name.setText(newList.get(position).getItemnNameDisplay());
holder.qty.setText(String.valueOf(newList.get(position)
.getQuantityDisplay()));
holder.name.setTextColor(Color.parseColor("#FFFFFF"));
holder.qty.setTextColor(Color.parseColor("#FFFFFF"));
}
}
}

call adapter.notifyDataSetChanged() inside the listview ClickListener.
listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
#Override
public boolean onItemLongClick(AdapterView<?> parent, View view,
int position, long id) {
// TODO Auto-generated method stub
for (int i = 0; i <itemsList1.size(); i++) {
if(i == position){
view.setEnabled(false);
view.setClickable(false);
view.setBackgroundColor(Color.parseColor("#DCDBDB"));
ItemsBean bean=new ItemsBean();
bean.setInvNo(itemsList1.get(position).getInvNo());
bean.setItemnNameDisplay(itemsList1.get(position).getItemnNameDisplay());
bean.setQuantityDisplay(itemsList1.get(position).getQuantityDisplay());
bean.setProdnum(itemsList1.get(position).getProdnum());
newlist.add(bean);
adapter.getmethod(position);
}
insertintodatabase(newlist);
newlist.clear();
adapter.notifyDataSetChanged();
return true;
}
});

The ListView is just a container.
Instead of enabling the single items, clear it and recreate it through your Adapter.
In fact the adapter just ties the ListView to an ArrayList of elements and represents into the ListView the "state" of the ArrayList.
Do not operate to ListView already created, but refresh the ArrayList and the ListView will be refreshed too!

use notifydatasetchanged();
Notifies the attached observers that the underlying data has been changed and any View reflecting the data set should refresh itself

Related

App crashes while trying to iterate through the ArrayList

When i was trying to iterate through the arraylist of custom listview used for loop, my app suddenly crashed and when i tried to look at the logcat no error appeared. I've tried one by one finding the problem then i found out the problem is the part where i try to get the item value. can help me point out the problem?
This is part of my code in iterating/getting the arraylist value
for(int i=0;i<=myAdapter.myItem.size();i++){
String name=tabl.getText().toString();
//this is the part that causes the crash
String answer=myAdapter.myItem.get(i).toString();
//mHelper.insertData(name,answer);
//temporary disable sql
}
This is my subclass for the custom listview
public class MyAdapter extends BaseAdapter {
private LayoutInflater mInflater;
public ArrayList myItem = new ArrayList();
public MyAdapter() {
mInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
for (int i = 1; i < x+1; i++) {
ListItem listItem = new ListItem();
listItem.caption = "hahaha";
myItem.add(i+".");
}
notifyDataSetChanged();
}
public int getCount() {
return myItem.size(); }
public Object getItem(int position) {
return position; }
public long getItemId(int position) {
return position; }
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView == null) {
holder = new ViewHolder();
convertView = mInflater.inflate(R.layout.items, null);
holder.caption = (EditText) convertView
.findViewById(R.id.ItemCaption);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
//Fill EditText with the value you have in data source
holder.caption.setText(myItem.get(position).toString());
holder.caption.setId(position);
//we need to update adapter once we finish with editing
holder.caption.setOnFocusChangeListener(new View.OnFocusChangeListener() {
public void onFocusChange(View v, boolean hasFocus) {
if (!hasFocus){
final int position = v.getId();
final EditText Caption = (EditText) v;
myItem.set(position, Caption.getText().toString());
}
}
});
return convertView;
}
}
class ViewHolder { EditText caption;}
class ListItem { String caption;}
change
for(int i=0;i<=myAdapter.myItem.size();i++){
with:
for(int i=0; i < myAdapter.myItem.size(); i++) {
When you're using <=, at the last iteration you're pointing to null. The condition should be just i < myAdapter.myItem.size();

ListView adapter behaves strangely

ListView adapter does strange things. Method getChecked() (adapter code shown below) does not return the value that I expect. As if he is late by one step.
For understanding, I will explain: I am using a custom ListView, every item contain one CheckBox (and other Views). I want to make when I press the button to show the position of the checked elements. This makes the method getChecked().
But the following happens: I check the 2nd and the 4th list items and click on the button, the result - [], then I check the 5th item, the result - [2, 4], then I clean all CheckBoxes, result [2, 4, 5] when I click the button again, I receive - []. Result is late by one step.
public class ContactAdapter extends BaseAdapter {
private LayoutInflater inflater;
private ArrayList<Contact> contacts;
private boolean isCheckBoxVisible;
private View view;
private int[] colors = {Color.BLACK, Color.BLUE, Color.RED, Color.GRAY, Color.GREEN};
private int currentMaleColor;
private int currentFemaleColor;
public ContactAdapter(Context context, ArrayList<Contact> contacts) {
this.contacts = contacts;
inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
isCheckBoxVisible = false;
setColors();
}
#Override
public int getCount() {
return contacts.size();
}
#Override
public Object getItem(int position) {
return contacts.get(position);
}
#Override
public long getItemId(int position) {
return position;
}
private Contact getContact(int position) {
return (Contact) getItem(position);
}
public void setCheckBoxVisibility(boolean isVisible) {
isCheckBoxVisible = isVisible;
notifyDataSetChanged();
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
view = convertView;
if (view == null) {
view = inflater.inflate(R.layout.contact_item, parent, false);
}
CheckBox cb = (CheckBox) view.findViewById(R.id.lv_box);
if (isCheckBoxVisible) {
cb.setVisibility(View.VISIBLE);
} else {
cb.setVisibility(View.INVISIBLE);
}
Contact c = getContact(position);
((TextView) view.findViewById(R.id.lv_name)).setText(c.getName() + " " + c.getSurname());
((ImageView) view.findViewById(R.id.lv_img)).setImageBitmap(c.getPhoto());
if (c.getSex().equals("Man")) {
view.setBackgroundColor(currentMaleColor);
} else {
view.setBackgroundColor(currentFemaleColor);
}
boolean isCheck = ((CheckBox) view.findViewById(R.id.lv_box)).isChecked();
contacts.get(position).setChecked(isCheck);
return view;
}
public ArrayList<Integer> getChecked() {
notifyDataSetChanged();
ArrayList<Integer> IDs = new ArrayList<Integer>();
for (Contact c : contacts) {
if (c.isChecked()) IDs.add(c.getID());
}
return IDs;
}
private void setColors() {
int colorM = Integer.parseInt(MainActivity.sp.getString("lp_colorM", "0"));
int colorW = Integer.parseInt(MainActivity.sp.getString("lp_colorW", "0"));
currentMaleColor = colors[colorM];
currentFemaleColor = colors[colorW];
}
}
In my activity I use my adapter, like so:
#Override
protected void onResume() {
super.onResume();
adapter = new ContactAdapter(getApplicationContext(), contacts);
list.setAdapter(adapter);
}
My button's code:
ArrayList<Integer> al = adapter.getChecked();
Toast.makeText(this, al.toString(), Toast.LENGTH_LONG).show();
What do you think about this? I will be glad of any help.
Try to get State of view if convertView == null
if (convertView == null) {
holder = new Holder();
convertView = mInflator.inflate(R.layout.row_viewproduct, null);
convertView.setTag(holder);
} else {
holder = (Holder) convertView.getTag();
}
// set the data to view from holder
This is not the answer but want say you can use below
private void setColors() {
int colorM = Integer.parseInt(MainActivity.sp.getString("lp_colorM", "0"));
int colorW = Integer.parseInt(MainActivity.sp.getString("lp_colorW", "0"));
if(colorM < 5){
currentMaleColor = colors[colorM];
}
if(colorW < 5){
currentFemaleColor = colors[colorM];
}
}
To answer your question look at the view holder pattern
http://ricston.com/blog/optimising-listview-viewholder-pattern/
On the advice of njzk2, I changed it:
boolean isCheck = ((CheckBox) view.findViewById(R.id.lv_box)).isChecked();
contacts.get(position).setChecked(isCheck);
At this:
CheckBox checkBox = (CheckBox) view.findViewById(R.id.lv_box);
checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
#Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
contacts.get(position).setChecked(isChecked);
}
});
Now it works :)

Custom List Adapter - select all checkboxes button [duplicate]

This question already has answers here:
Android Checkbox listview select all (disable/enable) [duplicate]
(4 answers)
Closed 8 years ago.
I have managed to implement a custom Listview which has check boxes. The user can tap a row on the listview and the checkbox will check. The positions are stored even if a user scrolls.
The listview is bound to the adapter in the onPostExecute of an Async task.
protected void onPostExecute(Boolean result) {
ImageAdapter adapter = new ImageAdapter(this, pix, paths);
lstView.setAdapter(adapter);
}
I can click on a list item and check the checkbox for that item like this:
lstView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view, int position, long row) {
CheckBox cb = (CheckBox) view.findViewById(R.id.checkBox1);
cb.performClick();
}
I want to introduce a button which will check all the checkboxes.
I tried this but it is not working.
mSelectAllButton.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
CheckBox cb = (CheckBox) v.findViewById(R.id.checkBox1);//find the checkbox in the custom list
int cntChoice = mListView.getCount();
for(int i = 0; i < cntChoice; i++)
{
//if the checkbox is not clicked then click it
if(!mListView.isItemChecked(i))
{
//cb.performClick(); // didnt work
//cb.setChecked(true); // didnt work
}
}
Can anyone please explain to me clearly (I am new to Android and Java) how to change my adapter, and also how to implement this in an OnClick Listener from my main activity?
Do I have to create a new ImageAdapter for this and rebind it to the ListView?
Thanks
My Adapter:
public class ImageAdapter extends BaseAdapter {
Context context;
ArrayList<Bitmap> images;
ArrayList folderName;
boolean[] checkBoxState;
public ImageAdapter(Context c, ArrayList<Bitmap> images, ArrayList folderName){
this.context = c;
this.images = images;
this.folderName = folderName;
this.context = context;
checkBoxState=new boolean[images.size()];
imageLoader = ImageLoader.getInstance();
}
public int getCount() {
return images.size();
}
public Object getItem(int arg0) {
// TODO Auto-generated method stub
return null;
}
public long getItemId(int arg0) {
// TODO Auto-generated method stub
return 0;
}
private class ViewHolder {
TextView title;
ImageView iconImage;
CheckBox checkbox;
}
public View getView(final int position, View arg1, ViewGroup arg2) {
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View v = arg1;
ViewHolder holder;
if (arg1 == null) {
LayoutInflater vi = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = vi.inflate(R.layout.list_row, null);
holder = new ViewHolder();
holder.title = (TextView) v.findViewById(R.id.filename);
holder.iconImage = (ImageView) v.findViewById(R.id.list_image);
holder.checkbox = (CheckBox)v.findViewById(R.id.checkBox1);
v.setTag(holder);
} else {
holder = (ViewHolder) v.getTag();
}
int i = folderName.get(position).toString().lastIndexOf('\\');
if(i!= -1)
{
holder.title.setText(folderName.get(position).toString().substring(i));
}
else
{
holder.title.setText(folderName.get(position).toString());
}
holder.iconImage.setImageBitmap(images.get(position));
holder.checkbox.setChecked(checkBoxState[position]);
holder.checkbox.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
if(((CheckBox)v).isChecked())
checkBoxState[position]=true;
else
checkBoxState[position]=false;
}
});
return v;
First you need to declare ImageAdapter adapter as global variable
Second, you used adapter in your
protected void onPostExecute(Boolean result) {
adapter = new ImageAdapter(this, pix, paths);
lstView.setAdapter(adapter);
}
Third, Add one more method in your ImageAdapter class
public void selectedAll() {
for(int i = 0; i< checkBoxState.length; i++){
checkBoxState[i] = true;
}
notifyDataSetChanged();
}
Final, call previous method in your select all click event.
if(adapter != null)
adapter.selectedAll();
First, you need to add one more parameter to your ViewHolder.
int id
Here are update for your getView() method
public View getView(final int position, View arg1, ViewGroup arg2) {
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View v = arg1;
final ViewHolder holder;
if (arg1 == null) {
LayoutInflater vi = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = vi.inflate(R.layout.list_row, null);
holder = new ViewHolder();
holder.title = (TextView) v.findViewById(R.id.filename);
holder.iconImage = (ImageView) v.findViewById(R.id.list_image);
holder.checkbox = (CheckBox) v.findViewById(R.id.checkBox1);
v.setTag(holder);
} else {
holder = (ViewHolder) v.getTag();
}
holder.id = position;
int i = folderName.get(position).toString().lastIndexOf('\\');
if (i != -1) {
holder.title.setText(folderName.get(position).toString()
.substring(i));
} else {
holder.title.setText(folderName.get(position).toString());
}
holder.iconImage.setImageBitmap(images.get(position));
holder.checkbox.setChecked(checkBoxState[position]);
holder.checkbox
.setOnCheckedChangeListener(new OnCheckedChangeListener() {
#Override
public void onCheckedChanged(CompoundButton arg0,
boolean isCheck) {
if (isCheck)
checkBoxState[holder.id] = true;
else
checkBoxState[holder.id] = false;
notifyDataSetChange();
}
});
return v;
}
Please let me know the result asap

Android - Remove GridView item from inside getView()?

I need a way to remove an Item from the GridView but this must be done from within the getView() method inside my custom Adapter. Here is my GridView:
Activity:
...
String[] newList;
newList[0] = "Item 1";
newList[1] = "Item 2";
newList[2] = "Item 3";
...
GridView GV = (GridView) getActivity().findViewById(R.id.gv);
GV.setAdapter(new Adapter(getActivity(), newList));
GV.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView arg0,
View arg1, int position, long arg3) {
...
}
});
Adapter
public class Adapter extends BaseAdapter {
private Context mContext;
private LayoutInflater mInflator;
private String mEntries[];
public static class ViewHolder {
public TextView myTextView;
}
public Adapter (Context context, String[] entries) {
mContext = context;
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) {
ViewHolder holder = null;
if(convertView == null) {
convertView = mInflator.inflate(R.layout.gvitemlayout, parent, false);
holder = new ViewHolder();
holder.myTextView = (TextView) convertView.findViewById(R.list.removeItem);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
String string = mEntries[position];
String[] data = string.split("\\.");
if (data.length < 2) {
TextView itemName = (TextView) convertView.findViewById(R.list.itemName);
itemName.setText("");
TextView itemClass = (TextView) convertView.findViewById(R.favlist.itemClass);
itemClass.setText("");
holder.myTextView.setText("");
TextView itemNone = (TextView) convertView.findViewById(R.list.itemNone);
itemNone.setText("No Items");
} else {
TextView itemName = (TextView) convertView.findViewById(R.list.itemName);
itemName.setText(data[1]);
TextView itemClass = (TextView) convertView.findViewById(R.list.itemClass);
itemClass.setText(data[0]);
}
final int info = (Integer) getItem(position);
holder.myTextView.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
SharedPreferences sP = mContext.getSharedPreferences("fav", mContext.MODE_PRIVATE);
Boolean b = sP.getBoolean(mEntries[info], false);
if (b == true) {
SharedPreferences.Editor editor = sP.edit();
editor.remove(mEntries[info]);
editor.commit();
// REMOVE ITEM CODE NEEDED HERE
}
}
});
return convertView;
}
}
Hope this makes it easier to understand what I need.
This is what I did, there was no need to initialise the 'adapter' variable. Inside the getView() simply do this:
Remove the Item from the list that was used as the data source.
So. if you want to remove Item 2 from the list
String mEntries[] = ITEM1, ITEM2, ITEM3, etc
Do this:
String newList[] = new String[mEntries.length - 1];
int count = 0;
for (int i = 0; i < mEntries.length; i++) {
if (mEntries.length - 1 > 0) {
if (mEntries[i] == mEntries[1]) { // mEntries[1] as the range starts from 0, so 1 would be ITEM2
// SKIP IF MATCHES THE ITEM YO WANT TO REMOVE
} else {
newList[count] = mEntries[i];
count++;
}
}
}
mEntries = newList; // save the new list into mEntries
notifyDataSetChanged(); // notify the changes and the listview/gridview will update
What you are asking for is very possible. You didn't give enough code for it to be clear exactly what's happening, but the code above you posted won't work unless the remove button is an entire view returned by getView in the adapter.
Your getView in your adapter will need to look something like this:
public View getView(final int position, View convertView, ViewGroup parent) {
if (convertView == null) {
convertView = inflater.inflate(R.layout.grid_view_item, null);
}
Button removeButton = (Button) convertView.findViewById(R.id.remove_button);
removeButton.setOnClickListener( new OnClickListener() {
#Override
public void onClick(View v) {
adapter.mThumbIdsList.remove(position);
adapter.notifyDataSetChanged();
}
});
return convertView;
}
Hope this helps. Good luck!

Android - Having problem while deleting items from ListView?

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

Categories

Resources