单选按钮未在RadioGroup中显示

时间:2014-10-13 07:16:56

标签: android radio-button

我正在按程序添加一些单选按钮,但它可能无法显示按钮。

结果只能显示itemNameTextoptCatText,单选按钮没有显示。我想知道他们是否被加入了广播组......

以下是我的代码。故障在哪里?

        convertView = LayoutInflater.from(context).inflate(layout, parent, false);

        FoodItem item = this.getItem(position);
        TextView itemNameText = (TextView)convertView.findViewById(R.id.food_name);
        itemNameText.setText(item.getFoodInfo(db, EasyMealDB.FOOD_NAME));

        LinearLayout options = (LinearLayout)convertView.findViewById(R.id.options);
        String optCatSql = "SELECT "+EasyMealDB.FOOD_OPTION_CATEGORY_NAME+
                                ", "+EasyMealDB.FOOD_OPTION_CATEGORY_ID+
                            " FROM "+EasyMealDB.FOOD_OPTION_CATEGORY_TABLE+
                            " WHERE "+EasyMealDB.FOOD_ID+" = "+item.getId();
        Log.d(TAG, optCatSql);
        Cursor optCatCursor = db.rawQuery(optCatSql, null);
        while (optCatCursor.moveToNext()){
            TextView optCatText = new TextView(context);
            optCatText.setText(optCatCursor.getString(0)+":");

            options.addView(optCatText);

            RadioGroup radioGp = new RadioGroup(context);
            radioGp.setOrientation(RadioGroup.VERTICAL);
            String optSql = "SELECT "+EasyMealDB.FOOD_OPTION_NAME+
                        " FROM "+EasyMealDB.FOOD_OPTION_TABLE+
                        " WHERE "+EasyMealDB.FOOD_OPTION_CATEGORY_ID+" = "+optCatCursor.getInt(1);
            Log.d(TAG, optSql);
            Cursor optCursor = db.rawQuery(optSql, null);               
            while (optCursor.moveToNext()){
                RadioButton optionButton = new RadioButton(context);
                optionButton.setText(optCursor.getString(0));
                Log.d(TAG, optionButton.getText().toString());
                radioGp.addView(optionButton);
            }
            optCursor.close();
        }
        optCatCursor.close(); 

0 个答案:

没有答案