好的,我正在改写这个问题,
我有一个具有多个布局的自定义 BaseAdaptor,在选择列表行时选择复选框时遇到问题,
实际上它不适用于使用布局的第一行,其他的完全按照我想要的方式工作。
***编辑添加一些代码的时间:在我的主类中:
myAdaptor = new ListAdapter(this, myValues);
listview.setAdapter(myAdaptor);
Log.d("SettingsScreen", "Setup listview click");
listview.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> l, View v, int pos, long arg3) {
if (pos == 1) {
myAdaptor.displayNeedle.setChecked(!myAdaptor.displayNeedle
.isChecked());
} else if (pos == 2) {
accent1st.setChecked(!accent1st.isChecked());
} else if (pos == 3) {
myAdaptor.wakeLock.setChecked(!myAdaptor.wakeLock
.isChecked());
} else if (pos == 4) {
tapTimeSig.setChecked(!tapTimeSig.isChecked());
}
}
});
}
我的自定义适配器:
@Override
public View getView(int position, View convertView, ViewGroup parent) {
int type = layoutType[position];
holder = null;
holder = new ViewHolder();
if (convertView == null) {
holder = new ViewHolder();
switch (type) {
case 0:
convertView = mInflater.inflate(R.layout.tickbox, null);
holder.textView = (TextView) convertView
.findViewById(R.id.label);
if (position == 1) {
displayNeedle = (CheckBox) convertView
.findViewById(R.id.mycheckbox);
displayNeedle
.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(
CompoundButton arg0, boolean arg1) {
getData().setDisplayNeedle(
!getData().getDisplayNeedle());
}
});
}
else if (position == 2) {
accent1st = (CheckBox) convertView
.findViewById(R.id.mycheckbox);
accent1st.setChecked(getData().getAccentBeat(0));
accent1st
.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(
CompoundButton arg0, boolean arg1) {
getData().setAccentBeat(0,
accent1st.isChecked());
}
});
}
if (position == 3) {
wakeLock = (CheckBox) convertView
.findViewById(R.id.mycheckbox);
wakeLock.setChecked(getData().getWakeLock());
if (!getData().getPro()) {
wakeLock.setEnabled(false);
values[3] += " (Pro version only)";
}
wakeLock.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton arg0,
boolean arg1) {
if (getData().getPro())
getData().setWakeLock(wakeLock.isChecked());
}
});
}
if (position == 4) {
tapTimeSig = (CheckBox) convertView
.findViewById(R.id.mycheckbox);
tapTimeSig.setChecked(getData().getTapTimeSig());
tapTimeSig
.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(
CompoundButton arg0, boolean arg1) {
getData().setTapTimeSig(
tapTimeSig.isChecked());
}
});
}
break;
感谢您到目前为止的支持,我已经坚持了太久了,例如几周!我真的很想让它正常运行。