*> I tried doing custom base adapter but have a small problem. when i > check checkbox row scroll down some other check box is checked. * That is probably because you are using the convertView parameter that is passed to the getView() method (which is a good thing!)... What is happening is that you are reusing views when you scroll to avoid the cost of creating a new one unnecessarily every time. This also means that you will be inheriting the checked state of a checkbox because you are reusing a view but not changing the checked state.
What I do to solve this problem is come up with some sort of mechanism (usually a map or ArrayList of some sort) that I can use to tell me if a particular view is supposed to be checked or not, and I explicitly set the state of the checkbox in the getView method... Hope that helps, Justin ---------------------------------------------------------------------- There are only 10 types of people in the world... Those who know binary and those who don't. ---------------------------------------------------------------------- On Tue, May 11, 2010 at 12:58 AM, skalluraya <skallur...@gmail.com> wrote: > I tried doing custom base adapter but have a small problem. when i > check checkbox row scroll down some other check box is checked. > > The code for that is following: > > package com.testing; > > import java.io.IOException; > import java.util.ArrayList; > import android.content.Context; > import android.graphics.BitmapFactory; > import android.view.LayoutInflater; > import android.view.View; > import android.view.ViewGroup; > import android.view.View.OnClickListener; > import android.widget.BaseAdapter; > import android.widget.CheckBox; > import android.widget.CompoundButton; > import android.widget.ImageView; > import android.widget.LinearLayout; > import android.widget.TextView; > import android.widget.CompoundButton.OnCheckedChangeListener; > > > package com.virtualprogramming; > > import java.io.IOException; > import java.util.ArrayList; > import android.content.Context; > import android.graphics.BitmapFactory; > import android.view.LayoutInflater; > import android.view.View; > import android.view.ViewGroup; > import android.view.View.OnClickListener; > import android.widget.BaseAdapter; > import android.widget.CheckBox; > import android.widget.CompoundButton; > import android.widget.ImageView; > import android.widget.LinearLayout; > import android.widget.TextView; > import android.widget.CompoundButton.OnCheckedChangeListener; > > > public class QuickIDDialogAdapter extends BaseAdapter > { > > private Context mContext; > private final LayoutInflater mInflater; > private String[] mFeildsList; > private String mAssetFolderName; > private boolean[] mbCheckedStatus; > private ArrayList<String> mListData; > > > public QuickIDDialogAdapter(Context context,ArrayList<String> > inListData, String inAssetFolderName, boolean[] inCheckedStatus) > { > mInflater = LayoutInflater.from(context); > mContext = context; > mAssetFolderName = inAssetFolderName; > mbCheckedStatus = inCheckedStatus; > mListData = inListData; > } > > > @Override > public int getCount() > { > // TODO Auto-generated method stub > return mListData.size(); > } > > /** > * Since the data comes from an array, just returning the index is > sufficent > * to get at the data. If we were using a more complex data > structure, we > * would return whatever object represents one row in the list. > * > * @see android.widget.ListAdapter#getItem(int) > */ > public Object getItem(int position) > { > return position; > } > > /** > * Use the array index as a unique id. > * > * @see android.widget.ListAdapter#getItemId(int) > */ > public long getItemId(int position) > { > return position; > } > > /** > * Make a view to hold each row. > * > * @see android.widget.ListAdapter#getView(int, android.view.View, > * android.view.ViewGroup) > */ > public View getView(int position, View convertView, ViewGroup > parent) > { > // A ViewHolder keeps references to children views to avoid > unneccessary calls > // to findViewById() on each row. > ViewHolder holder; > > // When convertView is not null, we can reuse it directly, > there is > no need > // to reinflate it. We only inflate a new View when the > convertView > supplied > // by ListView is null. > if (convertView == null) > { > convertView = > mInflater.inflate(R.layout.dialoglistrow, null); > // Creates a ViewHolder and store references to the > two children > views > // we want to bind data to. > > holder = new ViewHolder(); > > > holder.filterCheckBox = (CheckBox) > convertView.findViewById(R.id.dialogrowcheckbox); > holder.filterCheckBox.setOnClickListener(new > CheckBoxClickListener(position)); > > holder.filterName = (TextView) > convertView.findViewById(R.id.dialogrowname); > holder.filterIcon = (ImageView) > convertView.findViewById(R.id.dialogrowimage); > convertView.setTag(holder); > } > else > { > // Get the ViewHolder back to get fast access to the > TextView > // and the ImageView. > holder = (ViewHolder) convertView.getTag(); > } > > String filterName = mListData.get(position); > // Bind the data efficiently with the holder. > holder.filterName.setText(filterName); > holder.filterCheckBox.setChecked(mbCheckedStatus[position]); > try > { > > > holder.filterIcon.setImageBitmap(BitmapFactory.decodeStream(mContext.getAssets().open(mAssetFolderName > +"/"+filterName+ ".png"))); > } > catch (IOException e) > { > // TODO Auto-generated catch block > e.printStackTrace(); > } > return convertView; > } > > static class ViewHolder > { > TextView filterName; > ImageView filterIcon; > CheckBox filterCheckBox; > boolean filterChecked=false; > @Override > public String toString() > { > // TODO Auto-generated method stub > return ""+filterName.getText()+"--"+filterChecked; > } > } > > > class CheckBoxClickListener implements OnClickListener > { > int miPosition = 0; > public CheckBoxClickListener(int position) > { > // TODO Auto-generated constructor stub > miPosition = position; > } > > > @Override > public void onClick(View v) > { > // TODO Auto-generated method stub > System.out.println(mbCheckedStatus[miPosition]+" > miPosition:"+miPosition); > // TODO Auto-generated method stub > if(mbCheckedStatus[(int)getItemId(miPosition)]) > { > mbCheckedStatus[(int)getItemId(miPosition)] > = false; > } > else > { > mbCheckedStatus[(int)getItemId(miPosition)] > = true; > } > } > > } > } > > > > > On May 10, 6:22 pm, TreKing <treking...@gmail.com> wrote: > > On Mon, May 10, 2010 at 2:18 AM, skalluraya <skallur...@gmail.com> > wrote: > > > How can i go about it. > > > > Try setting a custom adapter on the listview in the dialog. > > > > > ------------------------------------------------------------------------------------------------- > > TreKing - Chicago transit tracking app for Android-powered deviceshttp:// > sites.google.com/site/rezmobileapps/treking > > > > -- > > You received this message because you are subscribed to the Google > > Groups "Android Beginners" group. > > > > NEW! Try asking and tagging your question on Stack Overflow athttp:// > stackoverflow.com/questions/tagged/android > > > > To unsubscribe from this group, send email to > > android-beginners+unsubscr...@googlegroups.com<android-beginners%2bunsubscr...@googlegroups.com> > > For more options, visit this group athttp:// > groups.google.com/group/android-beginners?hl=en > > -- > You received this message because you are subscribed to the Google > Groups "Android Beginners" group. > > NEW! Try asking and tagging your question on Stack Overflow at > http://stackoverflow.com/questions/tagged/android > > To unsubscribe from this group, send email to > android-beginners+unsubscr...@googlegroups.com<android-beginners%2bunsubscr...@googlegroups.com> > For more options, visit this group at > http://groups.google.com/group/android-beginners?hl=en > -- You received this message because you are subscribed to the Google Groups "Android Beginners" group. NEW! Try asking and tagging your question on Stack Overflow at http://stackoverflow.com/questions/tagged/android To unsubscribe from this group, send email to android-beginners+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en