[英]soft keyboard doesn't appear on ListView element (EditBox)
I know this question have one million answers but nothing works for my case. 我知道这个问题有100万个答案,但对我的情况无济于事。 I have a custom dialog that contains ListView
, and custom elements TextView
and EditText
. 我有一个自定义对话框,其中包含ListView
以及自定义元素TextView
和EditText
。
public static void createDialog(Context context, Activity activity) {
AlertDialog.Builder alertDialog = new AlertDialog.Builder(context);
LayoutInflater inflater = activity.getLayoutInflater();
View convertView = inflater.inflate(R.layout.custom_simple_dialog_layout, null);
alertDialog.setView(convertView);
final ListView listView = (ListView) convertView.findViewById(R.id.dialog_listView);
//myCustomObjList - contains strings for TextView and strings for EditTet hint
ListAdapter adapter = new DialogListAdapter(context, myCustomObjList);
listView.setAdapter(adapter);
AlertDialog myAlert = alertDialog.create();
myAlert.setCancelable(false);
myAlert.show();
}
I use BaseAdapter: 我使用BaseAdapter:
public class DialogListAdapter extends BaseAdapter {
private Context context;
private static List<MyObj> myCustomObjList = null;
private static LayoutInflater inflater = null;
public DialogListAdapter(Context context, List<MyObj> myCustomObjList) {
this.context = context;
this.myCustomObjList = myCustomObjList;
inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
@Override
public int getCount() {
return myCustomObjList.size();
}
@Override
public Object getItem(int position) {
return myCustomObjList.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View view, ViewGroup parent) {
if (view == null)
view = inflater.inflate(R.layout.custom_dialog_element, null);
TextView titleTxt = (TextView) view.findViewById(R.id.dialog_element_title);
titleTxt.setText(myCustomObjList.getTxtx());
EditText elementEditTxt = (EditText) view.findViewById(R.id.dialog_edit);
elementEditTxt.setHint(myCustomObjList.getTxtHint());
return view;
}}
I was trying: 我正在尝试:
set in xml: 在xml中设置:
<EditText>
<requestFocus />
</EditText>
programaticaly: programaticaly:
edittext.requestFocus();
force SoftKeyboard to appear: 强制出现SoftKeyboard:
InputMethodManager mImm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
mImm.showSoftInput(SearchEdit, InputMethodManager.SHOW_IMPLICIT);
even 甚至
edittext.setFocusable(true);
edittext.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if (hasFocus)
mImm.showSoftInput(SearchEdit, InputMethodManager.SHOW_IMPLICIT);
else
mImm.hideSoftInputFromWindow(edittext.getWindowToken(), 0);
}
});
I suppose that problem is somewhere else... 我想这个问题在别的地方...
Dunno whether it works or not anyway try this 邓诺无论是否可行尝试
in you code change like this and give a try 在你这样的代码更改,并尝试
AlertDialog myAlert = alertDialog.create();
myAlert.getWindow().setSoftInputMode (WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.