我試圖找到一個解決我的問題,有1級的職位,有同樣的問題,但wasnt沒有回答(here)顯示在alertdialog後面的keybord,我如何將它關注於edittextview對話框?
我已經創建了一個alertDialog與它的editTextView。 當我打電話給對話框時,keybord不會顯示。 我發現了一些顯示鍵盤的代碼,但只在alertDialog後面顯示。
我的代碼:(我都談到了一些我的嘗試)
package com.moyoweb.winescanner.dialogs;
import java.util.Calendar;
import com.moyoweb.winescanner.JSONParser;
import com.moyoweb.winescanner.R;
import com.moyoweb.winescanner.User;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.View;
import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.EditText;
public class AddReviewDialog extends AlertDialog{
private Context context;
public AddReviewDialog(Context context) {
super(context);
this.setCanceledOnTouchOutside(true);
this.context=context;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.setContentView(R.layout.dialog_add_review);
getWindow().setBackgroundDrawableResource(R.color.not_transparent);
final EditText etAddReview = (EditText)this.findViewById(R.id.dialog_add_review_edittext);
// InputMethodManager imm =
// (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
//// imm.toggleSoftInput(InputMethodManager.SHOW_FORCED,0);
// etAddReview.requestFocus();
//
// etAddReview.setFocusable(true);
// etAddReview.requestFocus();
// InputMethodManager mgr = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
// mgr.hideSoftInputFromWindow(etAddReview.getWindowToken(), 0);
etAddReview.requestFocus();
etAddReview.postDelayed(new Runnable() {
@Override
public void run() {
InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED,0);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM, WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
imm.showSoftInput(etAddReview, InputMethodManager.SHOW_FORCED);
}
},500);
// InputMethodManager imm = (InputMethodManager)
// context.getSystemService(Context.INPUT_METHOD_SERVICE);
// // For SHOW_FORCED
// imm.showSoftInput (etAddReview, InputMethodManager.SHOW_FORCED);
// setOnShowListener(new OnShowListener() {
// @Override
// public void onShow(DialogInterface arg0) {
// // TODO Auto-generated method stub
// InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
// imm.toggleSoftInput(InputMethodManager.SHOW_FORCED,0);
// getWindow().setFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM, WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
// }
// });
Button btnSubmitReview = (Button)this.findViewById(R.id.dialog_btn_add_review);
this.setTitle("Adding a review");
final User us= new User();
btnSubmitReview.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
JSONParser.getInstance().addReviewWineToJSON(Calendar.getInstance().getTimeInMillis(),us.getUserID(), etAddReview.getText().toString());
dismiss();
}
});
}
}
http://stackoverflow.com/questions/5622202/how-to-resize-alertdialog-on-the-keyboard-display –
抱歉,但我coudnt從該鏈接獲得任何幫助,以幫助我,thx試圖幫助。 – cc2k