views:

244

answers:

1

I have a grid view of buttons that is generated by a CursorAdapter. When the CursorAdapter is passed to the Gridview the view renders correctly however the first item in the grid does not fire the OnClickListener event.

If I select another button in the grid, the event fires correctly however if I selected the first button then another button, it loads the first button action then the section button action.

When testing this, it only seems to be an issue in Android 2.2 on my emulator, my 1.5 phone works as expected. I've wiped the emulator but that doesn't seem to have made a difference.

public class AdapterMedia extends CursorAdapter {

    Context context;
    Cursor cursor;

    public AdapterMedia(Context context, Cursor dataset)
    {
        super(context, dataset);
        this.context = context;
        this.cursor  = dataset;
    }

    @Override
    public View newView(Context context, Cursor cursor, ViewGroup arg2)
    {
        Button imageView;

        imageView = new Button(context);
        imageView.setLayoutParams(new GridView.LayoutParams(85, 85));
        imageView.setPadding(8, 8, 8, 8);
        imageView.setId(cursor.getInt(0));
        imageView.setText(cursor.getString(1));
        imageView.setOnClickListener(buttonClickListener);

        return imageView;
    }

    @Override
    public void bindView(View arg0, Context arg1, Cursor arg2)
    {
        Button imageView = (Button) arg0;

        imageView.setLayoutParams(new GridView.LayoutParams(85, 85));
        imageView.setPadding(8, 8, 8, 8);
        imageView.setId(cursor.getInt(0));
        imageView.setText(cursor.getString(1));
        imageView.setOnClickListener(buttonClickListener);
    }

    public OnClickListener buttonClickListener = new OnClickListener()
    {
        public void onClick(View view)
        {
            Bundle dataset = new Bundle();
            dataset.putInt("media_id", view.getId());

            Intent showMedia = new Intent(context.getApplicationContext(), MediaActivity.class);
            showMedia.putExtras(dataset);

            context.startActivity(showMedia);
        }
    };
}
A: 

Did you ever figure out what was going on?

I am having the same problem where it works in 2.1, but when I try it on a 2.2 droid or emulator both don't respond to clicks, the events do not get triggered.

RichardJohnn