如何获取/识别视图层次结构中的唯一 ID。下面是我的代码片段 fot 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();
}
}
}
});
现在单击下图中的“保存”按钮,当我获取文本时,它始终会获取底行值,因为所有视图都具有相同的 ID。请帮我。