ビュー階層で一意の 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();
}
}
}
});
下の画像の [保存] ボタンをクリックすると、すべてのビューが同じ ID を持つため、getText は常に一番下の行の値を取得します。私を助けてください。