我将解释我在alertBox中所做的事情。我为其名称为alertBox的视图提供了一个视图。在该视图中,LinearLayout的名称是'main layout',我为另一个包含radioGroups和editTexts的视图充气。它的名字是布局。我将第二个视图(布局)添加到第一个视图(视图)。当我点击radioButtons它正常工作。但是当我点击editText时,它不会打开softKeyboard -
我打开一个为视图充气的alertBox。但是当我点击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 :(得分: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就像它必须一样。
我希望它有效
答案 1 :(得分: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();