Hi Chander,
I wish if i could help with the whole source. The problem is the design.
let me tell you the real approach.
1. create a model class which holds the data that is name and checkbox with
setters and getters. below is the example
/** Holds Music data. */
private static class Music {
private String name = "";
private boolean checked = false;
public Music() {
}
have the setters and getters for name and checked
2.Create a View adapter class which holds the child view data. below is the
example
private static class MusicViewHolder {
private CheckBox checkBox;
private TextView textView;
public MusicViewHolder() {
}
public MusicViewHolder(TextView textView, CheckBox checkBox) {
this.checkBox = checkBox;
this.textView = textView;
}
public CheckBox getCheckBox() {
return checkBox;
}
public void setCheckBox(CheckBox checkBox) {
this.checkBox = checkBox;
}
public TextView getTextView() {
return textView;
}
public void setTextView(TextView textView) {
this.textView = textView;
}
}
3. your custom adapter which actally extends the Arrayadapter should be
like this
/** Custom adapter for displaying an array of Music objects. */
private static class MusicArrayAdapter extends ArrayAdapter<Music> {
private LayoutInflater inflater;
public MusicArrayAdapter(Context context, List<Music> musicList) {
super(context, R.layout.simplerow, R.id.rowTextView, musicList);
// Cache the LayoutInflate to avoid asking for a new one each time.
inflater = LayoutInflater.from(context);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// Music to display
Music music = (Music) this.getItem(position);
// The child views in each row.
CheckBox checkBox;
TextView textView;
// Create a new row view
if (convertView == null) {
convertView = inflater.inflate(R.layout.simplerow, null);
// Find the child views.
textView = (TextView) convertView
.findViewById(R.id.rowTextView);
textView.setTextColor(Color.BLACK);
checkBox = (CheckBox) convertView.findViewById(R.id.CheckBox01);
convertView.setTag(new MusicViewHolder(textView, checkBox));
checkBox.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
CheckBox cb = (CheckBox) v;
Music music = (Music) cb.getTag();
music.setChecked(cb.isChecked());
}
});
}
else {
MusicViewHolder viewHolder = (MusicViewHolder) convertView
.getTag();
checkBox = viewHolder.getCheckBox();
textView = viewHolder.getTextView();
}
checkBox.setTag(music);
checkBox.setChecked(music.isChecked());
textView.setText(music.getName());
return convertView;
}
}
4.finally your setItemclicklisteners should be
Music music = listAdapter.getItem(position);
music.toggleChecked();
MusicViewHolder viewHolder = (MusicViewHolder) item
.getTag();
viewHolder.getCheckBox().setChecked(music.isChecked());
That's it. as i said, i have done this earlier, it requries the whole
process. bascially you need to create and store the data in private Music[]
musiclistarray;
Warm Regards,
*Mukesh Kumar*,
Android Consultant/Freelancer,
India,Hyderabad.
On Wed, Jan 11, 2012 at 12:11 PM, chander <[email protected]> wrote:
> Hi all,
>
> In my application, i created a custom file adapter and i am using
> ListView with checkboxes, upto this point everything working great.
> But now i have to take the values of Checked listView items in an
> Array list. In my list view, i am listing Files present on the SD card
> so i have to take Files for further processing by storing it in an
> Array List.
>
> I am confused here how i pass multiple files for the processing, can
> someone help me in how i pass checked Files to further processing, or
> do i need to change my FileAdapter also ?
>
> My Adapter class code :--
>
> public class FileAdapter extends ArrayAdapter<File>
> {
> Context context;
> File[] files;
> CheckBox Check;
>
>
> public FileAdapter(Context context, File[] files)
> {
> super(context, -1, files);
> this.context = context;
> this.files = files;
>
>
> }
>
>
> Thanks
>
> --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en
--
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en