private void initBarButtons() { final LinearLayout.LayoutParams llButtonParams = new LinearLayout.LayoutParams(buttonWidth, buttonWidth); llButtonParams.setMargins(0, 0, buttonMargin, 0); undoButton.setBackgroundResource(R.drawable.undo_button_selector); undoButton.setPadding(0, 0, 0, 0); undoButton.setLayoutParams(llButtonParams); this.addView(undoButton); redoButton.setBackgroundResource(R.drawable.redo_button_selector); redoButton.setPadding(0, 0, 0, 0); redoButton.setLayoutParams(llButtonParams); this.addView(redoButton); // Tool radio group LayoutParams radioGroupParams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); radioGroupParams.setMargins(0, 0, 0, 0); final RadioGroup toolRadioGroup = new RadioGroup(this.getContext()); toolRadioGroup.setOrientation(RadioGroup.HORIZONTAL); toolRadioGroup.setLayoutParams(radioGroupParams); toolRadioGroup.setPadding(0, 0, 0, 0); final RadioGroup.LayoutParams rgButtonParams = new RadioGroup.LayoutParams(buttonWidth, buttonWidth); rgButtonParams.setMargins(0, 0, buttonMargin, 0); selectButton.setButtonDrawable(R.drawable.select_button_selector); selectButton.setLayoutParams(rgButtonParams); toolRadioGroup.addView(selectButton); eraserButton.setButtonDrawable(R.drawable.erase_button_selector); eraserButton.setLayoutParams(rgButtonParams); toolRadioGroup.addView(eraserButton); for (int i = 0; i < 8; i++) { penButtons[i] = new PenRadioButton(this.getContext()); penButtons[i].setLayoutParams(rgButtonParams); toolRadioGroup.addView(penButtons[i]); } this.addView(toolRadioGroup); menuButtonSpacer.setLayoutParams( new LinearLayout.LayoutParams(0, LayoutParams.MATCH_PARENT, 1.0f)); this.addView(menuButtonSpacer); menuButton.setBackgroundResource(R.drawable.ic_action_overflow); menuButton.setPadding(0, 0, 0, 0); menuButton.setLayoutParams(llButtonParams); menuButton.setOnClickListener(menuButtonListener); this.addView(menuButton); }
@Override public View onCreateView( LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.stats_visitors_and_views_fragment, container, false); TextView titleTextView = (TextView) view.findViewById(R.id.stats_pager_title); titleTextView.setText(getTitle()); mVisitorsToday = (TextView) view.findViewById(R.id.stats_visitors_and_views_today_visitors_count); mViewsToday = (TextView) view.findViewById(R.id.stats_visitors_and_views_today_views_count); mViewsBestEver = (TextView) view.findViewById(R.id.stats_visitors_and_views_best_ever_views_count); mViewsAllTime = (TextView) view.findViewById(R.id.stats_visitors_and_views_all_time_view_count); mCommentsAllTime = (TextView) view.findViewById(R.id.stats_visitors_and_views_all_time_comment_count); RadioGroup mRadioGroup = (RadioGroup) view.findViewById(R.id.stats_pager_tabs); mRadioGroup.setVisibility(View.VISIBLE); mRadioGroup.setOnCheckedChangeListener(this); for (int i = 0; i < TITLES.length; i++) { RadioButton rb = (RadioButton) LayoutInflater.from(getActivity()).inflate(R.layout.stats_radio_button, null, false); RadioGroup.LayoutParams params = new RadioGroup.LayoutParams( RadioGroup.LayoutParams.WRAP_CONTENT, RadioGroup.LayoutParams.WRAP_CONTENT); int dp8 = (int) Utils.dpToPx(8); params.setMargins(0, 0, dp8, 0); rb.setMinimumWidth((int) Utils.dpToPx(80)); rb.setGravity(Gravity.CENTER); rb.setLayoutParams(params); rb.setText(TITLES[i]); mRadioGroup.addView(rb); if (i == mSelectedButtonIndex) rb.setChecked(true); } return view; }
public void renderView() { mGiftTip.setVisibility(View.INVISIBLE); mIndicator.setVisibility(View.GONE); mRadioGroup.setVisibility(View.INVISIBLE); mTxtSend.setVisibility(View.INVISIBLE); mLoading.setVisibility(View.VISIBLE); // SpecialGift[] specialGifts = (SpecialGift[]) // MemoryDataCenter.getInstance().get(MemoryDataCenter.SPECIALGIFTS); // if(GiftInfoManager.getInstance().initData()){ mGiftTip.setVisibility(View.VISIBLE); mRadioGroup.setVisibility(View.VISIBLE); mTxtSend.setVisibility(View.VISIBLE); mLoading.setVisibility(View.INVISIBLE); mGroupNames = GiftInfoManager.getGroupNames(); mAdapter = new GiftKeyBoardAdapter(mContext, mGroupNames, forChat); mViewPager.setAdapter(mAdapter); // 初始化 int firstPageCount = ((GiftKeyBoardAdapter) mAdapter).getFirstPageCount(); int secondPageCount = ((GiftKeyBoardAdapter) mAdapter).getSecondPageCount(); if (!forChat) { if (firstPageCount + secondPageCount > 1) { mIndicator.setVisibility(View.VISIBLE); mIndicator.setCount(firstPageCount + secondPageCount); mIndicator.setCurrentItem(0); } mIndicatorForChat.setVisibility(View.GONE); } else { mIndicator.setVisibility(View.GONE); if (firstPageCount + secondPageCount > 1) { mIndicatorForChat.setVisibility(View.VISIBLE); mIndicatorForChat.setCount(firstPageCount + secondPageCount); mIndicatorForChat.setCurrentItem(0); } } if (mGroupNames.length >= 2) { mRadioGroup.setVisibility(View.VISIBLE); mRadioGroup.removeAllViews(); rlp = new RadioGroup.LayoutParams(0, LayoutParams.MATCH_PARENT); rlp.weight = 1.0f; for (int i = 0; i < mGroupNames.length; i++) { RadioButton rb = (RadioButton) ((LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE)) .inflate(R.layout.view_item_radio_button, null); if (i == 0) { rb.setChecked(true); } rb.setId(i); rb.setText(mGroupNames[i]); mRadioGroup.addView(rb, rlp); rb.setOnClickListener(listener); } mRadioGroup.check(0); } // } if (forChat) { mGiftTip.setVisibility(View.GONE); mMarginLayout.setVisibility(View.GONE); mBottomLayout.setVisibility(View.GONE); } else { initUserPageSendGift(0); } }
private void addRadioButton(int answerRow, String[] answer) { rgp = (RadioGroup) findViewById(R.id.radioGroup); // ((RadioButton) rgp.getChildAt(answer)).setChecked(true); for (int row = 0; row < 1; row++) { for (int i = 0; i < answerRow; i++) { RadioButton radioButton = new RadioButton(this); radioButton.setText(answer[i]); radioButton.setId(i); // // radioButton.setBackground(getDrawable(R.drawable.custom_radiogroup_divider)); radioButton.invalidate(); RadioGroup.LayoutParams rprms = new RadioGroup.LayoutParams( RadioGroup.LayoutParams.WRAP_CONTENT, RadioGroup.LayoutParams.WRAP_CONTENT); // rprms.topMargin = 20 ; rprms.weight = 1f; rprms.leftMargin = 60; // rprms.gravity = Gravity.CENTER | Gravity.LEFT; rgp.addView(radioButton, rprms); } } rgp.setOnCheckedChangeListener( new RadioGroup.OnCheckedChangeListener() { @Override public void onCheckedChanged(RadioGroup group, int checkedId) { // get selected radio button from radioGroup int selectedId = rgp.getCheckedRadioButtonId(); RadioButton radioButton = (RadioButton) findViewById(checkedId); radioButton.setChecked(true); String selection = (String) radioButton.getText(); txtStudentAnswer.setText(selection); if (counter == 0) { QuestionID = getQuestionID(Question); } else { // int Question_id = sp.getInt("Question_ID " + counter, -1); } editor.putInt("answer_choice " + counter, checkedId); editor.putString("answer_choice" + counter, selection); editor.putString("specificAnswer" + counter, specificAnswer); editor.putInt("answer_choice_ID" + counter, getChoiceID(selection, QuestionID)); editor.commit(); // find the radiobutton by returned id // Toast.makeText(QuestionPageActivity.this, radioButton // .getText(), Toast.LENGTH_SHORT).show(); // // Log.d("GExam", "Question: " + (counter + 1) + " = " + // String.valueOf(sp.getInt("answer_choice " + (counter), -1))); // // // // // // // // Log.e("GExam", "score = " + score); // Log.e("GExam", "selection = " + selection); Log.e("GExam", "QuestionID = " + QuestionID); } }); } // end of addRadioButton