软键盘没有出现在ListView元素(EditBox)上

时间:2015-12-10 14:52:35

标签: android listview android-softkeyboard

我知道这个问题有一百万个答案,但对我的情况没有任何作用。我有一个自定义对话框,其中包含ListView和自定义元素TextViewEditText

    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();
}

我使用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;
    }}

我在尝试:

在xml中设置:

    <EditText>
    <requestFocus />
</EditText>  

programaticaly:

  edittext.requestFocus();

强制SoftKeyboard出现:

 InputMethodManager mImm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);  
 mImm.showSoftInput(SearchEdit, InputMethodManager.SHOW_IMPLICIT); 

甚至

    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);  
   } 
});

我认为问题出在其他地方......

ps原始解决方案src

1 个答案:

答案 0 :(得分:0)

Dunno无论如何都可以尝试这个

在您的代码更改中,并尝试

 AlertDialog myAlert = alertDialog.create();
myAlert.getWindow().setSoftInputMode (WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);