1

我将解释我在alertBox中完成的操作i为alertBox充气视图,其名称为view。在那个视图中,LinearLayout的名字是'main layout',我膨胀了包含radioGroups和editTexts的另一个视图。它的名字是布局。我将第二个视图(布局)添加到第一个视图(视图)。当我点击收音机按钮正常工作。但是当我点击编辑文本它不会打开softkeyboard -无法打开editText上的键盘

我打开一个警告框,充气视图。但是当我点击alertBox中的EditText时,它不显示软键盘。

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

但是当我点击的EditText(etEndsOn)它不会弹出键盘

+0

粘贴您的清单 – Aamirkhan 2013-04-24 09:31:44

回答

2

你必须给分众的布局。我也面临这个问题。使用下面的代码。希望这可以工作。

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

UPDATE

LinearLayout mainLayout= (LinearLayout)view.findViewById(R.id.main_Layout); 
    mainLayout.setFocusableInTouchMode(true); 
    mainLayout.requestFocus(); 
+0

确定我将检查 – Vikky 2013-04-24 08:58:09

+0

没有它不工作.. 我会解释我在做alertBox 我充气的alertBox它的名字是图的图。 ,并在该视图中LinearLayout的名称是'主布局' 我膨胀另一个视图,其中包含radioGroups和editTexts。 它的名字是布局。我将第二个视图(布局)添加到第一个视图(视图)。当我点击收音机按钮正常工作。但是当我点击editText时,它不会打开软键盘 – Vikky 2013-04-24 09:06:16

+0

Ohk。试着穿上mainLayout。我更新答案。请检查。 – 2013-04-24 09:20:56

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就像它必须是的。

我希望工程