I have my app in which I touch a button and displays a popup window. Inside it is the following layout:
popupip.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:layout_marginTop="15dp"
android:orientation="vertical"
>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:background="@drawable/popup_border" >
>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_margin="10dp" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Dirección IP: " />
<TextView
android:id="@+id/ip"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="@string/dir_ip" />
</LinearLayout>
<EditText
android:id="@+id/new_ip"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
android:background="@android:color/white"
android:text="@string/nuevaip" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<Button
android:id="@+id/guardar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="25dp"
android:text="Guardar"
android:onClick="guardarip" />
<Button
android:id="@+id/salir"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Salir" />
</LinearLayout>
</LinearLayout>
Button salir
is the dismiss button. Also I want to write some text in the textedit view, so when i touch guardar
button it stores it in a string and put it in textview ip
.
I also have the following code for the popup:
Activity_main.java
@Override
protected void onCreate(Bundle savedInstanceState) {
final Button botonip = (Button)findViewById(R.id.btn_ip);
botonip.setOnClickListener(new Button.OnClickListener(){
@Override
public void onClick(View arg0) {
LayoutInflater layoutInflater
= (LayoutInflater)getBaseContext()
.getSystemService(LAYOUT_INFLATER_SERVICE);
View popupView = layoutInflater.inflate(R.layout.popupip, null);
final PopupWindow popupWindow = new PopupWindow(
popupView,
LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT);
Button btnDismiss = (Button)popupView.findViewById(R.id.salir);
btnDismiss.setOnClickListener(new Button.OnClickListener(){
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
popupWindow.dismiss();
}});
popupWindow.showAsDropDown(botonip, 50, -30);
}});
}
my question is if can use more than one popupView.finViewById for the other elements in the popup or how can I handle the button, textView and TextEdit?
Yes, you may use popupView.findViewById() as many times as you would like, just like you can use findViewById() multiple times in an activity.