Displaying soft keyboard from EditText in a custom dialog causes UI to temporarily stop responding
I have a problem in my application. When I click the EditText 开发者_Python百科in my custom dialog, the soft keyboard appears, but after it is displayed / hide, the UI is unresponsive for 2-3 seconds. If I wait until after 2-3 seconds, it runs smoothly.
Why would the keyboard cause my app to run slowly?
//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>
Thank you.
精彩评论