1

I will explain what i done in my alertBox i Inflate a View for the alertBox its name is view. and in that view a LinearLayout is there its name is 'main layout' i inflate another view which contains a radioGroups and editTexts. its name is layout. i add the 2nd view(layout) to the first view (view). and when i click on the radioButtons its work properly. but when i click on the editText it doesn't open the softKeyboard –</p>

i open an alertBox which inflate a view. but it doesn't show a the soft keyboard when i click on the EditText in the alertBox.

Builder alertCreate = new AlertDialog.Builder(parent);
        alertCreate.setTitle("New Schedule");
        inflater = LayoutInflater.from(parent);
        View view = inflater.inflate(R.layout.activity_schedule, null);     
        spinnerRepeat = (Spinner)view.findViewById(R.id.spinner_schedule_repeat);

spinnerRepeat.setOnItemSelectedListener(new OnItemSelectedListener() {

            public void onItemSelected(AdapterView<?> arg0, View arg1,
                    int arg2, long arg3) {
                LinearLayout mainLayout= (LinearLayout)view.findViewById(R.id.main_Layout);
                LinearLayout spinnerLayout = (LinearLayout)view.findViewById(R.id.spinner_Layout);
                View weeklyLayout = inflater.inflate(R.layout.schedule_week_selection, null);
                initializeWeeks(weeklyLayout);
                if(arg2>0)
                {
                    if(flag==0)
                    {
                        View layout = inflater.inflate(R.layout.schedule_ends_on, null);
                        RelativeLayout layout2 =(RelativeLayout)layout.findViewById(R.id.endsOn_layout);    
                        rgEndsOn =(RadioGroup)layout.findViewById(R.id.radioGroup_endsOn);
                        radio_occr=(RadioButton)layout.findViewById(R.id.radio_schedule_occr);
                        radio_date=(RadioButton)layout.findViewById(R.id.radio_schedule_date);
                        occurence=(TextView)layout.findViewById(R.id.tv_schedule_Occur);
                        addCheckListenerToRgEndsOn();
                        etEndsOn=(EditText)layout.findViewById(R.id.Et_schedule_occur);
                        etEndDate=(EditText)layout.findViewById(R.id.et_schedule_enddate);
                        etEndDate.setClickable(true);
                        etEndDate.setText(formatDate(TimeFormater.DateToString(startDate)));
                        mainLayout.addView(layout, 3);
                        flag=1;
                    }
                    if(arg2==2)
                    {
                        spinnerLayout.addView(weeklyLayout,2);
                    }
                    else
                    {
                        View v = (View)spinnerLayout.getChildAt(2);
                        spinnerLayout.removeView(v);
                    }
                }
                else
                {
                    Log.e("id",""+mainLayout.getChildAt(3));
                    View v = (View)mainLayout.getChildAt(3);
                    View v2 = (View)spinnerLayout.getChildAt(2);
                    spinnerLayout.removeView(v2);
                    mainLayout.removeView(v);
                    flag=0;
                }
            }

but when i click on the EditText (etEndsOn) it doesn't pop up the keyboard

4

2 回答 2

3

我遇到了和你一样的问题......并尝试设置一些参数(以编程方式和在 xml 中),但它似乎不起作用。

但是我已经实施了一个解决方案,它对我有用:

在 onCreate 方法中,我将参数填充到了 edittext(只是宽度和高度)并调用了一个方法来显示 AlertDialog:

    EditText input = new EditText(this);
    LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
            LinearLayout.LayoutParams.FILL_PARENT,
            LinearLayout.LayoutParams.FILL_PARENT);
    input.setLayoutParams(lp);

    createInputDialog(this, this, this, input);

继承人 createInputDialog 方法:

public void createInputDialog(final Activity ga,
        DialogInterface.OnClickListener listener,
        DialogInterface.OnKeyListener keylistener, EditText input) {

    AlertDialog.Builder editalert = new AlertDialog.Builder(ga);
    editalert
            .setTitle(
                    getResources().getString(R.string.input_dialog_title))
            .setMessage(
                    getResources().getString(
                            R.string.input_dialog_description))
            .setView(input)
            .setPositiveButton(
                    getResources().getString(R.string.dialog_save_button),
                    listener)
            .setNegativeButton(
                    getResources().getString(R.string.button_cancel),
                    listener).setOnKeyListener(keylistener);

    if (alert_input == null) {
        alert_input = editalert.create();
    }

}

然后我只需要在我想要的时候显示警报,edittext 就像它必须的那样工作。

我希望它有效

于 2013-05-07T16:13:11.673 回答
2

您必须为布局提供焦点。我也面临这个问题。使用以下代码。希望这有效。

 RelativeLayout layout2 =(RelativeLayout)layout.findViewById(R.id.endsOn_layout);
layout2.setFocusableInTouchMode(true);
layout2.requestFocus();

更新

 LinearLayout mainLayout= (LinearLayout)view.findViewById(R.id.main_Layout);
    mainLayout.setFocusableInTouchMode(true);
    mainLayout.requestFocus();
于 2013-04-24T08:49:54.193 回答