Java 访问另一布局上的文本视图

Java 访问另一布局上的文本视图,java,android,android-layout,Java,Android,Android Layout,我已经做了一个弹出窗口,它工作得很好,但我想在上面写下文本视图。尽管Eclipse找到了TextView的id并且没有显示任何问题,但使用标准方法不起作用(只是使其崩溃)。弹出窗口位于另一个XML布局中 生成弹出窗口 public PopupWindow pw; public void popUpShow() { LayoutInflater inflater = (LayoutInflater) this.getSystemService(Context

我已经做了一个弹出窗口,它工作得很好,但我想在上面写下文本视图。尽管Eclipse找到了TextView的id并且没有显示任何问题,但使用标准方法不起作用(只是使其崩溃)。弹出窗口位于另一个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>

如果文本视图位于对话框中,则应通过

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


如果textView位于对话框中,则应通过

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


在创建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);

在创建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);

你能添加一些代码吗你能添加一些代码吗正是我想要的。谢谢,正是我想要的。谢谢