Доступ к просмотру текста на другом макете - PullRequest
1 голос
/ 06 марта 2012

Я сделал всплывающее окно, которое отлично работает, но я хотел бы написать в TextView на нем.Использование стандартного метода не работает (просто вылетает), несмотря на то, что Eclipse находит идентификатор TextView и не показывает никаких проблем.Всплывающее окно находится в другом макете XML.

Создает всплывающее окно

    public PopupWindow pw;

public void popUpShow() {
    LayoutInflater inflater = (LayoutInflater)
           this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    pw = new PopupWindow(
           inflater.inflate(R.layout.popup, null, false), 
           400, 
           600, 
           true);
            pw.showAtLocation(this.findViewById(R.id.main), Gravity.CENTER, 0, 0);
}

Макет

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/popup_layout"
android:orientation="vertical"
android:padding="10dp"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#AAA"
>

<TextView
    android:id="@+id/popupOut"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="10dp"
    android:text=""
/>

<Button
    android:id="@+id/popupclose"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/close"
    android:onClick="popUpHide" />

</LinearLayout>

Ответы [ 2 ]

1 голос
/ 06 марта 2012

Перед созданием вашего PopupWindow, сохраните ссылку на представление Inflated

ViewGroup v = (ViewGroup)inflater.inflate(R.layout.popup, null, false);

pw = new PopupWindow(
       v, 
       400, 
       600, 
       true);
        pw.showAtLocation(this.findViewById(R.id.main), Gravity.CENTER, 0, 0);

TextView view = (TextView)v.findViewById(R.id.textView1);
0 голосов
/ 06 марта 2012

Если textView находится в диалоговом окне, тогда идентификатор представления должен быть получен с помощью

Dialog dialog = new Dialog(this);
TextView view = (TextView)dialog.findViewById(R.id.textView1);

Попробуйте

 public void popUpShow() {
    LayoutInflater inflater = (LayoutInflater)
           this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    LinearLayout t = (LinearLayout) inflater.inflate(R.layout.item1, null, false);
    PopupWindow pw = new PopupWindow(
           t, 
           400, 
           600, 
           true);

    pw.showAtLocation(t.findViewById(R.id.main), Gravity.CENTER, 0, 0);
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...