1

I know this question have one million answers but nothing works for my case. I have a custom dialog that contains ListView, and custom elements TextView and 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:

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:

    <EditText>
    <requestFocus />
</EditText>  

programaticaly:

  edittext.requestFocus();

force SoftKeyboard to appear:

 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...

ps original solutions src

Community
  • 1
  • 1
Vasile Doe
  • 1,674
  • 1
  • 24
  • 40

1 Answers1

0

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);
George Thomas
  • 4,566
  • 5
  • 30
  • 65