i have a listview
of all install app.i am using custom adobter now issue is this i want to save checkbox state when i check checkbox its state save in sharedprefrences and again when app restart and i open the listview checkbox state auto check which i save.how to made this please help me. here is my code
public class Listadapter extends BaseAdapter {
private Context mContext;
private List<ApplicationInfo> mListAppInfo;
private PackageManager mPackManager;
private ArrayList<Boolean> checkList = new ArrayList<Boolean>();
CheckBox checkBox;
boolean index[];
boolean[] itemChecked;
public Listadapter(Context applicationContext, List<ApplicationInfo> installedApplication, PackageManager packageManager) {
//super(applicationContext,textViewResourceId,installedApplication);
super();
this.mContext = applicationContext;
this.mListAppInfo = installedApplication;
index = new boolean[installedApplication.size()];
this.mPackManager = packageManager;
for (int i = 0; i < installedApplication.size(); i++) {
checkList.add(false);
itemChecked = new boolean[installedApplication.size()];
}
}
private class ViewHolder {
ImageView ivAppIcon;
TextView tvAppName;
TextView tvPkgName;
CheckBox checkBox;
}
@Override
public int getCount() {
return mListAppInfo.size();
//return ((null != mListAppInfo) ? mListAppInfo.size() : 0);
}
@Override
public Object getItem(int position) {
// index = new boolean[mListAppInfo.size()];
return mListAppInfo.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
// get the selected entry
final ViewHolder holder;
// LayoutInflater inflater = (LayoutInflater) mContext.getLayoutInflater();
LayoutInflater inflater = (LayoutInflater) mContext.getSystemService( Context.LAYOUT_INFLATER_SERVICE );
if (convertView == null) {
convertView = inflater.inflate(R.layout.list_item, null);
holder = new ViewHolder();
// reference to convertView
holder.tvAppName = (TextView) convertView
.findViewById(R.id.textView1);
holder.tvPkgName = (TextView) convertView
.findViewById(R.id.textView);
holder.checkBox = (CheckBox) convertView
.findViewById(R.id.checkBox1);
holder.ivAppIcon = (ImageView) convertView
.findViewById(R.id.imageView);
convertView.setTag(holder);
// holder.ck1.setTag(packageList.get(position));
}
else {
holder = (ViewHolder) convertView.getTag();
}
final ApplicationInfo entry = mListAppInfo.get(position);
holder.ivAppIcon.setImageDrawable(entry.loadIcon(mPackManager));
holder.tvAppName.setText(entry.loadLabel(mPackManager));
holder.tvPkgName.setText(entry.packageName);
holder.checkBox.setChecked(false);
holder.checkBox.setChecked(false);
if (itemChecked[position])
holder.checkBox.setChecked(true);
else
holder.checkBox.setChecked(false);
holder.checkBox.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if (holder.checkBox.isChecked())
itemChecked[position] = true;
else
itemChecked[position] = false;
}
});
return convertView;
}
}
please help me with some code thanks.
Aucun commentaire:
Enregistrer un commentaire