정상적인 활동에서 GridView이 있으면 정상적으로 작동합니다. 하지만 여기에 나는 PopupWindow을 가지고 있으며, 작동하도록 모든 것을 시도했지만 onItemClick은 호출되지 않을 것입니다!은 (아마도 내가 그들을 잘못했습니다?) 나는 대부분의 사람들을위한 솔루션 않은 다음과 시도했지만 그들은 나를 위해 작동하지 않았다 활동의PopupWindow의 GridView에 대한 setOnItemClickListener가 작동하지 않습니다.
android:clickable="false"
android:focusable="false"
android:focusableInTouchMode="false"
android:descendantFocusability="blocksDescendants"
부 :
bgGrid.setAdapter(new ImageAdapter(context));
bgGrid.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> arg0, View v, int position, long id) {
Log.v("CLICK", "ITEM SELECTED " + position);
}
});
pw = new PopupWindow(layout, posx, posy);
pw.setOutsideTouchable(false);
pw.showAtLocation(layout, Gravity.CENTER, 0, 0); //bgGrid is part of layout
을 와 XML :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#444444"
android:orientation="vertical"
android:padding="5dip" >
<GridView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/gridview"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:columnWidth="160dp"
android:gravity="center"
android:horizontalSpacing="10dp"
android:numColumns="auto_fit"
android:stretchMode="columnWidth"
android:verticalSpacing="10dp" >
</GridView>
<Button
android:id="@+id/popup_close"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:onClick="closePopup"
android:text="Close" />
</LinearLayout>
ImageAdapter
public class ImageAdapter extends BaseAdapter {
private Context mContext;
public ImageAdapter(Context c) {
mContext = c;
}
public int getCount() {
return mThumbIds.length;
}
public Object getItem(int position) {
return null;
}
public long getItemId(int position) {
return 0;
}
public View getView(int position, View convertView, ViewGroup parent) {
ImageView imageView;
if (convertView == null) { mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
imageView = new ImageView(mContext);
imageView.setLayoutParams(new GridView.LayoutParams(160, 120));
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
} else {
imageView = (ImageView) convertView;
}
imageView.setImageResource(mThumbIds[position]);
return imageView;
}
전체 팝업 부분은 PereferenceActivity에 있으며 여기에서 Preference에 대한 클릭을 감지하고 Popup을 여는 리스너가 있습니다. 분명히 오직 하나의 리스너가있을 수 있으며, 나는 이것을 푸는 방법을 모르므로 onClick to Preference를 설정할 수는 없습니다 (onPreferenceClick은 결코 어떤 클릭도 감지하지 못합니다). 팝업 (내가 그 클릭을 얻을 수있는 유일한 방법)를 호출 첫 번째 청취자 :
images = (Preference) findPreference("prefs_bg");
images.setOnPreferenceClickListener(new BackgroundColorSelector());
를 클릭하여 화면에 표시됩니다 통해 얻을 수 없습니다 클릭 상관없이 (심지어 drawSelectorOnTop을 시도하지), 그러나.
이벤트가 팝업 창 자체에 들어가나요? – Nathaniel
ITEM SELECTED가 logcat에 인쇄됩니까? – NPike
@NPike 아니오, –