Mohan, I have done this before, where i am reading all the music files in
SDCard and able to show it in Listview with checkbox.

Please follow the below points which will help you in resolving.

1. Create a class which extends the ArrayAdapter

2.In the getView method of the Adapterclass have the following.

// 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());
}
});
}



in onCreate bind the Adapter with your list.

listAdapter = new MusicArrayAdapter(this, musicList);
mainListView.setAdapter(listAdapter);


Warm Regards,
*Mukesh Kumar*,
Android Consultant/Freelancer,
India,Hyderabad



On Tue, Jan 10, 2012 at 11:09 AM, chander <mohan.c...@gmail.com> wrote:

> hi all,
>
> I am creating an application in which i used a List view to list all
> files present in SD card, but for some purpose i need to make ListView
> checkable or selectable by user.
> i created my own Array adapter of Files, i tried getChoiceMode
> property as Multiselection but its not working. can someone help me in
> correcting my code if there is any missing thing.
>
>        ListView listFiles;
>        FileAdapter adapter;
>        File[] files;           // Full path to the files
>        File file;              // Current file
>  public void onCreate(Bundle savedInstanceState)
>    {
>        super.onCreate(savedInstanceState);
>        setContentView(R.layout.filelist);
>
>        Home = this.getFilesDir();
>
>        // Finding Buttons for listing files
>
>        btnBack = (Button)findViewById(R.id.btnBack);
>        btnBack.setOnClickListener(this);
>
>        btnSDCard = (Button)findViewById(R.id.btnSDCard);
>        btnSDCard.setOnClickListener(this);
>
>        btnHome = (Button)findViewById(R.id.btnHome);
>        btnHome.setOnClickListener(this);
>
>        btnRoot = (Button)findViewById(R.id.btnRoot);
>        btnRoot.setOnClickListener(this);
>
>        listFiles = (ListView)findViewById(R.id.listFiles);
>        listFiles.setOnItemClickListener(this);
>
>        listFiles.setAdapter(new
>
> ArrayAdapter<File>(this,android.R.layout.simple_list_item_multiple_choice,files));
>        adapter = new FileAdapter(this,files);
>        listFiles.setAdapter(adapter);
>        listFiles.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
> }
>
>
> When i am running this code its giving Null Pointer exception,can
> someone help me how i rectify or correct this problem.
>
>
> Thanks
>
> --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to android-developers@googlegroups.com
> To unsubscribe from this group, send email to
> android-developers+unsubscr...@googlegroups.com
> 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 android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to