2013-02-08 3 views
3

정상적인 활동에서 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을 시도하지), 그러나.

+0

이벤트가 팝업 창 자체에 들어가나요? – Nathaniel

+0

ITEM SELECTED가 logcat에 인쇄됩니까? – NPike

+0

@NPike 아니오, –

답변

-1

ImageAdapter가 부 풀리는 레이아웃에 OnItemClickListeners가 등록되어 있지 않은지, 그리고/또는 Adapter 레이아웃에 android : focussable = false가 설정되어 있는지 확인하십시오.

예를 들면 :

<ImageView 
android:id="@+id/imageViewIcon" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:focussable=false 
/> 
+0

ImageAdapter를 보시면 이미지 레이아웃을 사용하고 있지 않습니다. 나는 다른 어떤 클릭 리스너도 가지고 있지 않다. –

0

:

popUpWindow.setOutsideTouchable(true); 
popUpWindow.setBackgroundDrawable(getResources().getDrawable(android.R.color.white)); 
popUpWindow.setFocusable(true); 

첫 번째 줄은 popupwindow 외부 터치 이벤트를 할 수 있습니다.

두 번째 줄 터치 이벤트가 없으면 팝업 창에서 차단됩니다.

그리고 세 번째 줄은 문제를 해결합니다.

첫 번째와 두 번째가 없으면 사용자 인터페이스는 팝업 창 외부에서 발생한 터치/클릭 이벤트에 응답하지 않습니다.

관련 문제