Android:画布上的弹出窗口

时间:2014-03-13 04:48:14

标签: android canvas popupwindow android-popupwindow

您好我正在尝试在画布上调用弹出窗口。基本上我有这个绘制矩形的视图类,我想在触摸后调用一个弹出窗口,如果在矩形上3秒。我在弹出窗口中有一个textview,我想将名称设置为textview。该名称是从mainactivity中检索的。

我的代码如下,但我不知道为什么它没有出现。请指教。

// Open popup window
if (rectList.get(i).contains(x, y)) {

        Handler handlerPop = new Handler();
        handlerPop.postDelayed(new Runnable() {
        @Override
        public void run() {

        LayoutInflater layoutInflater = (LayoutInflater) getContext().getSystemService(
                                                        Context.LAYOUT_INFLATER_SERVICE);

               View popupView = layoutInflater.inflate(R.layout.popup_layout, null);
           final PopupWindow popupWindow = new PopupWindow(popupView, LayoutParams.WRAP_CONTENT,
                                        LayoutParams.WRAP_CONTENT);
         if (MainActivity.name == null) {
            popupWindow.dismiss();
        } else {

                       TextView equationTV = (TextView) popupView.findViewById(R.id.equationTextView);
            equationTextView.setText(MainActivity.name); 

    }
            Button btnDismiss = (Button) popupView.findViewById(R.id.dismiss);

                     btnDismiss.setOnClickListener(new Button.OnClickListener() {

                @Override
               public void onClick(View v) {   
                   popupWindow.dismiss();                                                                    
               }
        });

     }
}, 3000);

}

popup_layout.xml:

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" 
        android:background="@android:color/background_light">
     <LinearLayout 
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:orientation="vertical" 
         android:layout_margin="1dp"
         android:background="@android:color/darker_gray">
         >
         <LinearLayout 
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:orientation="vertical" 
          android:layout_margin="20dp">
          <TextView
               android:id="@+id/equationTextView"
              android:layout_width="fill_parent"
              android:layout_height="wrap_content"
              android:text="It's a PopupWindow" />
          <ImageView
              android:layout_width="fill_parent"
              android:layout_height="wrap_content"
              android:src="@drawable/ic_launcher" />
          <Button
              android:id="@+id/dismiss"
              android:layout_width="fill_parent"
              android:layout_height="wrap_content"
              android:text="Dismiss" />
          </LinearLayout>
 </LinearLayout>
</LinearLayout>

0 个答案:

没有答案