我有一个ImageButton plus。点击后我需要对视图进行充气。
我的问题是,当我使用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();
}
}
有人有任何想法吗?
答案 0 :(得分:0)
仔细检查您呼叫addPhone.performClick();
的部分代码。可能是那部分被调用了两次。
答案 1 :(得分:0)
有点迟了,但系统会在单击按钮时自行调用performClick(),因此您不应在代码中使用它。