如何获取/识别视图层次结构中的唯一ID。下面是我的代码片段FOT getChildView(...)在android中获取独特的ID在getchildView(...)的层次结构
public View getChildView(int groupPosition, final int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
final ExpandListChild child = (ExpandListChild) getChild(groupPosition, childPosition);
if (convertView == null)
{
LayoutInflater infalInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = infalInflater.inflate(R.layout.manage_insurance, null);
}
company = (EditText) convertView.findViewById(R.id.et_CompanyName);
interest = (EditText) convertView.findViewById(R.id.et_Interest);
duration = (EditText) convertView.findViewById(R.id.et_Duration);
btnSave = (Button) convertView.findViewById(R.id.btnSave);
btnDelete = (Button) convertView.findViewById(R.id.btnDelete);
company.setTag(R.id.string_key1, childPosition);
//interest.setTag(childPosition, childPosition);
//duration.setTag(childPosition, childPosition);
btnSave.setTag(R.id.string_key2, childPosition);
//btnDelete.setTag(childPosition, childPosition);
company.setText(child.getCompanyName().toString());
interest.setText(child.getInterest()+"");
duration.setText(child.getDuration()+"");
btnSave.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
int viewtag = (Integer) v.getTag(R.id.string_key2);
if (childPosition == viewtag){
durationValue = (duration.getText().toString().equals("") ? 0.0f : Float.parseFloat(duration.getText().toString()));
interestValue = (interest.getText().toString().equals("") ? 0.0f : Float.parseFloat(interest.getText().toString()));
Log.v("durationValue", "durationValue ======" + durationValue +"========"+ interestValue);
if (checkingForEmptyFields()){
int updatedRows = dbManager.updateInsurance(companyValue, durationValue, 15);
if (updatedRows > 0){
Toast.makeText(mContext, "Successfully updated", Toast.LENGTH_SHORT).show();
mContext.startActivity(new Intent(mContext, InsurancePanelInflator.class));
}
else
{
Toast.makeText(mContext, "Problem occured while updating", Toast.LENGTH_SHORT).show();
}
}
else
{
Toast.makeText(mContext, "Fill Mandatory Fields First", Toast.LENGTH_SHORT).show();
}
}
}
});
现在就点击下方图片保存按钮时,我的gettext它总是底行值的所有视图具有相同的ID。请帮帮我。
要重复使用相同的ID在每个条目,使用条目的ID来检索条目,然后调用findViewById该条目检索当前公司利益和持续时间。例如。一个列表视图包含所有视图内部具有相同标识的项目,这些项目通过使用项目本身的项目标识而不是内部视图的标识进行区分。 – Tobrun 2013-03-23 12:40:59
感谢您的评论。它不适合我:expandableRow =(LinearLayout)convertView.findViewById(R.id.lnrExpListRow); \t \t \t \t company =(EditText)expandableRow.findViewById(R.id.et_CompanyName); \t \t interest =(EditText)expandableRow.findViewById(R.id.et_Interest); \t \t duration =(EditText)expandableRow.findViewById(R.id.et_Duration); \t \t btnSave =(Button)expandableRow.findViewById(R.id.btnSave); \t \t btnDelete =(Button)expandableRow.findViewById(R.id.btnDelete); – sns 2013-03-23 15:52:08