我有一个从 BaseAdapter 获取数据的 ListView。我在列表视图中有一个切换按钮,可以切换显示/隐藏字段。
当我单击列表视图中某一行的切换按钮时,我只想更新该特定行。
这是我正在尝试的代码。
请帮我。任何帮助,将不胜感激。
公共类 BankListAdapter 扩展 BaseAdapter {
private BankClass context;
private ArrayList<BankDetail> bank;
private LayoutInflater l_inflator;
private ViewHolder holder;
public BankListAdapter(BankClass context, ArrayList<BankDetail> bank) {
this.context = context;
this.bank = bank;
l_inflator = LayoutInflater.from(context);
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return bank.size();
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return bank.get(position);
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
Log.d("Method", "In getView");
if (convertView == null) {
convertView = l_inflator
.inflate(R.layout.layout_banklistview, null);
holder = new ViewHolder();
holder.bank_name = (TextView) convertView
.findViewById(R.id.TV_bankNameLabelValue);
holder.branch_name = (TextView) convertView
.findViewById(R.id.TV_branchNameLabelValue);
holder.atm_pin = (TextView) convertView
.findViewById(R.id.TV_atmPinLabelValue);
holder.acc_no = (TextView) convertView
.findViewById(R.id.TV_accNoLabelValue);
holder.card_no = (TextView) convertView
.findViewById(R.id.TV_atmCardNoLabelValue);
holder.tgl_atm_pin = (ToggleButton) convertView
.findViewById(R.id.Tgl_atmPin);
convertView.setTag(holder);
holder.tgl_atm_pin.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
BankDetail bd = bank.get((Integer) v.getTag());
String tempPin = bd.getAtmPin();
Log.d("Checked", bd.getAtmPin());
// TODO Auto-generated method stub
if (holder.tgl_atm_pin.isChecked()) {
// holder.atm_pin.setText(bd.getAtmPin());
// holder.atm_pin.setTransformationMethod(PasswordTransformationMethod);
holder.atm_pin.setInputType(InputType.TYPE_CLASS_TEXT
| InputType.TYPE_TEXT_VARIATION_PASSWORD);
} else {
// holder.atm_pin.setText(tempPin);
holder.atm_pin.setInputType(InputType.TYPE_CLASS_TEXT);
notifyData();
}
}
});
}
else {
holder = (ViewHolder) convertView.getTag();
}
// TODO Auto-generated method stub
holder.bank_name.setText(bank.get(position).getBankName());
holder.branch_name.setText(bank.get(position).getBranchName());
holder.atm_pin.setText(bank.get(position).getAtmPin());
if (holder.tgl_atm_pin.isChecked()) {
holder.atm_pin.setInputType(InputType.TYPE_CLASS_TEXT
| InputType.TYPE_TEXT_VARIATION_PASSWORD);
} else {
holder.atm_pin.setInputType(InputType.TYPE_CLASS_TEXT);
}
holder.acc_no.setText(bank.get(position).getAccNo());
holder.card_no.setText(bank.get(position).getAtmCardNo());
holder.tgl_atm_pin.setTag(position);
// Log.d("Position", "'"+position+"'");
// holder.tgl_atm_pin
// .setOnCheckedChangeListener(new
// CompoundButton.OnCheckedChangeListener() {
//
// @Override
// public void onCheckedChanged(CompoundButton buttonView,
// boolean isChecked) {
// // TODO Auto-generated method stub
// if (isChecked) {
// holder.atm_pin
// .setInputType(InputType.TYPE_CLASS_TEXT
// | InputType.TYPE_TEXT_VARIATION_PASSWORD);
//
//
// } else {
// holder.atm_pin
// .setInputType(InputType.TYPE_CLASS_TEXT);
//
// }
//
// }
// });
return convertView;
}
protected void notifyData() {
context.setBankDetails();
context.adapter = new BankListAdapter(context, context.bank_info);
context.adapter.notifyDataSetChanged();
context.list.setAdapter(context.adapter);
}
static class ViewHolder {
TextView bank_name;
TextView branch_name;
TextView atm_pin;
TextView acc_no;
TextView card_no;
ToggleButton tgl_atm_pin;
}
}
提前致谢