我想在 String 数组中获取已检查的项目列表。我已经将 videoList 作为列表视图,并且我已经用它实现了基本适配器并覆盖了 baseadapter 并使用复选框对其进行了自定义。
我已经尝试过了,但它给出了 nullpointerexception。
btnplay.setOnClickListener(new View.OnClickListener()
{
SparseBooleanArray sparseBooleanArray = videolist.getCheckedItemPositions();
@Override
public void onClick(View v)
{
for(int i =0 ; i<videolist.getCount();i++)
{
if(sparseBooleanArray.get(i))
{
String str = (String) videolist.getItemAtPosition(sparseBooleanArray.keyAt(i));
Toast.makeText(getBaseContext(),str , 3).show();
}
}
}
});
public class VideoAdapter extends BaseAdapter
{
private Context vContext;
public VideoAdapter(Context c)
{
vContext = c;
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return count;
}
@Override
public Object getItem(int arg0) {
// TODO Auto-generated method stub
return null;
}
@Override
public long getItemId(int arg0) {
// TODO Auto-generated method stub
return 0;
}
@Override
public View getView(int position, View convertView, ViewGroup parent)
{
System.gc();
LayoutInflater inflater = (LayoutInflater) vContext.getSystemService(vContext.LAYOUT_INFLATER_SERVICE);
View view;
CheckBox cb;
String id = null;
if (convertView == null)
{
view = new View(vContext);
view = inflater.inflate(R.layout.row, null);
cb = (CheckBox) view.findViewById(R.id.checkBox1);
video_column_index = videocursor.getColumnIndexOrThrow(MediaStore.Video.Media._ID);
videocursor.moveToPosition(position);
video_column_index = videocursor.getColumnIndexOrThrow(MediaStore.Video.Media.DISPLAY_NAME);
videocursor.moveToPosition(position);
id = videocursor.getString(video_column_index);
video_column_index = videocursor.getColumnIndexOrThrow(MediaStore.Video.Media.SIZE);
videocursor.moveToPosition(position);
id += " Size(KB):" + videocursor.getString(video_column_index);
cb.setText(id);
} else
view = convertView;
return view;
}