我面临的情景如下:
我的对话框edittext的焦点对准我希望键盘出现在 对话框。
我在SO中经历了这么多答案。但没有工作
适配器类edittext onfocus中的代码
edittext.setOnFocusChangeListener(new OnFocusChangeListener() {
public void onFocusChange (View v,boolean hasFocus){
edittext.post(new Runnable() {
public void run() {
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
}
});
列表视图
LayoutInflater li = LayoutInflater.from(context);
View promptsView = li.inflate(R.layout.custom_dialog, null);
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setView(promptsView);
builder.setTitle(" Please select size");
listView = (ListView) promptsView.findViewById(R.id.listt);
dataAdapter = new MyCustomAdapter(context, R.layout.size_info,
sizePojoList, active);
listView.setAdapter(dataAdapter);
listView.setDescendantFocusability(ViewGroup.FOCUS_AFTER_DESCENDANTS);
listView.setItemsCanFocus(true);
答案 0 :(得分:0)
尝试:
dialog.getWindow().setSoftInputMode( WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);