2014-03-03 61 views
0

我有一個GridView(Android)。我想隱藏其中一列,然後訪問它的值。如何在GridView中隱藏列(android)

可能嗎?

+0

SetVisibility,但這是所有的GridView所以沒有關係 – fRubio

+0

我把我的答案放在你的問題的下面,但它真的很難想出一個很好的理由,你會試圖推動這個......你能解釋一下你正在努力完成? – NameSpace

+0

我正在從數據庫加載信息並將其放入gridview。第一列包含對我有用的ID,用於管理數據庫,但對用戶無用。我想沒有加載ID,但我需要它來做另一個查詢。這就是爲什麼我想隱藏它。 (我試圖實現你的建議)......我不知道我是否已經很好地解釋了它...... – fRubio

回答

0

更新:根據您的回覆,我覺得你最好把你的數據在地圖上,而不是用一種無形的列...

例子:

HashMap<Integer, Integer> map_positionToId = new HashMap<Integer, Integer>(); 
    map_positionToId.put(position, id); 
    int id = map_positionToId.get(position); 

有沒有簡單的設置在GridView上進行翻轉以使我知道的列不可見。 然而,下面是嘗試建議...這可能需要一些試驗和錯誤的正確決絕:

這是你的GridView適配器getView方法:

public View getView(int position, View convertView, ViewGroup parent) { 

     //You want your if(convertView == null) code here. 
     //As we can't set visibility of a null object; 

     .... 

     // Assuming u want to blank the 3rd column, in a 3 column gridview 
     if(position % 3 == 0) 
      convertView.setVisibility(View.INVISIBLE); //u can try gone too? 
     else 
      convertView.setVisibility(View.VISIBLE); 

     // rest of your code... 

    } 

您也可能玩弄填充/邊距,並查看寬度,以獲得所需的效果,如果您試圖將不可見列從屏幕上推下去。