/** 初始化单选按钮组 */ public void initRadioGroup() { baoRadioGroup = (RadioGroup) findViewById(R.id.buy_join_radiogroup_baodi); for (int i = 0; i < baoTitle.length; i++) { RadioButton radio = new RadioButton(this); radio.setText(baoTitle[i]); radio.setTextColor(Color.BLACK); radio.setTextSize(13); radio.setId(i); radio.setButtonDrawable(R.drawable.radio_select); radio.setPadding(Constants.PADDING, 0, 10, 0); baoRadioGroup.addView(radio); } baoRadioGroup.setOnCheckedChangeListener(this); baoRadioGroup.check(1); openRadioGroup = (RadioGroup) findViewById(R.id.buy_join_radiogroup_open); for (int i = 0; i < openTitle.length; i++) { RadioButton radio = new RadioButton(this); radio.setText(openTitle[i]); radio.setTextColor(Color.BLACK); radio.setTextSize(13); radio.setId(i); radio.setButtonDrawable(R.drawable.radio_select); radio.setPadding(Constants.PADDING, 0, 10, 0); openRadioGroup.addView(radio); } openRadioGroup.setOnCheckedChangeListener(this); openRadioGroup.check(0); }
private void initializeViews() { WindowManager.LayoutParams lpWindow = new WindowManager.LayoutParams(); lpWindow.flags = WindowManager.LayoutParams.FLAG_DIM_BEHIND; lpWindow.dimAmount = 0.8f; getWindow().setAttributes(lpWindow); setContentView(R.layout.select_box_dialog); Button.class.cast(findViewById(R.id.confirm)).setOnClickListener(confirmClickListener); RadioGroup select_group = RadioGroup.class.cast(findViewById(R.id.select_group)); select_group.setOnCheckedChangeListener(radio_group_listener); for (Map.Entry<Object, String> elem : select_list.entrySet()) { RadioButton radio_button = new RadioButton(this.getContext()); radio_button.setButtonDrawable(R.drawable.ui_radio_blue); radio_button.setText(elem.getValue()); radio_button.setId(ServerList.ServerInfo.ServerName.class.cast(elem.getKey()).ordinal()); if (checked_index == ServerList.ServerInfo.ServerName.class.cast(elem.getKey()).ordinal()) { radio_button.setChecked(true); } select_group.addView(radio_button); } TextView.class.cast(findViewById(R.id.message)).setText(this.message); if (this.message.equals("")) { TextView.class.cast(findViewById(R.id.message)).setVisibility(View.GONE); } }
private void init(Context context, View contentview, String[] items) { /** 用数据初始化ui */ radioGroup = (RadioGroup) contentview.findViewById(R.id.filter_layout); radioGroup.clearCheck(); if (items == null) return; for (int i = 0; i < items.length; i++) { RadioButton radioButton = (RadioButton) LayoutInflater.from(context).inflate(R.layout.line_popupwindow_rbt, null); radioButton.setId(rbtIds[i]); radioButton.setText(items[i]); radioGroup.addView(radioButton, -1, radioGroup.getLayoutParams()); if (items[i].equals(outCbx.getText())) { outCbx.setTag(i); radioButton.setChecked(true); } } radioGroup.setOnCheckedChangeListener( new RadioGroup.OnCheckedChangeListener() { @Override public void onCheckedChanged(RadioGroup group, int checkedId) { dismiss(); } }); }
public void generate() { radioGroup.removeAllViews(); for (int i = 0; i < strings.size(); i++) { RadioButton b = new RadioButton(getContext()); b.setText(strings.get(i)); b.setId(values.get(i)); radioGroup.addView(b); } }
public void initTopButton() { for (int i = 0; i < topTitle.length; i++) { RadioButton radio = new RadioButton(this); radio.setText(topTitle[i]); radio.setTextColor(Color.BLACK); radio.setTextSize(13); radio.setId(i); radio.setButtonDrawable(R.drawable.radio_select); radio.setPadding(Constants.PADDING, 0, 10, 0); topButton.addView(radio); } }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_settings); float currentSearchDistance = Application.getSearchDistance(); if (!availableOptions.contains(currentSearchDistance)) { availableOptions.add(currentSearchDistance); } Collections.sort(availableOptions); // The search distance choices RadioGroup searchDistanceRadioGroup = (RadioGroup) findViewById(R.id.searchdistance_radiogroup); for (int index = 0; index < availableOptions.size(); index++) { float searchDistance = availableOptions.get(index); RadioButton button = new RadioButton(this); button.setId(index); button.setText(getString(R.string.settings_distance_format, (int) searchDistance)); searchDistanceRadioGroup.addView(button, index); if (currentSearchDistance == searchDistance) { searchDistanceRadioGroup.check(index); } } // Set up the selection handler to save the selection to the application searchDistanceRadioGroup.setOnCheckedChangeListener( new OnCheckedChangeListener() { public void onCheckedChanged(RadioGroup group, int checkedId) { Application.setSearchDistance(availableOptions.get(checkedId)); } }); // Set up the log out button click handler Button logoutButton = (Button) findViewById(R.id.logout_button); logoutButton.setOnClickListener( new OnClickListener() { public void onClick(View v) { // Call the Parse log out method ParseUser.logOut(); // Start and intent for the dispatch activity Intent intent = new Intent(SettingsActivity.this, DispatchActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(intent); } }); }
public void populateRadioGroup() { if (radioGroup == null || populateRadioGroup == false) return; for (int i = 0; i < groupList.length; i++) { RadioButton radioButton = new RadioButton(context); radioButton.setText(groupList[i].name); radioButton.setId(groupList[i].grpid); radioButton.setTextColor(R.color.text_dark_green); radioGroup.addView(radioButton); } radioGroup.invalidate(); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_test); /*Test test =data.getTest(); TextView textWording=(TextView)findViewById(R.id.pregunta_test); textWording.setText(test.getWording()); RadioGroup group=(RadioGroup)findViewById(R.id.test_choices); int i=0; for(Test.Choice choice : test.getChoices()){ RadioButton radio =new RadioButton(this); radio.setText(choice.getWording()); group.addView(radio); if(choice.iscorrect()) correct=i; i++; }*/ /** *************************ANTES DE COMUNICACIONES****************** */ TextView pregunta = (TextView) findViewById(R.id.pregunta_test); Button enviar = (Button) findViewById(R.id.button_send_test); RadioGroup respuestas = (RadioGroup) findViewById(R.id.test_choices); pregunta.setText(R.string.pregunta_test); String[] opciones = { "Versión de la aplicación", "Listado de componentes de la aplicación", "Opciones del menú de ajustes", "Nivel mínimo de la API Android requerida", "Nombre del paquete java de la aplicación" }; int i; for (i = 0; i < opciones.length; i++) { RadioButton radio = new RadioButton(this); radio.setText(opciones[i]); radio.setId(i); radio.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { findViewById(R.id.button_send_test).setVisibility(View.VISIBLE); } }); respuestas.addView(radio); } /**/ }
/** 初始化单选按钮组 */ public void initRadioGroup() { topButton = (RadioGroup) findViewById(R.id.buy_zixuan_radiogroup_top); for (int i = 0; i < topTitle.length; i++) { RadioButton radio = new RadioButton(this); radio.setText(topTitle[i]); radio.setTextColor(Color.BLACK); radio.setTextSize(13); radio.setId(i); radio.setButtonDrawable(R.drawable.radio_select); radio.setPadding(Constants.PADDING, 0, 6, 0); topButton.addView(radio); } topButton.setOnCheckedChangeListener(this); topButton.check(0); }
/** * Creates the new RadioGroup based on the Input Type of current LogItem * * @param options */ public void createRadioGroup(ArrayList<String> options) { RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT); params.addRule(RelativeLayout.BELOW, R.id.LogItemName); group = new RadioGroup(this.getContext()); group.setLayoutParams(params); for (int i = 0; i < options.size(); i++) { RadioButton btn = new RadioButton(this.getContext()); btn.setId(i); btn.setText(options.get(i)); group.addView(btn); } group.setGravity(Gravity.CENTER_HORIZONTAL); rlayout.addView(group); // Todo: create Listener to add to database when input. }
@Override public void onClick(View view) { if (view.getId() == R.id.detail_send) { mProgressDialog.show(); responseString = mEditText.getText().toString(); sendMessageToServer(); } else if (view.getId() == R.id.option_reply) { final RadioGroup radioGroup = new RadioGroup(MessageDetailActivity.this); radioGroup.setBackgroundColor(getResources().getColor(R.color.default_background)); for (int i = 0; i < options.length; i++) { RadioButton radioButton = new RadioButton(this); radioButton.setText(options[i]); if (i == 0) { radioButton.setChecked(true); responseString = options[0]; } radioButton.setId(i); radioGroup.addView(radioButton); } radioGroup.setId(-1); radioGroup.setOnCheckedChangeListener( new RadioGroup.OnCheckedChangeListener() { @Override public void onCheckedChanged(RadioGroup radioGroup, int checkedId) { responseString = options[checkedId]; } }); new AlertDialog.Builder(this) .setTitle(getString(R.string.reply)) .setView(radioGroup) .setCancelable(false) .setPositiveButton( getString(R.string.ok), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { mProgressDialog.show(); sendMessageToServer(); } }) .show(); } }
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { // Initialize the basics of the AlertDialog AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); // Get the layout inflater LayoutInflater inflater = getActivity().getLayoutInflater(); // Get the view (so we can use findViewById) View view = inflater.inflate(R.layout.custom_workout_dialog_load_from_presets_outer, null); radioGroup = (RadioGroup) view.findViewById(R.id.custom_workout_dialog_load_from_presets_radio_group); PresetsDataSource dataSource = new PresetsDataSource(getActivity()); dataSource.open(); presets = dataSource.getPresets(); dataSource.close(); for (int i = 0; i < presets.size(); i++) { RadioButton button = new RadioButton(getActivity()); button.setId(i); button.setText(presets.get(i).getTitle()); radioGroup.addView(button); } builder .setView(view) // Add action buttons .setPositiveButton( R.string.accept, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { passDataBack(); } }) .setNegativeButton( R.string.cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { CustomWorkoutDialogLoadFromPresets.this.getDialog().cancel(); } }); return builder.create(); }
public void updateUI() { radioGroup.removeAllViews(); radioGroup.setOnCheckedChangeListener(null); String[] messageOptions = app.settings().getMessageOptionsArray(); RadioButton buttonToCheck = new RadioButton(getContext()); for (int i = 0; i < messageOptions.length; i++) { RadioButton button = new RadioButton(getContext()); button.setText(messageOptions[i]); button.setTag(messageOptions[i]); button.setId(i); if (app.settings().getDefaultMessage().equals(messageOptions[i])) { buttonToCheck = button; } radioGroup.addView(button); } buttonToCheck.setChecked(true); radioGroup.setOnCheckedChangeListener(this); removeOptionButton.setEnabled(messageOptions.length != 1); }
private void createRadio() { // データ取得 Cursor cursor = productDB.query("product_info", COLUMNS, null, null, null, null, "product_category"); // LinearLayoutオブジェクト取得 if (lLayout == null) { lLayout = (LinearLayout) this.findViewById(R.id.itemInfo); } lLayout.removeAllViews(); // LinearLayout初期化 if (cursor.moveToFirst()) { // RadioGroup生成(レコードが1件以上の場合) RadioGroup rGroup = new RadioGroup(this); rGroup.setId(0); do { // 品物情報を保持 this.keepItemInfo(cursor); // RadioButton生成 RadioButton rButton = new RadioButton(this); rButton.setId(cursor.getInt(0)); String itemName = " 品物名: " + cursor.getString(1) + "\n 種別: " + cursor.getString(2); rButton.setText(itemName); rGroup.addView(rButton); // RadioGroupにRadioButtonを追加 } while (cursor.moveToNext()); lLayout.addView(rGroup); // LinearLayoutにRadioGroupを追加 } else { // TextView生成(レコードが0件のとき) TextView nothing = new TextView(this); nothing.setText("品物は現在登録されていません。"); lLayout.addView(nothing); // LinearLayoutにTextViewを追加 } // 検索結果クリア cursor.close(); }
@Override public void drawQuestionUI(LayoutInflater inflater, final RelativeLayout relativeLayout) { super.drawQuestionUI(inflater, relativeLayout); radioGroup = (RadioGroup) inflater.inflate(R.layout.radiogroup, null); Integer lastId = getLastId(); for (String answer : getAnswerList()) { RadioButton radioButton = (RadioButton) inflater.inflate(R.layout.radiobutton, null); radioButton.setText(answer); radioButton.setId(getId()); increaseId(); radioGroup.addView(radioButton); radioButton.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { updateSubmitButton(relativeLayout); } }); } radioGroup.setId(getId()); relativeLayout.addView(radioGroup, getLayoutParameter(lastId)); increaseId(); }
public SelectOneWidget(Context context, FormEntryPrompt prompt) { super(context, prompt); // SurveyCTO-added support for dynamic select content (from .csv files) XPathFuncExpr xPathFuncExpr = ExternalDataUtil.getSearchXPathExpression(prompt.getAppearanceHint()); if (xPathFuncExpr != null) { mItems = ExternalDataUtil.populateExternalChoices(prompt, xPathFuncExpr); } else { mItems = prompt.getSelectChoices(); } buttons = new ArrayList<RadioButton>(); // Layout holds the vertical list of buttons LinearLayout buttonLayout = new LinearLayout(context); String s = null; if (prompt.getAnswerValue() != null) { s = ((Selection) prompt.getAnswerValue().getValue()).getValue(); } if (mItems != null) { for (int i = 0; i < mItems.size(); i++) { RadioButton r = new RadioButton(getContext()); r.setText(prompt.getSelectChoiceText(mItems.get(i))); r.setTextSize(TypedValue.COMPLEX_UNIT_DIP, mAnswerFontsize); r.setTag(Integer.valueOf(i)); r.setId(QuestionWidget.newUniqueId()); r.setEnabled(!prompt.isReadOnly()); r.setFocusable(!prompt.isReadOnly()); buttons.add(r); if (mItems.get(i).getValue().equals(s)) { r.setChecked(true); } r.setOnCheckedChangeListener(this); String audioURI = null; audioURI = prompt.getSpecialFormSelectChoiceText(mItems.get(i), FormEntryCaption.TEXT_FORM_AUDIO); String imageURI; if (mItems.get(i) instanceof ExternalSelectChoice) { imageURI = ((ExternalSelectChoice) mItems.get(i)).getImage(); } else { imageURI = prompt.getSpecialFormSelectChoiceText( mItems.get(i), FormEntryCaption.TEXT_FORM_IMAGE); } String videoURI = null; videoURI = prompt.getSpecialFormSelectChoiceText(mItems.get(i), "video"); String bigImageURI = null; bigImageURI = prompt.getSpecialFormSelectChoiceText(mItems.get(i), "big-image"); MediaLayout mediaLayout = new MediaLayout(getContext()); mediaLayout.setAVT( prompt.getIndex(), "." + Integer.toString(i), r, audioURI, imageURI, videoURI, bigImageURI); if (i != mItems.size() - 1) { // Last, add the dividing line (except for the last element) ImageView divider = new ImageView(getContext()); divider.setBackgroundResource(android.R.drawable.divider_horizontal_bright); mediaLayout.addDivider(divider); } buttonLayout.addView(mediaLayout); } } buttonLayout.setOrientation(LinearLayout.VERTICAL); // The buttons take up the right half of the screen LayoutParams buttonParams = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT); addView(buttonLayout, buttonParams); }
/** * 加载每一行的单选按钮 * * @param layoutMain * @param line * @param lineNum */ private void addLine( LinearLayout layoutMain, int line, int lineNum, int isDanNum, int danTeamNum, int teamNum, final boolean isBeijing) { LinearLayout layoutOne = new LinearLayout(context); int id = 0; int last = getNum(teamNum - 1, true); boolean isCheck = isLastCheck(teamNum, danTeamNum); for (int j = 0; j < lineNum; j++) { id = line * this.LineNum + j; RadioButton radio = new RadioButton(context); if (id < isDanNum) { radio.setEnabled(false); radio.setTextColor(Color.GRAY); radio.setButtonDrawable(R.drawable.radio_select); } else if (!isCheck && id >= last) { radio.setEnabled(false); radio.setTextColor(Color.GRAY); radio.setButtonDrawable(R.drawable.radio_select); } else { radio.setTextColor(Color.BLACK); radio.setButtonDrawable(R.drawable.radio_select); } if (isBeijing) { radio.setText(beijingTextId[id]); } else { radio.setText(radioTextId[id]); } int width = PublicMethod.getDisplayWidth(context); if (width == 720) { radio.setTextSize(PublicMethod.getPxInt(7, context)); } else if (width == 640) { radio.setTextSize(PublicMethod.getPxInt(7, context)); } else if (width == 240) { radio.setTextSize(PublicMethod.getPxInt(20, context)); } else if (width == 320) { radio.setTextSize(PublicMethod.getPxInt(15, context)); } else if (width == 800) { radio.setTextSize(PublicMethod.getPxInt(8, context)); } else { radio.setTextSize(PublicMethod.getPxInt(10, context)); } if (Constants.SCREEN_HEIGHT == 854) { radio.setTextSize(PublicMethod.getPxInt(8, context)); } radio.setId(id); radio.setPadding(PublicMethod.getPxInt(20, context), 0, 0, 0); int withPx = PublicMethod.getPxInt(75, context); // 将dip换算成px radio.setLayoutParams(new LayoutParams(withPx, LayoutParams.WRAP_CONTENT)); radio.setOnCheckedChangeListener( new OnCheckedChangeListener() { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { if (isBeijing) { ((BeiJingSingleGameIndentActivity) context).bettingNum = getBeijingRadioZhu(buttonView.getText().toString()); ((BeiJingSingleGameIndentActivity) context).setBettingInformationShow(); } else { touzhuDialog.zhuShu = getRadioZhu(buttonView.getText().toString()); touzhuDialog.setAlertText(); setRadioPrize(buttonView.getText().toString()); } clearRadio(buttonView); } } }); radioBtns.add(radio); layoutOne.addView(radio); } layoutMain.addView(layoutOne); }
private void TabloDoldur() { try { Integer count = 0; YeDatabase db = new YeDatabase(this); final ObDataBase yDb = new ObDataBase(this); db.open(); final Cursor cursor = db.QueryTbDataBases(); tlResults.removeAllViews(); while (cursor.moveToNext()) { yDb.ID = cursor.getInt(0); yDb.Name = cursor.getString(1); yDb.Instance = cursor.getString(2); yDb.Ip = cursor.getString(3); yDb.Port = cursor.getString(4); yDb.User = cursor.getString(5); yDb.Pass = cursor.getString(6); yDb.InUse = cursor.getInt(7); yDb.Description = cursor.getString(8); LayoutInflater inflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE); TableRow tr = (TableRow) inflater.inflate(R.layout.satir, null); tr.setId(100 + count); tr.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)); TextView labelDesc = new TextView(this, null, R.style.BodyText); labelDesc.setId(200 + count); labelDesc.setText(yDb.Description); tr.addView(labelDesc); TextView labelIp = new TextView(this, null, R.style.BodyText); labelIp.setId(200 + count); labelIp.setText(yDb.Ip); tr.addView(labelIp); TextView labelName = new TextView(this); labelName.setId(200 + count); labelName.setText(yDb.Name); tr.addView(labelName); RadioButton labelInUse = new RadioButton(this); labelInUse.setId(200 + count); labelInUse.setTag(200 + ""); labelInUse.setGravity(Gravity.CENTER_VERTICAL); labelInUse.setGravity(Gravity.CENTER_HORIZONTAL); labelInUse.setEnabled(false); // rdgActiveData.addView(labelInUse); if (yDb.InUse == 1) labelInUse.setChecked(true); else labelInUse.setChecked(false); tr.addView(labelInUse); tlResults.addView( tr, new TableLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)); count++; tr.setOnClickListener( new OnClickListener() { @Override public void onClick(View view) { DetayDoldur((TableRow) view); } }); tr.setOnLongClickListener( new OnLongClickListener() { @Override public boolean onLongClick(View v) { SetAktifVeriTabani((TableRow) v); return true; } }); } } catch (Exception e) { Toast.makeText(this, "detay göster" + e.getMessage(), Toast.LENGTH_LONG).show(); } }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_quiz); final TextView qNo = (TextView) findViewById(R.id.textViewQuesNo); ques = (TextView) findViewById(R.id.textViewQuestion); rgOptions = (RadioGroup) findViewById(R.id.radioGroupOptions); Button nextBtn = (Button) findViewById(R.id.buttonStartQuiz); quesImage = (ImageView) findViewById(R.id.imageViewQuizQues); spinner = (ProgressBar) findViewById(R.id.progressBarLoadingImage); spinner.setVisibility(View.GONE); questionArrayList = getIntent().getParcelableArrayListExtra("QuestionList"); final ArrayList<String> questions = new ArrayList<String>(); final ArrayList<String> imageUrls = new ArrayList<String>(); for (final Question q : questionArrayList) { for (int k = 0; k < q.getHashMap().keySet().size(); k++) { questions.add(q.getHashMap().keySet().iterator().next().toString()); if (q.getImageUrl() != null) { imageUrls.add(q.getImageUrl()); } else if (q.getImageUrl() == null) { imageUrls.add("null"); } } } qNo.setText(String.format("Q%s", String.valueOf(index + 1))); ques.setText(questions.get(0)); new GetImageAsyncTask().execute(imageUrls.get(0)); // Log.d("Questions Array", // questionArrayList.get(0).getOptionsList(questions.get(0)).toString()); for (int kk = 0; kk < questionArrayList.get(0).getScores().length; kk++) Log.d("Question 0 Score", questionArrayList.get(0).getScores()[kk].toString()); ques.setText(questions.get(0)); ArrayList<String> optionsArray = questionArrayList.get(0).getOptionsList(questions.get(0)); HashMap<String, Integer> keyVal = new HashMap<String, Integer>(); for (int i = 0; i < optionsArray.size(); i++) { keyVal.put(optionsArray.get(i), Integer.valueOf(questionArrayList.get(0).getScores()[i])); } List<Map.Entry<String, Integer>> list = new ArrayList<Map.Entry<String, Integer>>(keyVal.entrySet()); Collections.shuffle(list); int n = 0; for (Map.Entry<String, Integer> entry : list) { Log.d("Key: " + entry.getKey(), "Value: " + entry.getValue()); RadioButton button = new RadioButton(this); button.setId(entry.getValue()); button.setText(entry.getKey()); rgOptions.addView(button); n++; } findViewById(R.id.buttonQuit) .setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { finish(); Intent i = new Intent(Quiz.this, Welcome.class); startActivity(i); } }); /* for (int k = 0; k < optionsArray.size(); k++) { RadioButton button = new RadioButton(this); button.setId(k); button.setText(optionsArray.get(k)); rgOptions.addView(button); }*/ /*Code below this is debugging purpose only you can see how questions and options and *all things are being retrieved*/ /* int i=0; // questionArrayList for(Question q : questionArrayList) { for(Object S:q.getHashMap().keySet() ) { Log.d("Quiz Question: " + i, S.toString()); if(q.getImageUrl()!=null) Log.d("Quiz Questions" + i + "Image Url", q.getImageUrl()); ArrayList<String> OptionsNScores= q.getOptionsList(S); for(int j=0;j<OptionsNScores.size();j++){ Log.d("Quiz options for Q:" + i, OptionsNScores.get(j).toString()); } } i++; }//Debug code ends here*/ nextBtn.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { if (index < questions.size() && (index + 1) != questions.size()) { if (rgOptions.getCheckedRadioButtonId() == -1) { Toast.makeText(Quiz.this, "Please select an option..", Toast.LENGTH_LONG).show(); } else if (rgOptions.getCheckedRadioButtonId() != -1) { rgOptions.setOnCheckedChangeListener( new RadioGroup.OnCheckedChangeListener() { @Override public void onCheckedChanged(RadioGroup group, int checkedId) { if (checkedId == -1) { // Toast.makeText(Quiz.this, "Please select an option..", // Toast.LENGTH_LONG).show(); } else { Log.d("Index: ", String.valueOf(index)); // if (checkedId != -1) { // value = // Integer.parseInt(questionArrayList.get(index).getScores()[checkedId]); value = checkedId; Log.d("Score value for id: " + checkedId, String.valueOf(value)); } // checkedId = -1; // } } }); score = score + value; Log.d("Score: ", String.valueOf(score)); rgOptions.clearCheck(); rgOptions.removeAllViews(); index++; qNo.setText(String.format("Q%s", String.valueOf(index + 1))); if (!imageUrls.get(index).equalsIgnoreCase("null")) new GetImageAsyncTask().execute(imageUrls.get(index)); else // if(imageUrls.get(index).equalsIgnoreCase("null")) quesImage.setImageBitmap(null); ques.setText(questions.get(index)); /* ArrayList<String> optionsArray = questionArrayList.get(index).getOptionsList(questions.get(index)); for (int k = 0; k < optionsArray.size(); k++) { RadioButton button = new RadioButton(Quiz.this); button.setId(k); button.setText(optionsArray.get(k)); rgOptions.addView(button); }*/ HashMap<String, Integer> keyVal = new HashMap<String, Integer>(); ArrayList<String> optionsArray = questionArrayList.get(index).getOptionsList(questions.get(index)); for (int i = 0; i < optionsArray.size(); i++) { keyVal.put( optionsArray.get(i), Integer.valueOf(questionArrayList.get(index).getScores()[i])); } List<Map.Entry<String, Integer>> list = new ArrayList<Map.Entry<String, Integer>>(keyVal.entrySet()); Collections.shuffle(list); int n = 0; for (Map.Entry<String, Integer> entry : list) { Log.d("Key: " + entry.getKey(), "Value: " + entry.getValue()); RadioButton button = new RadioButton(Quiz.this); button.setId(entry.getValue()); button.setText(entry.getKey()); rgOptions.addView(button); n++; } } } else { Intent intent = new Intent(Quiz.this, Result.class); intent.putExtra("Score", score); startActivity(intent); finish(); } // } } }); }
public SelectOneAutoAdvanceWidget(Context context, FormEntryPrompt prompt) { super(context, prompt); LayoutInflater inflater = LayoutInflater.from(getContext()); // SurveyCTO-added support for dynamic select content (from .csv files) XPathFuncExpr xPathFuncExpr = ExternalDataUtil.getSearchXPathExpression(prompt.getAppearanceHint()); if (xPathFuncExpr != null) { mItems = ExternalDataUtil.populateExternalChoices(prompt, xPathFuncExpr); } else { mItems = prompt.getSelectChoices(); } buttons = new ArrayList<RadioButton>(); listener = (AdvanceToNextListener) context; String s = null; if (prompt.getAnswerValue() != null) { s = ((Selection) prompt.getAnswerValue().getValue()).getValue(); } // use this for recycle Bitmap b = BitmapFactory.decodeResource(getContext().getResources(), R.drawable.expander_ic_right); if (mItems != null) { for (int i = 0; i < mItems.size(); i++) { RelativeLayout thisParentLayout = (RelativeLayout) inflater.inflate(R.layout.quick_select_layout, null); LinearLayout questionLayout = (LinearLayout) thisParentLayout.getChildAt(0); ImageView rightArrow = (ImageView) thisParentLayout.getChildAt(1); RadioButton r = new RadioButton(getContext()); r.setText(prompt.getSelectChoiceText(mItems.get(i))); r.setTextSize(TypedValue.COMPLEX_UNIT_DIP, mAnswerFontsize); r.setTag(Integer.valueOf(i)); r.setId(QuestionWidget.newUniqueId()); r.setEnabled(!prompt.isReadOnly()); r.setFocusable(!prompt.isReadOnly()); rightArrow.setImageBitmap(b); buttons.add(r); if (mItems.get(i).getValue().equals(s)) { r.setChecked(true); } r.setOnCheckedChangeListener(this); String audioURI = null; audioURI = prompt.getSpecialFormSelectChoiceText(mItems.get(i), FormEntryCaption.TEXT_FORM_AUDIO); String imageURI; if (mItems.get(i) instanceof ExternalSelectChoice) { imageURI = ((ExternalSelectChoice) mItems.get(i)).getImage(); } else { imageURI = prompt.getSpecialFormSelectChoiceText( mItems.get(i), FormEntryCaption.TEXT_FORM_IMAGE); } String videoURI = null; videoURI = prompt.getSpecialFormSelectChoiceText(mItems.get(i), "video"); String bigImageURI = null; bigImageURI = prompt.getSpecialFormSelectChoiceText(mItems.get(i), "big-image"); MediaLayout mediaLayout = new MediaLayout(getContext()); mediaLayout.setAVT(prompt.getIndex(), "", r, audioURI, imageURI, videoURI, bigImageURI); if (i != mItems.size() - 1) { // Last, add the dividing line (except for the last element) ImageView divider = new ImageView(getContext()); divider.setBackgroundResource(android.R.drawable.divider_horizontal_bright); mediaLayout.addDivider(divider); } questionLayout.addView(mediaLayout); addView(thisParentLayout); } } }
public void addView(int type) { book_count++; act_count++; set_flag[book_count] = type; final EditText name, author, quantity, edition, isbn; ImageView cancel; RadioGroup radioGroup; Button plus_btn, minus_btn; RadioButton radio_new, radio_old; AwesomeTextView link; View v = LayoutInflater.from(context).inflate(R.layout.books_edittext, linearLayout, false); name = (EditText) v.findViewById(R.id.bookname_edittxt); isbn = (EditText) v.findViewById(R.id.isbn_edittxt); author = (EditText) v.findViewById(R.id.bookauthor_edittxt); cancel = (ImageView) v.findViewById(R.id.cancel_action); radioGroup = (RadioGroup) v.findViewById(R.id.radio_group); quantity = (EditText) v.findViewById(R.id.quantity_edittext); edition = (EditText) v.findViewById(R.id.bookedition_edittxt); plus_btn = (Button) v.findViewById(R.id.plus_button); minus_btn = (Button) v.findViewById(R.id.minus_button); radio_new = (RadioButton) v.findViewById(R.id.radio_btn_new); radio_old = (RadioButton) v.findViewById(R.id.radio_btn_old); link = (AwesomeTextView) v.findViewById(R.id.link_textview); link.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { String url = "https://www.google.co.in/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q=isbn"; Intent i = new Intent(Intent.ACTION_VIEW); i.setData(Uri.parse(url)); i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); v.getContext().startActivity(i); } }); if (type == 1) { radioGroup.setVisibility(View.VISIBLE); link.setVisibility(View.VISIBLE); } else if (type == 2) { name.setHint("Stationary Title"); author.setHint("Stationary Description"); name.setInputType( InputType.TYPE_TEXT_FLAG_MULTI_LINE | InputType.TYPE_TEXT_FLAG_CAP_SENTENCES); edition.setVisibility(View.GONE); isbn.setVisibility(View.GONE); } else if (type == 3) { name.setHint("Description.."); name.setInputType( InputType.TYPE_TEXT_FLAG_MULTI_LINE | InputType.TYPE_TEXT_FLAG_CAP_SENTENCES); author.setVisibility(View.GONE); edition.setVisibility(View.GONE); isbn.setVisibility(View.GONE); } v.setId(9000 + book_count); name.setId(1000 + book_count); author.setId(2000 + book_count); cancel.setId(3000 + book_count); quantity.setId(4000 + book_count); radio_new.setId(5000 + book_count); radio_old.setId(6000 + book_count); edition.setId(7000 + book_count); isbn.setId(8000 + book_count); name.requestFocus(); cancel.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View vi) { int id = vi.getId(); // Toast.makeText(context,"cancelled"+id,Toast.LENGTH_SHORT).show(); View v = linearLayout.findViewById(id - 3000 + 9000); linearLayout.removeView(v); set_flag[id - 3000] = 0; act_count--; } }); plus_btn.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { if (quantity.getText().toString().length() == 0) { quantity.setText("1"); return; } int x = Integer.parseInt(quantity.getText().toString()); x++; quantity.setText(x + ""); } }); minus_btn.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { if (quantity.getText().toString().length() == 0) { quantity.setText("1"); return; } int x = Integer.parseInt(quantity.getText().toString()); x--; if (x < 1) { quantity.setText("1"); return; } quantity.setText(x + ""); } }); linearLayout.addView(v); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_rupmiembros_g); context = this; btnNext = (ImageButton) findViewById(R.id.btnSiguiente); btnBack = (ImageButton) findViewById(R.id.btnAtras); rgOcupacion = (RadioGroup) findViewById(R.id.rgOcupacion); rgMotivoNoTrabajo = (RadioGroup) findViewById(R.id.rgMotivoNoTrabajo); conecciondb = new ConnectionDB(context); ArrayList<Ocupaciones> ocupacionesArrayList = conecciondb.getOcupaciones(); for (int i = 0; i < ocupacionesArrayList.size(); i++) { RadioButton radioButton = new RadioButton(this); radioButton.setText( ocupacionesArrayList.get(i).CodigoOcupacion + ". " + ocupacionesArrayList.get(i).DescripcionOcupacion); radioButton.setId(Integer.valueOf(ocupacionesArrayList.get(i).IdOcupacion)); rgOcupacion.addView(radioButton); } ArrayList<RazonesNoTrabajo> razonesArrayList = conecciondb.getRazonesNoTrabajo(); for (int i = 0; i < razonesArrayList.size(); i++) { RadioButton radioButton = new RadioButton(this); radioButton.setText( razonesArrayList.get(i).CodigoRazonNoTrabajo + ". " + razonesArrayList.get(i).DescripcionRazonNoTrabajo); radioButton.setId(Integer.valueOf(razonesArrayList.get(i).IdRazonNoTrabajo)); rgMotivoNoTrabajo.addView(radioButton); } Intent mIntent = getIntent(); if (mIntent.getSerializableExtra("User") != null) { User = (Usuario) mIntent.getSerializableExtra("User"); } if (mIntent.getSerializableExtra("FSU") == null) { Ficha = new RUP(); } else { Ficha = (RUP) mIntent.getSerializableExtra("FSU"); } if (mIntent.getSerializableExtra("Miembro") == null) { miembrohogar = new Miembros(); } else { miembrohogar = (Miembros) mIntent.getSerializableExtra("Miembro"); if (miembrohogar.IdOcupacion != null) { if (miembrohogar.EdadAnios != null) { if (miembrohogar.EdadAnios >= 5) { for (int i = 0; i < rgOcupacion.getChildCount(); i++) { rgOcupacion.getChildAt(i).setEnabled(true); } for (int i = 0; i < rgMotivoNoTrabajo.getChildCount(); i++) { rgMotivoNoTrabajo.getChildAt(i).setEnabled(true); } } else { for (int i = 0; i < rgOcupacion.getChildCount(); i++) { rgOcupacion.getChildAt(i).setEnabled(false); } for (int i = 0; i < rgMotivoNoTrabajo.getChildCount(); i++) { rgMotivoNoTrabajo.getChildAt(i).setEnabled(false); } } } rgOcupacion.check(miembrohogar.IdOcupacion); if (conecciondb.getCodigoOcupacionesById(miembrohogar.IdOcupacion) == 5 || conecciondb.getCodigoOcupacionesById(miembrohogar.IdOcupacion) == 11 || conecciondb.getCodigoOcupacionesById(miembrohogar.IdOcupacion) == 13) { for (int i = 0; i < rgMotivoNoTrabajo.getChildCount(); i++) { rgMotivoNoTrabajo.getChildAt(i).setEnabled(true); } } else { for (int i = 0; i < rgMotivoNoTrabajo.getChildCount(); i++) { rgMotivoNoTrabajo.getChildAt(i).setEnabled(false); } } } else { if (miembrohogar.EdadAnios != null) { if (miembrohogar.EdadAnios <= 4) { for (int i = 0; i < rgOcupacion.getChildCount(); i++) { rgOcupacion.getChildAt(i).setEnabled(false); } for (int i = 0; i < rgMotivoNoTrabajo.getChildCount(); i++) { rgMotivoNoTrabajo.getChildAt(i).setEnabled(false); } } } } if (miembrohogar.IdMotivoNoTrabajar != null) { rgMotivoNoTrabajo.check(miembrohogar.IdMotivoNoTrabajar); } if (Ficha.TipoFicha == 5) { for (int j = 0; j < rgOcupacion.getChildCount(); j++) { rgOcupacion.getChildAt(j).setEnabled(false); } for (int j = 0; j < rgMotivoNoTrabajo.getChildCount(); j++) { rgMotivoNoTrabajo.getChildAt(j).setEnabled(false); } } } rgOcupacion.setOnCheckedChangeListener( new RadioGroup.OnCheckedChangeListener() { @Override public void onCheckedChanged(RadioGroup group, int checkedId) { if (conecciondb.getCodigoOcupacionesById(checkedId) == 5 || conecciondb.getCodigoOcupacionesById(checkedId) == 11 || conecciondb.getCodigoOcupacionesById(checkedId) == 12) { for (int i = 0; i < rgMotivoNoTrabajo.getChildCount(); i++) { rgMotivoNoTrabajo.getChildAt(i).setEnabled(true); } } else { rgMotivoNoTrabajo.clearCheck(); for (int i = 0; i < rgMotivoNoTrabajo.getChildCount(); i++) { rgMotivoNoTrabajo.getChildAt(i).setEnabled(false); } } } }); btnBack.setOnClickListener( new View.OnClickListener() { public void onClick(View v) { if (Ficha.TipoFicha == 1 || Ficha.TipoFicha == 6) { // Nuevas Fichas addParameters(); Intent intent = new Intent(context, RUPMiembrosF.class); intent.putExtra("FSU", Ficha); intent.putExtra("Miembro", miembrohogar); intent.putExtra("User", User); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(intent); context.finish(); overridePendingTransition(R.anim.fadeinback, R.anim.fadeout); } if (Ficha.TipoFicha == 5) { // Ficha Visualización Intent intent = new Intent(context, RUPMiembrosF.class); intent.putExtra("FSU", Ficha); intent.putExtra("Miembro", miembrohogar); intent.putExtra("User", User); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(intent); context.finish(); overridePendingTransition(R.anim.fadeinback, R.anim.fadeout); } } }); btnNext.setOnClickListener( new View.OnClickListener() { public void onClick(View v) { if (Ficha.TipoFicha == 1 || Ficha.TipoFicha == 6) { // Nuevas Fichas if (validar()) { addParameters(); Intent intent = new Intent(context, RUPMiembrosH.class); intent.putExtra("FSU", Ficha); intent.putExtra("Miembro", miembrohogar); intent.putExtra("User", User); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(intent); context.finish(); overridePendingTransition(R.anim.fadein, R.anim.fadeout); } } if (Ficha.TipoFicha == 5) { // Ficha Visualización Intent intent = new Intent(context, RUPMiembrosH.class); intent.putExtra("FSU", Ficha); intent.putExtra("Miembro", miembrohogar); intent.putExtra("User", User); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(intent); context.finish(); overridePendingTransition(R.anim.fadein, R.anim.fadeout); } } }); }
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