在自定义对话框中从EditText显示软键盘会导致UI暂时停止响应

时间:2011-01-26 11:50:10

标签: java android

我的申请表有问题。当我单击自定义对话框中的EditText时,会出现软键盘,但在显示/隐藏后,UI会无响应2-3秒。 如果我等到2-3秒后,它会顺利运行。

为什么键盘会导致我的应用程序运行缓慢?

//CustomDialog Class
pubilc CustomDialog extends Dialog implements OnClickListener{
    private Context context;
    private Activity activity;
    private Button button1, button2;
    private EditText editText

public CustomDialog(Context context, Activity activity){
    this.context = context;
    this.activity = activity;
    this.button1 = null;        
    this.button2 = null;        
    this.editText = null;        
}

public void onCreate(Bundle savedInstanceState){
    super.onCreate(savedInstanceState);
    this.requestWindowFeature(Window.FEATURE_NO_TITLE); 

    this.setContentView(R.layout.custom_dialog_layout);
    this.editText = (EditText)findViewById(R.id.custom_edittext);               
    button1 = (Button)findViewById(R.id.confirm_button);
    button1.setOnClickListener(this);
    button2 = (Button)findViewById(R.id.cancel_button);
    button2.setOnClickListener(this);
}

public void onClick(View view){
    if(view == this.confirmButton){
        activity.doSomething();
    }else if(view == this.cancelButton){
        this.dismiss();
    }
}

}



//Main Activity
public Main extends Dialog implements OnClickListener{
    private Button button;
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.requestWindowFeature(Window.FEATURE_NO_TITLE); 
        setContentView(R.layout.main); 

        this.bindResources();
    }

    private void bindResources(){
        this.button = (Button)this.findViewById(R.id.main_button);
        this.button.setOnClickListener(this);
    }

    public void onClick(View view){
        if(view == this.button){
            CustomDialog dialog = new CustomDialog(this, this);
            dialog.show();
        }
    }
}

//CustomDialog XML

<TextView   android:id="@+id/custom_message"
        android:layout_width="wrap_content"  
        android:layout_height="wrap_content" 
        android:textStyle="bold"
        android:layout_centerHorizontal="true"
        android:text="@string/custom_message"
        android:textSize="20px"
        android:paddingTop="5px"
        android:textColor="#FFFFFF"/> 

<EditText   android:id="@+id/custom_edittext"
                android:layout_height="wrap_content"
                android:layout_marginTop="10px"
                android:layout_width="250px"
                android:layout_centerHorizontal="true"
                android:layout_below="@id/custom_message"
                android:digits="0123456789."
                android:inputType="phone"
                android:singleLine="true"
                android:maxLength="20"/>                

<RelativeLayout android:id="@+id/button_group"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:gravity="center_horizontal"
        android:layout_marginTop="5px"
        android:layout_below="@id/custom_edittext">

   <Button  android:id="@+id/confirm_button"
                android:text="@string/confirm_button_label"
                android:layout_width="100px"
                android:textSize="15px"
                android:textColor="#000000"
                android:textStyle="bold"
                android:layout_height="wrap_content"/>          

    <Button     android:id="@+id/cancel_button"
                android:text="@string/cancel_button_label"
                android:layout_width="100px"
                android:textSize="15px"
                android:textColor="#000000"
                android:textStyle="bold"
                android:layout_toRightOf="@id/confirm_button"
                android:layout_height="wrap_content"/>
</RelativeLayout>                         

谢谢。

0 个答案:

没有答案