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);
}
Related
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.
I am using the StickyListHeadersListView android library from github for my application. It was working fine. After I implement MultiChoiceMode listener for copying and deleting elements, there is a problem in highlighting of elements.
Whenever I select an element and scroll up and down, some Section Headers are highlighted automatically like shown in the image below
How to avoid this behaviour. Is there any steps I'm missing? Need some hand in resolving the issue.
My Adapter which extends the StickyListHeadersAdapter is given below
public class MessageStickyAdapter extends BaseAdapter implements StickyListHeadersAdapter, SectionIndexer {
private final Context mContext;
private List<Msg> messages;
private int[] mSectionIndices;
private String[] mSectionDates;
private LayoutInflater mInflater;
public MessageStickyAdapter(Context context,List<Msg> listMessages) {
mContext = context;
mInflater = LayoutInflater.from(context);
messages = listMessages;
mSectionIndices = getSectionIndices();
mSectionDates = getSectionDates();
}
private int[] getSectionIndices() {
ArrayList<Integer> sectionIndices = new ArrayList<>();
String lastDate = messages.get(0)._msg_date;
sectionIndices.add(0);
for (int i = 1; i < messages.size(); i++) {
if (!messages.get(i)._msg_date.equalsIgnoreCase(lastDate)) {
Log.d("LastDate,Newdate",lastDate + ',' +messages.get(i)._msg_date);
lastDate = messages.get(i)._msg_date;
sectionIndices.add(i);
}
}
int[] sections = new int[sectionIndices.size()];
for (int i = 0; i < sectionIndices.size(); i++) {
sections[i] = sectionIndices.get(i);
}
Log.d("Sections",String.valueOf(sections.length));
return sections;
}
private String[] getSectionDates() {
String[] dates = new String[mSectionIndices.length];
for (int i = 0; i < mSectionIndices.length; i++) {
dates[i] = messages.get(i)._msg_date;
Log.d("Dates",dates[i]);
}
return dates;
}
#Override
public int getCount() {
return messages.size();
}
#Override
public Object getItem(int position) {
return messages.get(position);
}
#Override
public long getItemId(int position) {
return position;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView == null) {
holder = new ViewHolder();
convertView = mInflater.inflate(R.layout.right, parent, false);
holder.text = (TextView) convertView.findViewById(R.id.msgr);
holder.time = (TextView) convertView.findViewById(R.id.tim);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
try {
holder.text.setText(URLDecoder.decode( messages.get(position)._msg_content, "UTF-8"));
holder.text.setTag(messages.get(position).getMsgID());
holder.time.setText(messages.get(position)._msg_time);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
return convertView;
}
#Override
public View getHeaderView(int position, View convertView, ViewGroup parent) {
HeaderViewHolder holder;
if (convertView == null) {
holder = new HeaderViewHolder();
convertView = mInflater.inflate(R.layout.date_separator, parent, false);
holder.text = (TextView) convertView.findViewById(R.id.textSeparator);
convertView.setTag(holder);
} else {
holder = (HeaderViewHolder) convertView.getTag();
}
String headerText = messages.get(position)._msg_date;
holder.text.setText(headerText);
return convertView;
}
/**
* Remember that these have to be static, postion=1 should always return
* the same Id that is.
*/
#Override
public long getHeaderId(int position) {
// return the first character of the country as ID because this is what
// headers are based upon
return getSectionForPosition(position);
}
#Override
public int getPositionForSection(int section) {
if (mSectionIndices.length == 0) {
return 0;
}
if (section >= mSectionIndices.length) {
section = mSectionIndices.length - 1;
} else if (section < 0) {
section = 0;
}
return mSectionIndices[section];
}
#Override
public int getSectionForPosition(int position) {
for (int i = 0; i < mSectionIndices.length; i++) {
if (position < mSectionIndices[i]) {
return i - 1;
}
}
return mSectionIndices.length - 1;
}
#Override
public Object[] getSections() {
return mSectionDates;
}
public void clear() {
messages.clear();
mSectionIndices = new int[0];
mSectionDates = new String[0];
notifyDataSetChanged();
}
public void restore(List<Msg> newMessages)
{
messages.clear();
mSectionIndices = new int[0];
mSectionDates = new String[0];
messages = newMessages;
mSectionIndices = getSectionIndices();
mSectionDates = getSectionDates();
notifyDataSetChanged();
}
public void add(Msg newMessage)
{
messages.add(0,newMessage);
mSectionIndices = getSectionIndices();
mSectionDates = getSectionDates();
}
class HeaderViewHolder {
TextView text;
}
class ViewHolder {
TextView text;
TextView time;
}
}
I'm trying to scroll my simple listview, but unfortunately it's not scrolling smoothly.
I can't figure out what seem to be the problem. I'm not doing anything fancy.
public class ArticleRowAdapter extends BaseAdapter {
private static final int TYPE_MAINARTICLE = 0;
private static final int TYPE_ARTICLE = 1;
private static final int TYPE_MAX_COUNT = TYPE_ARTICLE + 1;
private Context context;
private ArrayList<ArticleRow> mData = new ArrayList<ArticleRow>();
private LayoutInflater mInflater;
public ArticleRowAdapter(Context context,ArrayList<ArticleRow> data) {
this.context = context;
this.mData = data;
mInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
static class ArticleRowHolder
{
TextView tvTitle;
ImageView ivImage;
TextView tvSubTitle;
}
public void addItem(final ArticleRow item) {
mData.add(item);
notifyDataSetChanged();
}
#Override
public int getItemViewType(int position) {
return position == 0 ? TYPE_MAINARTICLE : TYPE_ARTICLE;
}
#Override
public int getViewTypeCount() {
return TYPE_MAX_COUNT;
}
#Override
public int getCount() {
return mData.size();
}
#Override
public ArticleRow getItem(int position) {
return mData.get(position);
}
#Override
public long getItemId(int position) {
return position;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
ArticleRowHolder holder = null;
int type = getItemViewType(position);
if(convertView == null)
{
holder = new ArticleRowHolder();
switch(type)
{
case TYPE_MAINARTICLE:
convertView = mInflater.inflate(R.layout.mainarticle,parent, false);
break;
case TYPE_ARTICLE:
convertView = mInflater.inflate(R.layout.article,parent , false);
break;
}
holder.tvTitle = (TextView)convertView.findViewById(R.id.articleTitle);
holder.ivImage = (ImageView)convertView.findViewById(R.id.articleImage);
holder.tvSubTitle = (TextView)convertView.findViewById(R.id.articleSubTitle);
convertView.setTag(holder);
}
else
{
holder = (ArticleRowHolder)convertView.getTag();
}
ArticleRow articleRow = mData.get(position);
holder.tvTitle.setText((CharSequence)articleRow.title);
holder.tvSubTitle.setText(Html.fromHtml(articleRow.subTitle));
if(articleRow.imageURL == null)
holder.ivImage.setImageDrawable(this.context.getResources().getDrawable(R.drawable.dunk));
else
{
holder.ivImage.setImageDrawable(this.context.getResources().getDrawable(R.drawable.dunk));
}
return convertView;
}
I can say that the reason of lags are imageViews, thats for sure:
holder.ivImage = (ImageView)convertView.findViewById(R.id.articleImage);
try to not to fill imageViews with images and see what happens :). Also check google's BitmapFun and LazyList - both about images in list/grid views
I am working on app which has a GridView of images but the last item in GridView is a button that loads more item into Grid. But i am facing a strange issue and that is Button shows up sometime and sometime it doesn't specially when i scroll up and down really fast on GridView. I think it's because of recycle issue but i don't know how to fix it.
Here is my code:-
public class ButtonGridAdapter extends BaseAdapter implements OnCheckedChangeListener, OnClickListener {
private ArrayList<String> thumbUrls;
private ArrayList<String> mainUrls;
private LayoutInflater layoutInflater;
private Context context;
private Intent intent;
private ArrayList<String> positions = new ArrayList<String>();
private static ArrayList<String> urlsToUpload = new ArrayList<String>();
private int width;
public ButtonGridAdapter(Context context, ArrayList<String> thumbUrls, ArrayList<String> mainUrls, String clicked)
{
this.context = context;
this.thumbUrls = thumbUrls;
this.mainUrls = mainUrls;
intent = new Intent(context, GalleryView.class);
this.layoutInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
DisplayMetrics displaymetrics = new DisplayMetrics();
((Activity) context).getWindow().getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
this.width = displaymetrics.widthPixels;
System.out.println(width+" width");
}
#Override
public int getCount() {
return thumbUrls.size()+1;
}
#Override
public Object getItem(int arg0) {
return thumbUrls.get(arg0);
}
#Override
public long getItemId(int position) {
return position;
}
public static class ViewHolder
{
ImageView mainImage;
CheckBox checkBox;
Button button;
}
public static class ButtonHolder
{
}
#Override
public View getView(final int position, View convertView, ViewGroup parent) {
View row = convertView;
ViewHolder holder;
if(row==null || row.getTag().equals("button"))
{
row = layoutInflater.inflate(R.layout.griditem, parent, false);
holder = new ViewHolder();
holder.mainImage = (ImageView)row.findViewById(R.id.itemgrid);
holder.checkBox = (CheckBox)row.findViewById(R.id.itemselected);
holder.button = null;
row.setTag(holder);
}
else
{
holder = (ViewHolder)row.getTag();
}
if(position==thumbUrls.size())
{
int width = row.getWidth();
int height = row.getHeight()-70;
row = layoutInflater.inflate(R.layout.mybutton, parent, false);
holder.button = (Button)row.findViewById(R.id.gridbutton);
holder.button.setText("Load More");
LayoutParams params = holder.button.getLayoutParams();
params.height = height;
params.width = width;
holder.button.requestLayout();
holder.button.setOnClickListener(this);
System.out.println("Called");
row.setTag("button");
return row;
}
else
{
setImageSize(holder.mainImage);
System.out.println(position);
holder.mainImage.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
intent.putExtra("position", position);
intent.putStringArrayListExtra("MainUrls", mainUrls);
intent.putStringArrayListExtra("Thumbnails", thumbUrls);
context.startActivity(intent);
}
});
holder.checkBox.setOnCheckedChangeListener(null);
holder.checkBox.setTag(position);
holder.checkBox.setChecked(positions.contains(thumbUrls.get(position)));
holder.checkBox.setOnCheckedChangeListener(this);
UrlImageViewHelper.setUrlDrawable(holder.mainImage, thumbUrls.get(position), R.drawable.extras_load);
return row;
}
}
private void setImageSize(ImageView imageView) {
LayoutParams params = imageView.getLayoutParams();
int leftWidth = width - 80;
params.width = leftWidth/3;
params.height = leftWidth/3;
imageView.requestLayout();
}
#Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if(isChecked)
{
positions.add(thumbUrls.get((Integer)buttonView.getTag()));
urlsToUpload.add(mainUrls.get((Integer)buttonView.getTag()));
}
else
{
positions.remove(thumbUrls.get((Integer)buttonView.getTag()));
urlsToUpload.remove(mainUrls.get((Integer)buttonView.getTag()));
}
}
public static ArrayList<String> getUrlsToUpload()
{
return urlsToUpload;
}
#Override
public void onClick(View v) {
if(v.getId()==R.id.gridbutton)
{
InstagramImpl.getInstance().fetchMorePhotos();
}
}
}
Any help would be really really appreciate.
Thanks.
I post full getView method from my other answer. Simple you check the position first. If it's the last item (load more button) return layout immediately.
private final Media special = new Media("-1", "", "", "", "");
public MediaGridAdapter(Context context, int imageID, ArrayList<Media> array, int type, boolean isGetMore) {
list = array;
mediaType = type;
this.context = context;
if(list != null) {
list.add(special);
}
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
RelativeLayout item;
ViewHolder holder;
//this part check it's the last item. -1 is my special item id in contructor.
if(list.get(position).getId().equals("-1")) {
item = (RelativeLayout) LayoutInflater.from(context).inflate(R.layout.item_special_more, null);
item.setTag(MORE_BUTTON);
return item;
}
//
if(convertView == null || convertView.getTag().toString().equals(MORE_BUTTON)) {
Context context = parent.getContext();
item = (RelativeLayout) LayoutInflater.from(context).inflate(R.layout.item_with_icon_vertical, null);
holder = new ViewHolder();
holder.thumbnail = (ImageView) item.findViewById(R.id.iv_icon_media);
item.setTag(holder);
} else {
item = (RelativeLayout) convertView;
holder = (ViewHolder) item.getTag();
}
}
// set data.
holder.thumbnail.setBitmap(...)
return item;
Maybe you can try delete row==null and holder = (ViewHolder)row.getTag(); it's because of recycle issue,you can have a try first.But it will affect efficiency. Another thing i want to say,how do position==thumbUrls.size();? Maybe it's position==thumbUrls.size()-1;.Ok,that's my view,i help it work.
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