Android PopupWindow 和 SeekBar 监听器没有响应

Android PopupWindow and SeekBar listener not responding

有谁知道为什么我的搜索栏侦听器没有从搜索栏中获取任何数据??我已经完成所有设置和工作,但它没有更新文本视图,我认为它与使用不同 activity 布局的弹出窗口 window 有关,它位于

public class Environment extends Activity implements OnSeekBarChangeListener
{

private ImageButton lockButton;


SeekBar bar;
TextView textProgress, textAction;
private PopupWindow pwindo;


@Override
protected void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.setup_environment);

    lockButton = (ImageButton) findViewById(R.id.lock);
    lockButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            initiatePopupWindow();

        }
    });

}


private void initiatePopupWindow() {
    try {
        LayoutInflater inflater = (LayoutInflater) Environment.this
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View layout = inflater.inflate(R.layout.annotation,
                (ViewGroup) findViewById(R.id.popup_element));
        pwindo = new PopupWindow(layout, 1000, 1200, true);
        pwindo.showAtLocation(layout, Gravity.CENTER, 0, 0);

        bar = (SeekBar)findViewById(R.id.seekBar1); // make seekbar object
        bar.setOnSeekBarChangeListener(this);
        textProgress = (TextView)findViewById(R.id.textViewProgress);

        textAction = (TextView)findViewById(R.id.textViewAction);

    } catch (Exception e) {
        e.printStackTrace();
    }
}
@Override
public void onProgressChanged(SeekBar seekBar, int progress,
                              boolean fromUser) {
    // TODO Auto-generated method stub

    textProgress.setText("The value is: "+progress);

    textAction.setText("changing");
}

@Override
public void onStartTrackingTouch(SeekBar seekBar) {
    // TODO Auto-generated method stub
    textAction.setText("starting to track touch");

}

@Override
public void onStopTrackingTouch(SeekBar seekBar) {
    // TODO Auto-generated method stub
    seekBar.setSecondaryProgress(seekBar.getProgress());
    textAction.setText("ended tracking touch");
}

} 每当我使用滑块时,它应该根据滑块的位置更新为 0-100 的 int 值,如果我创建一个 activity 并立即使用它,它就会工作,但是当我把它放在弹出窗口中时 window 它什么也没做??

annotation.xml

<LinearLayout android:id="@+id/popup_element"
          xmlns:android="http://schemas.android.com/apk/res/android"
          android:layout_width="fill_parent"
          android:layout_height="fill_parent"
          android:background="#65bea9"
          android:orientation="vertical"
          android:padding="10sp">

<EditText
    android:layout_width="170dp"
    android:layout_height="250dp"
    android:id="@+id/editText2"
    android:layout_gravity="center_horizontal"
    android:background="#ffffff"
    android:textColor="#000000"
    android:hint="@string/hint_annotation"
    android:scrollIndicators="right"
    android:gravity="top"
    android:inputType="textMultiLine"
    android:textSize="8pt"/>

<TextView
    android:id="@+id/textViewProgress"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:text="progress displayed here"
    android:textAppearance="?android:attr/textAppearanceLarge"
    android:layout_gravity="center"
    android:textSize="6pt"></TextView>

<TextView
    android:id="@+id/textViewAction"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_below="@+id/textViewProgress"
    android:layout_marginTop="2dp"
    android:text="action displayed here"
    android:textAppearance="?android:attr/textAppearanceLarge"
    android:layout_gravity="center"
    android:textSize="6pt"></TextView>

<SeekBar
    android:id="@+id/seekBar1"
    android:layout_width="150dp"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_below="@+id/textView1"
    android:layout_marginTop="5dp"
    android:max="100"
    android:layout_gravity="center"></SeekBar>

<Button
    android:id="@+id/btn_close_popup"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:text="@string/btn_submit"/>

设置环境xml

 <?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
          xmlns:tools="http://schemas.android.com/tools"
          android:id="@+id/root"
          android:orientation="vertical"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          tools:context=".Activities.Environment">


    <ImageButton
        android:src="@mipmap/unlocked_syn"
        android:layout_width="48dp"
        android:layout_height="45dp"
        android:id="@+id/lock"
        android:layout_row="1"
        android:layout_column="11" />

   </LinearLayout>

试试这个,您应该通过布局中的视图初始化您的 Seekbar 等。只需执行 findViewById 搜索 activity

中的视图
private void initiatePopupWindow() {
    try {
        LayoutInflater inflater = (LayoutInflater) Environment.this
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View layout = inflater.inflate(R.layout.annotation,
                (ViewGroup) findViewById(R.id.popup_element));
        pwindo = new PopupWindow(layout, 1000, 1200, true);
        pwindo.showAtLocation(layout, Gravity.CENTER, 0, 0);

        bar = (SeekBar)layout.findViewById(R.id.seekBar1); // make seekbar object
        bar.setOnSeekBarChangeListener(this);
        textProgress = (TextView)layout.findViewById(R.id.textViewProgress);

        textAction = (TextView)layout.findViewById(R.id.textViewAction);

    } catch (Exception e) {
        e.printStackTrace();
    }
}