Reputation: 1475
I have a spinner populated from a cursor using SimpleCursorAdapter I want to delete some values from this adapter depending on a variable I try something like this but doesn't work fine
SimpleCursorAdapter toListAdapter = new SimpleCursorAdapter(MoreTicketSalesActivity.this, R.layout.generic_spinneritem, cursor, column,
viewIds) {
@Override
public void bindView(View view, Context context, Cursor cursor) {
super.bindView(view, context, cursor);
if (cursor.getLong(3) < session.getStopIndex()) {
view.setVisibility(View.INVISIBLE);
}
}
};
Please help me
Upvotes: 0
Views: 936
Reputation: 1475
So i find a solution who is just perfect for me
TextView textView = (TextView) view.findViewById(R.id.spinner_item_name);
int index = cursor.getInt(cursor.getColumnIndex("index"));
String name = cursor.getString(cursor.getColumnIndex("name"));
textView.setText(name);
if (index <= this.index) {
textView.setTextColor(Color.LTGRAY);
textView.setClickable(true);
} else {
textView.setTextColor(Color.BLACK);
textView.setClickable(false);
}
Upvotes: 1
Reputation: 11097
First of All you check value of your variable and get location of items to be deleted from the cursor.
Then remove those values from Cursor ( by remove(position of value) or etc ).
Then use toListAdapter.notifyDataSetChanged();
Upvotes: 0