2011-11-11 30 views
0

我在每行有一個ListView我有一個LinearLayout與一些對象(主要是一些TextViews)。SimpleCursorAdapter刪除值

這個ListView我從遊標動態填充它。在這個遊標中,我有一個值true或false。

我想隱藏或使不可點擊的行的值爲false。我試試這個代碼,但該適配器

http://developer.android.com/reference/android/widget/BaseAdapter.html#isEnabled(int

這個答案似乎它暗示上不起作用

public void contentProviderInitialized(final Cursor cursor) { 

    SimpleCursorAdapter commonTickets = new SimpleCursorAdapter(MyClass.this, 
     R.layout.row_ticketing, cursor, new String[] {"price", "productName", "stopName" }, 
     new int[] { R.id.ticketing_price, R.id.ticketing_product, R.id.ticketing_stop_name } 
    ) { 
     @Override 
     public void bindView(View view, Context context, Cursor cursor) { 
      String enabledStr = cursor.getString(cursor.getColumnIndex("enabled")); 
      String product = cursor.getString(cursor.getColumnIndex("productName")); 
      boolean enabled = Boolean.parseBoolean(enabledStr); 
      LinearLayout ticketingRow = (LinearLayout) view.findViewById(R.id.ticketing_row); 
      if (enabled) { 
       ticketingRow.setEnabled(true); 
      } else { 
       ticketingRow.setEnabled(false); 
      } 
      super.bindView(view, context, cursor); 
     }; 
     MyClass.this.ticketing_list_view.setAdapter(commonTickets); 
    } 
} 
+0

發佈完整的異常和您的StackTrace。 –

+0

我沒有提到有關例外情況。問題是具有錯誤值的行仍然是可點擊的。 – tinti

回答

1

覆蓋的IsEnabled。使用光標上的movetoposition。聽起來這樣的性能會很糟糕,但是,您可能需要根據數字位置對真/假值進行一些緩存?試試看。看看它是如何發展的。緩存可能是浪費。