2012-03-30 78 views
0

某些條目我想通過下面的代碼禁用ListView中

public class VSsimpleCursorAdapter extends SimpleCursorAdapter implements 
     Filterable { 
    public VSsimpleCursorAdapter(Context context, int layout, Cursor c, 
      String[] from, int[] to) { 
     super(context, layout, c, from, to); 
    } 

    public boolean areAllItemsEnabled() { 
     return false; 
    } 

    public boolean isEnabled(int position) { 
     String s = "mystring" 
     if (/*compare an entry in cursor with s*/){ 
      return false; 
     } else 
     return true; 

    } 
} 

的問題是isEnabled只有一個參數位置可以禁用在我的ListView的某些項目。如何使用Curser用於設置isEnabled中的Adapter

+0

你是否必須禁用某些行? – SALMAN 2012-03-30 21:13:28

+0

@SALMAN是的,「ListView」的某些行。 – 2012-03-30 21:14:39

回答

1

沒有測試過,但我想你只需要將光標移動到特定的行並獲得應該與s進行比較的值。所以像

public boolean isEnabled(int position) { 
    String s = "mystring"; 

    // the database column of the value that you want to compare to s 
    int column = 0; 
    Cursor cursor = getCursor(); 
    cursor.moveToPosition(position); 
    String value = cursor.getString(column); 

    if (s.equals(value)) { 
     return false; 
    } else 
     return true; 

}