Click here to Skip to main content
15,891,567 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am making a quiz app.I have two ArrayList of class Questions one is in English and one in any other language. I am adding checkboxes programatically on to a view, but what I want to do it when I click on one checkbox from English Language another checkbox from the other ArrayList gets selected as well.
I can get this to work when working with RadioButton as they are in RadioGroup but Checkboxes are bit of an issue. Any help would be appreciated

Here is my code

Java
private void ShowForeignLanguage(cQuestions toQuestions) {
		
		
		
		TextView t=(TextView)findViewById(R.id.tb_fQuestion);
		t.setText(toQuestions.getS_QText());
		String sQuesType = toQuestions.getS_QuesType().toString();
		List<cOptions> tOptions  =  toQuestions.getL_Options();
					
		if(sQuesType.equals("Multiple"))
		{
			ArrayList<cOptions> alFor =  (ArrayList)tOptions;  			
			CheckBox[] cbOption  =  new CheckBox[tOptions.size()];
			
			
			for(int i= 0;i<tOptions.size();i++)
			{										
				cbOption[i] =  new CheckBox(this);
				cbOption[i].setText(tOptions.get(i).getsOptionsText());				
				cbOption[i].setId(i);				
				cbOption[i].setOnCheckedChangeListener(cbFChecked_Listner);					
				lforeignLayout.addView(cbOption[i]
						);
			}					
		}
	}
	
	
	private android.widget.CompoundButton.OnCheckedChangeListener cbFChecked_Listner  =  new android.widget.CompoundButton.OnCheckedChangeListener()
	{
		@Override
		public void onCheckedChanged(CompoundButton selectedcBox, boolean isChecked) {
			
			int i_Selected  = selectedcBox.getId();
			//((CheckBox)llocalLayout.getChildAt(i_Selected)).setSelected(isChecked);
			CheckBox cb =  (CheckBox) llocalLayout.getChildAt(i_Selected);
			cb.setOnCheckedChangeListener(null);
			cb.setSelected(isChecked);						
			cb.setOnCheckedChangeListener(cbLChecked_Listner);
		}
		
	}; 
Posted

1 solution

Do you have 2 ArrayLists by need or because you want to provide 2 languages?
in second case you should figure the localization ( Android localization ) (also often called i18n or internationalization).

In the other case: you're setting the value of a copied checkbox. not the real one.
 
Share this answer
 
Comments
Chintu Chaudhary 28-May-13 4:49am    
I have two arraylists beacuse i want to provide two languages in one screen. So say on a screen a user will see questions in english on one side and in say french on the other side. Languages are predefined are not actually . Once the french reader sees the question and selects the appropriate reply checkbox.. the corresponding checkbox in english also gets selected automatically by a checkbox listner.
In other case how do it set it to the real one ?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900