【发布时间】:2013-04-11 12:34:49
【问题描述】:
我用单选按钮创建了一个列表视图。列表视图如下图所示:
而我的 getView 是:
public View getView(final int position, View convertView, ViewGroup parent) {
ViewHolder holder = null;
PaymentData rowItem = getItem(position);
LayoutInflater mInflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if (convertView == null) {
convertView = mInflater.inflate(
com.android.paypal.homeactivity.R.layout.list_item, null);
holder = new ViewHolder();
holder.radioBtn = (RadioButton) convertView
.findViewById(com.android.paypal.homeactivity.R.id.rdb_payment_method);
holder.btPaymentMethod = (Button) convertView
.findViewById(com.android.paypal.homeactivity.R.id.bt_item_event);
convertView.setTag(holder);
} else
holder = (ViewHolder) convertView.getTag();
holder.radioBtn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if ((position != mSelectedPosition) && (mSelectedRB != null)) {
mSelectedRB.setChecked(false);
}
mSelectedPosition = position;
mSelectedRB = (RadioButton) v;
}
});
if (mSelectedPosition != position) {
holder.radioBtn.setChecked(false);
} else {
holder.radioBtn.setChecked(true);
if (mSelectedRB != null && holder.radioBtn != mSelectedRB) {
mSelectedRB = holder.radioBtn;
}
}
holder.radioBtn.setText(rowItem.getRdbText());
holder.btPaymentMethod.setText(rowItem.getBtText());
return convertView;
}
我想在屏幕第一个出现时自动检查最后一个单选按钮。我怎样才能做到这一点。
【问题讨论】:
-
您的意思是列表中的最后一个单选按钮?
-
是的。请帮帮我,我想要这个尽快。
-
最后位置与上一个可见位置不同,请明确 this..last position 或 lastVisible 位置
标签: android listview radio-button