2014-10-27 65 views
1

enter image description here我有一個自定義彈出窗口與列表視圖是很好的..唯一的問題是我不能捕獲onItemClicked listner的ListView。在彈出菜單中的列表視圖中的項目沒有被點擊

LayoutInflater inflater = (LayoutInflater)getActivity().getSystemService(getActivity().LAYOUT_INFLATER_SERVICE); 
     View layout = inflater.inflate(R.layout.custom_dialog,null); 



     final PopupWindow pWindow = new PopupWindow(); 
     pWindow.setContentView(layout); 
     pWindow.setWidth(500); 
     pWindow.setHeight(700); 
     pWindow.showAtLocation(layout, Gravity.CENTER, 0, 0); 

     final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(getActivity(),android.R.layout.simple_list_item_1); 
     for(int i=0;i<FilterList.size();i++) 
     { 
      arrayAdapter.add(FilterList.get(i)); 
     } 

     ListView lv_popup = (ListView) layout.findViewById(R.id.list_info); 
     lv_popup.setAdapter(arrayAdapter); 

     lv_popup.setOnItemClickListener(new OnItemClickListener() { 

      @Override 
      public void onItemClick(AdapterView<?> arg0, View arg1, int position, 
        long arg3) { 
       // TODO Auto-generated method stub 
       selectedIndex =position; 
       fillSpinner(); 
       pWindow.dismiss(); 

      } 
     }); 
+0

你如何將數據傳遞給列出適配器 – 2014-10-27 13:03:07

+0

我有一個ArrayList的 FilterList ...數據SE越來越顯示那裏...只有onclikc行動不起作用 – 2014-10-27 13:07:34

+0

如果除了onclick之外的每件事情都工作,刪除OnItemClickListener中的所有代碼,並放在Toast,以確保錯誤在這裏 – 2014-10-27 13:15:58

回答

0

你爲什麼不嘗試的警告對話框,然後

AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this); 
       builder.setTitle("your title"); 
       // here put your items list 
       builder.setItems(items, new DialogInterface.OnClickListener() { 
        public void onClick(DialogInterface dialog, int item) { 
        // do what ever you want here 
         System.out.println("************* clicked-item :"+item); 

        } 
       }); 
      // set your custom view 
      // in your case its layout view 
      builder.setView(layout); 
      AlertDialog alert = builder.create(); 
      alert.show(); 

,如果你想用你的代碼,你可以嘗試 這個屬性的列表視圖

android:clickable="true" 

,並添加這個屬性給所有您的XML中的其他視圖

android:focusable="false" 

android:focusableInTouchMode="false" 

是那樣的

<ListView 
    android:id="@+id/YourID" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:clickable="true" 
    android:cacheColorHint="#00000000" 
    android:divider="#adb8c2" 
    android:dividerHeight="1dp" 
    android:scrollingCache="false" 
    android:smoothScrollbar="true" 

    > 

</ListView> 

我希望與你這項工作

+1

我希望這是自定義..曲線角落+自定義顏色 – 2014-10-27 13:39:45

+0

我更新我的答案我希望這次的工作 – 2014-10-27 13:53:02

相關問題