我有一个 ImageButton 加。单击时,我需要对视图进行膨胀。
我的问题是,当我使用 performClick 时,Imagebutton 被调用了两次,并同时执行了两次充气。
我不明白为什么会这样。
这是我的一些代码:
private ImageButton addPhone;
addPhone = (ImageButton)view.findViewById(R.id.ac_ibAddClientPhone);
addPhone.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
inflationFields = new InflatationFields(getActivity());
inflationFields.inflateNewField("phone", containerPhone, view, adapterPhone);
}
});
在代码的另一部分我调用按钮并尝试单击执行单击
try{
if(ccPhone.moveToFirst())
do{
if(flag_first==true){
phone = ccPhone.getString(ccPhone.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
Log.d(ClientEditContact.class.getName(), "PHONE: " +phone);
type = ccPhone.getInt(ccPhone.getColumnIndex(ContactsContract.CommonDataKinds.Phone.TYPE));
etPhone = (EditText)viewPrincipal.findViewById(R.id.ac_etAddClientPhone);
etPhone.setText(phone + "" +etPhone.getTag().toString());
spPhone.setSelection(convertTypeToIdSpinner(type));
flag_first=false;
}
else if(flag_first == false){
addPhone.performClick();
phone = ccPhone.getString(ccPhone.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
type = ccPhone.getInt(ccPhone.getColumnIndex(ContactsContract.CommonDataKinds.Phone.TYPE));
etPhone = (EditText)viewContainerPhone.findViewWithTag("etTagPhone" + count);
etPhone.setText(phone + "" + etPhone.getTag().toString());
count = count + 1;
if(count==ccPhone.getCount()){
break;
}
}
}while(ccPhone.moveToNext());
Log.d(ClientEditContact.class.getName(), "LAST PHONE ---> " +phone);
}finally{
if(ccPhone != null && ! ccPhone.isClosed()){
ccPhone.close();
}
}
有人知道吗?