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

我认为您发布的代码没有任何问题……尽管我能找到的此类事情的每个示例都显示newViewbindView. 也许你应该实现一个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 回答