2012-12-16 48 views
1

我想填充我的彈出窗口與列表視圖。但不知何故,我沒有獲取數據。 請幫我一把。彈出窗口沒有通過列表視圖填充

我在此使用openPopup()函數來啓動彈出窗口,並使用fillDataPopup()來填充彈出的數據。請讓我知道如果你需要任何進一步的細節

感謝

/** 
    * FUNCTION TO SHOW LIST OPTIONS ON LISTS BUTTON 
    */ 
    public void openPopup(){ 
     LayoutInflater layoutInflater = (LayoutInflater)getBaseContext().getSystemService(LAYOUT_INFLATER_SERVICE); 
     View popupView = layoutInflater.inflate(R.layout.task_list_popup, null); 
     final PopupWindow popupWindow = new PopupWindow(popupView,LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT); 
     popupWindow.setFocusable(true); 

     Button btnDismiss = (Button) popupView.findViewById(R.id.dismissBUtton); 
     btnDismiss.setOnClickListener(new View.OnClickListener() { 

      @Override 
      public void onClick(View v) { 
       popupWindow.dismiss(); 
      } 
     }); 
     fillDataPopup(); 
     popupWindow.showAsDropDown(listsButton, 50, -30); 

    } 

    public void fillDataPopup(){ 

     Cursor remindersCursor = mDBHelper.fetchAllReminders();   
     startManagingCursor(remindersCursor);       

     // Create an array to specify the fields we want (only the TITLE) 
     String[] from = new String[]{TasksDBAdapter.KEY_TITLE};  

     // and an array of the fields we want to bind in the view 
     int[] to = new int[]{R.id.listNameTextId};         

     // Now create a simple cursor adapter and set it to display -mapping layout with data 
     SimpleCursorAdapter reminders = new SimpleCursorAdapter(this, R.layout.popup_lists_name,remindersCursor, from, to); 
     setListAdapter(reminders); 
     // listNames.setAdaper(reminders); 
    } 

回答

0

什麼類型的類這是什麼? ListActivity,ListFragment?我不相信你可以使用這些類來填充這樣的ListView。

您需要使用popupView.findViewById()來找到您的ListView並將適配器直接傳遞給它。事情是這樣的:

listNames = popupView.findViewById(R.id.xxx); 

和恢復:

listNames.setAdaper(reminders); 
+0

我的類擴展listActivity像 公共類TaskManagerActivity擴展ListActivity – RayKaushik

+0

ü什麼建議修改應我做..?請詳細說明,因爲我是新來android.Thanks – RayKaushik

+0

ListActivity不會自動查找'task_list_popup.xml'內的ListView。您必須使用上述兩個步驟。 – Sam