`我剛接觸android並構建一個列表,並且列表包含已安裝的應用程序名稱以及CheckBox以選擇要卸載的應用程序名稱。例如,問題是當列表變得比電話屏幕更長並且滾動被激活時;當我選擇一個複選框時,會在列表底部自動選擇第二個複選框。Android自定義列表視圖中的自動複選框選擇
問題是自動複選框選擇複選框,PLZ幫助我。
public View getView(final int position, View convertView, ViewGroup parent)
{
LayoutInflater inflater = context.getLayoutInflater();
if (convertView == null) {
convertView = inflater.inflate(R.layout.ultimate, null);
holder = new ViewHolder();
holder.apkName = (TextView) convertView.findViewById(R.id.appName);
holder.apkInstall=(TextView)convertView.findViewById(R.id.appMemory);
holder.cb=(CheckBox)convertView.findViewById(R.id.cb);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
PackageInfo packageInfo = (PackageInfo) getItem(position);
Drawable appIcon = packageManager.getApplicationIcon(packageInfo.applicationInfo);
String appName = packageManager.getApplicationLabel(packageInfo.applicationInfo).toString();
appIcon.setBounds(0, 0, 50, 50);
holder.apkName.setCompoundDrawables(appIcon, null, null, null);
holder.apkName.setCompoundDrawablePadding(15);
holder.apkName.setText(appName);
holder.cb.setTag(position);
請張貼一些代碼 – Nisarg
holder.cb.setChecked(sba.get(位置));你爲什麼這樣做? – Nisarg