Hi,

Starting from the beginning, I build a custom grid loaded from a table in
the database. I did it using a GridLayout a CursorAdapter built from a
SimpleCursorAdapter using a custom layout that only contains a
CheckedTextView item. Here's the code that gets the GridLayout from the code
and populates it:

public void generateEquipmentsGridView() {

DbExtendedStringAdapter dbAdapter = new DbExtendedStringAdapter(this,
DbExtendedStringAdapter.TABLE_NAME_EQUIPMENTS);
dbAdapter.open();
// getting all elements from DB:
Cursor cursor = dbAdapter.getAll();
startManagingCursor(cursor);
// creating the adapter for the list:
if (cursor != null && cursor.getCount() > 0) {
CursorAdapter adapter = new SimpleCursorAdapter(this,
R.layout.extended_checkedtextview_custom,
cursor,
new String[]
{cursor.getColumnName(cursor.getColumnIndex(DbExtendedStringAdapter.KEY_STRING))},
new int[] {R.id.text1});
// setting the adapter in the list:
GridView gridviewEquipments =
(GridView)findViewById(R.id.field_equipments_gridview);
gridviewEquipments.setAdapter(adapter);
gridviewEquipments.setOnItemClickListener(new OnItemClickListener() {

@Override
public void onItemClick(AdapterView<?> l, View view, int position, long id)
{
CheckedTextView checkedTextView =
(CheckedTextView)view.findViewById(R.id.text1);
if (gridSelectedElementsIds.contains(id)) {
checkedTextView.setChecked(false);
gridSelectedElementsIds.remove(id);
} else {
checkedTextView.setChecked(true);
gridSelectedElementsIds.add(id);
}
}
});
}
}


As for the implementation of the onItemClick method, I just keep sync with a
List<Long> that contains the IDs of the items checked in the grid, it also
changes the state of the CheckedTextView to show it as checked or not.
It's working fine, but the problem I've just noticed is that when doing some
scroll the "ticks" that shows an item as checked are jumping from one item
to another. It seems to be random.

any idea of whats doing this to work that way? any kown bug?

I also tried to replace the onItemClick method for something simpler, like
this:

@Override

public void onItemClick(AdapterView<?> l, View view, int position, long id)
{
CheckedTextView checkedTextView =
(CheckedTextView)view.findViewById(R.id.text1);
checkedTextView.setChecked(!checkedTextView.isChecked());
}

I still got the same result with the scrolling things, it keeps jumping
between elements.

This is the definition of the *extended_checkedtextview_custom* layout:

<?xml version="1.0" encoding="utf-8"?>

<CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android";
    android:id="@+id/text1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:textAppearance="?android:attr/textAppearanceMedium"
    android:gravity="center_vertical"
    android:checkMark="?android:attr/listChoiceIndicatorMultiple"
    android:paddingLeft="6dip"
    android:paddingRight="6dip"
/>

Thank you guys! This is killing me becouse I don't know what to look for...
:(

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to