下面是我通过堆栈溢出浏览的代码,并为我的弹出对话框编写了下面的代码,其中包含2个EditText,我需要在提示时弹出我的SoftKeypad,当我触摸edittext时它会弹出键盘但是键盘在我的警告框后面。
所以我尝试在alert.show()下面强制使用键盘弹出,但它在背景中并且警报在它上面。
请提供解决方案
代码:
for (int k = 0; k < mCompetitorMainList.getChildCount(); k++)
{
LinearLayout layout = (LinearLayout) mCompetitorMainList.getChildAt(k);
Button btn = (Button) layout.getChildAt(0);
String tag = (String) btn.getTag();
LinearLayout dataDetail = (LinearLayout) layout.getChildAt(2);
if (tag.equalsIgnoreCase("yes") && btn.getText().toString().equals("OTHERS"))
{
final AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(getContext());
LayoutInflater inflater = getActivity().getLayoutInflater();
final View dialogView = inflater.inflate(R.layout.alert_other_competitor_item_detail, null);
ImageView addImg =(ImageView)dialogView.findViewById(R.id.addCompetitorImg);
ImageView removeImg = (ImageView)dialogView.findViewById(R.id.removeCompetitorImg);
final LinearLayout competitorOtherLayout = (LinearLayout)dialogView.findViewById(R.id.competitorLayout);
addImg.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
LayoutInflater inflaterLayout = getActivity().getLayoutInflater();
View dialogViewLayout = inflaterLayout.inflate(R.layout.add_other_item_layout, null);
EditText otherCompDesc = (EditText) dialogViewLayout.findViewById(R.id.otherCompetitorDescription);
EditText otherCompQty = (EditText) dialogViewLayout.findViewById(R.id.otherCompetitorQty);
otherCompDesc.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if (hasFocus) {
InputMethodManager imm = (InputMethodManager)getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
}
}
});
otherCompQty.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if (hasFocus) {
InputMethodManager imm = (InputMethodManager)getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
}
}
});
competitorOtherLayout.addView(dialogViewLayout);
}
});
removeImg.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(competitorOtherLayout.getChildCount()!=0)
{
competitorOtherLayout.removeViewAt(competitorOtherLayout.getChildCount()-1);
}
else
{
Toast.makeText(getActivity(),"No Other Competitor Present ",Toast.LENGTH_LONG).show();
}
}
});
dialogBuilder.setView(dialogView);
alertDialogOther = dialogBuilder.create();
alertDialogOther.getWindow().setFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM, WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
alertDialogOther.show();
//alertDialogOther.setCancelable(false);
Toast.makeText(getActivity(), "Others Clicked", Toast.LENGTH_SHORT).show();
btn.setTag("no");
}
else if (tag.equalsIgnoreCase("yes"))
{
dataDetail.setVisibility(View.VISIBLE);
btn.setTag("no");
}
else
{
dataDetail.setVisibility(View.GONE);
}
}
SCREENSHOT:
答案 0 :(得分:1)
private void openKeyboard(){
InputMethodManager inputMethodManager =
(InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
inputMethodManager.toggleSoftInput(InputMethodManager.SHOW_FORCED,0);
}
请改用..