У меня проблема всплывающего окна. Я не могу набирать всплывающее окно EditText. Когда я нажимаю TextView, я хочу открыть всплывающее окно и набрать EditText, нажав кнопку «Сохранить», чтобы иметь содержимое TextView. EdittextКак открыть клавиатуру на всплывающем окне Edittext Android
Класс всплывающих окон открыт!
private TextView name;
private PopupWindow popupWindow=null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
name=(TextView)findViewById(R.id.name);
name.setOnClickListener(new OnClickListener()
{ @Override
public void onClick(View arg0) {
if(popupWindow!=null)
{
popupWindow.dismiss();
popupWindow=null;
}
openpopup();
}
});
}
Функция открыта Всплывающее
private void openpopup()
{
LayoutInflater layoutInflater= getLayoutInflater();
View popupView = layoutInflater.inflate(R.layout.edittext, null);
popupWindow = new PopupWindow(popupView,LayoutParams.MATCH_PARENT,LayoutParams.WRAP_CONTENT);
Button btnsave = (Button)popupView.findViewById(R.id.save);
Button btncancel =(Button)popupView.findViewById(R.id.cancel);
final EditText text=(EditText)popupView.findViewById(R.id.name);
btnsave.setOnClickListener(new Button.OnClickListener(){
@Override
public void onClick(View v) {
popupWindow.dismiss();
popupWindow=null;
if(text.getText()==null)
{
name.setText(text.getText().toString());
}
}});
btncancel.setOnClickListener(new Button.OnClickListener(){
@Override
public void onClick(View v) {
popupWindow.dismiss();
popupWindow=null;
}});
popupWindow.showAsDropDown(name, 0, 0);
}
activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<TextView
android:id="@+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerInParent="true"
android:text="@string/name" />
</RelativeLayout>
edittext.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<EditText
android:id="@+id/name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="text" >
<requestFocus />
</EditText>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<Button
android:id="@+id/save"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@+string/save"/>
<Button
android:id="@+id/cancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@+string/cancel"/>
</LinearLayout>
</LinearLayout>
Как открыть клавиатуру, и вы можете ввести всплывающую EditText?
Спасибо за ответ. Эта проблема была решена этим порядком 'popupWindow.setFocusable (true);'. Но что я могу сделать, если я хочу, чтобы клавиатура «adjustResize» и в то же время появилась всплывающая подсказка ??? –