1

これには GridView と SimpleCursorAdapter があります。コードは次のようになります

GridView myGridView = (GridView) this.freePassDialog.findViewById(R.id.gridview_buttons);
    String[] column = { "name", "type" };
    int[] viewIds = new int[] { R.id.name_button, R.id.type_button };

    SimpleCursorAdapter myCursorAdapter = new SimpleCursorAdapter(this.parent, R.layout.row_free_pass_buttons, cursor, column, viewIds) {

        /**
         * {@inheritDoc}
         * @see android.widget.SimpleCursorAdapter#bindView(android.view.View, android.content.Context, android.database.Cursor)
         */
        @Override
        public void bindView(View view, Context context, Cursor cursor) {
            String freePassName = cursor.getString(cursor.getColumnIndex("name"));
            String freePassType = cursor.getString(cursor.getColumnIndex("type"));
            Button freePassBtn = (Button) view.findViewById(R.id.pass_name_button);
            if (PaymentMethodType.SMARTCARD_PASS == PaymentMethodType.valueOf(freePassType)) {
                freePassBtn.setVisibility(View.GONE);
            } else {
                freePassBtn.setVisibility(View.VISIBLE);
            }
            super.bindView(view, context, cursor);
        }
    };
    myGridView.setAdapter(myCursorAdapter);

カーソルには4つの値がありますが、ロガーをBindViewメソッドに入れると、最初の値だけが数回来ます誰か助けてもらえますか? ありがとう

4

1 に答える 1

0

あなたが投稿したコードには何の問題もありません...この種のもののすべての例は、newViewと同様にオーバーライドしていることを示していますbindView。多分あなたはnewViewオーバーライドを実装する必要がありますか?

@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
    final LayoutInflater inflater = LayoutInflater.from(context);
    View v = inflater.inflate(layout, parent, false);
    return v;
}
于 2012-06-12T12:31:33.490 に答える