我得到元素的标记和ID,但无法设置可见性或onClickListener。你能告诉我为什么吗?代码: onClickListener和知名度,这应该使视图不可见,在clicklistener应该说DS(我第一次尝试的一个然后其他):无法在PopUp窗口中的视图上设置onClickListener:
ViewGroup layoutHolder = (ViewGroup) inflater.inflate(context.getResources().getIdentifier("settings",
"layout", context.getPackageName()), (ViewGroup) this.findViewById(getResources().getIdentifier("settings",
"id", getPackageName())), false);
layoutHolder.findViewById(R.id.msettings).setOnClickListener(handler)
View.OnClickListener handler = new View.OnClickListener() {
public void onClick(View v) {
Toast.makeText(getApplicationContext(), "ds", Toast.LENGTH_SHORT).show();
};
弹出:
LayoutInflater layoutInflater
= (LayoutInflater)getBaseContext()
.getSystemService(LAYOUT_INFLATER_SERVICE);
View popupView = layoutInflater.inflate(R.layout.settings, null);
final PopupWindow popupWindow = new PopupWindow(
popupView,
LinearLayout.LayoutParams.WRAP_CONTENT,
LinearLayout.LayoutParams.WRAP_CONTENT);
Bitmap bitmap = null;
popupWindow.setBackgroundDrawable(new BitmapDrawable(getApplicationContext().getResources(), bitmap));
popupWindow.setOutsideTouchable(true);
popupWindow.showAsDropDown(v, 50, 11);
XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/settings"
android:tag="settings"
android:background="@drawable/shadow_light"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:paddingTop="5dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="60dp"
android:paddingTop="5dp"
android:paddingBottom="5dp"
android:orientation="horizontal"
android:gravity="center_horizontal|center_vertical"
android:background="@drawable/fast_menu_background"
android:id="@+id/top_menu"
android:tag="menu_top">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:id="@+id/top_menu_sub"
android:tag="menu_top">
<ImageButton
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:src="@drawable/fast_menu_map_settings"
android:background="#00000000"
android:adjustViewBounds="true"
android:scaleType="fitXY"
android:layout_marginLeft="5dp"
android:layout_marginStart="5dp"
android:layout_weight="1"
android:contentDescription="@string/desc_st"
android:id="@+id/msettings"
android:tag="msettings"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
显示代码第一 – 2015-02-24 12:36:40
我已经添加了代码 – user4597015 2015-02-24 12:40:09
显示辣油,并在您试图上点击收听 – 2015-02-24 12:40:55