-1

I tried to find a solution to my problem, there was 1 post that had the same problem, but wasnt not answered(here)

i have created an alertDialog with an editTextView on it. When i call the dialog, the keybord wont show. I found some code that did show the keyboard, but only behind the alertDialog.

my code:(i have commented out some of my tries)

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();
            }
        });
    }   
}
Community
  • 1
  • 1
cc2k
  • 351
  • 1
  • 2
  • 12

1 Answers1

2

instead of alertdialog you can use an activity and in manifest set theme for your activity like this

android:theme="@android:style/Theme.Dialog"

the activity will look like dialog

Kaushik
  • 6,150
  • 5
  • 39
  • 54