我正在开发一个应用程序备份应用程序,我想制作它只备份我通过复选框选择的那些应用程序。我已经在列表中实现了复选框,但是当我在它之前和之后每第 9 行检查一行时,它也会被选中:S
PS。我也很感激有人可以帮助我了解如何制作,以便应用程序备份也可以工作:)
(这只是完整java文件的一部分)
private static class AppViewHolder {
TextView top_view;
TextView bottom_view;
ImageView icon;
CheckBox check_mark;
//@SuppressWarnings("unused")
}
private class TableView extends ArrayAdapter<ApplicationInfo> {
private TableView() {
super(main.this, R.layout.tablerow_02, mAppList);
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
AppViewHolder holder;
ApplicationInfo info = mAppList.get(position);
if(convertView == null) {
LayoutInflater inflater = getLayoutInflater();
convertView = inflater.inflate(R.layout.tablerow_02, parent, false);
holder = new AppViewHolder();
holder.top_view = (TextView)convertView.findViewById(R.id.top_view);
holder.bottom_view = (TextView)convertView.findViewById(R.id.bottom_view);
holder.check_mark = (CheckBox)convertView.findViewById(R.id.checkBox1);
holder.icon = (ImageView)convertView.findViewById(R.id.row_image);
holder.icon.setMaxHeight(40);
convertView.setTag(holder);
} else {
holder = (AppViewHolder) convertView.getTag();
}
holder.check_mark.setOnCheckedChangeListener(new OnCheckedChangeListener(){
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked)
{
if ( isChecked )
{
Toast.makeText(getApplicationContext(), "#" + position + " is checked", Toast.LENGTH_LONG).show();
}
else{
Toast.makeText(getApplicationContext(), "#" + position + " is unchecked", Toast.LENGTH_LONG).show();
}
}
});
holder.top_view.setText(info.loadLabel(getPackageManager()));
holder.bottom_view.setText(info.packageName);
//this should not throw the exception
try {
holder.icon.setImageDrawable(mPackMag.getApplicationIcon(info.packageName));
} catch (NameNotFoundException e) {
holder.icon.setImageResource(R.drawable.ic_launcher);
}
return convertView;
}
}