2012-03-06 4 views
1

Я сделал всплывающее окно, которое отлично работает, но я хотел бы написать 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); 
} 

Layout

<?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> 
+0

пожалуйста, вы можете добавить код .. – user936414

ответ

1

Перед создания PopupWindow, сохранить ссылку на мнение надутого

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

Именно то, что я искал. Благодарю. – Rhyono

0

Если 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); 
} 
+0

я не использовал диалог. – Rhyono

Смежные вопросы