Android CheckBox问题 [英] Android CheckBox Issue

查看:75
本文介绍了Android CheckBox问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作一个测验应用程序。我有两个类问题的ArrayList,一个是英语,另一个是其他任何语言。我以编程方式将复选框添加到视图中,但是当我单击英语语言中的一个复选框时,我想要这样做,另一个ArrayList中的另一个复选框也被选中。

我可以得到这个使用RadioButton工作,因为他们在RadioGroup,但Checkboxes有点问题。任何帮助将不胜感激



这是我的代码



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

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);
		}
		
	}; 

推荐答案

您是否需要2个ArrayLists,或者您想提供2种语言?

秒您应该考虑本地化( Android本地化)(通常也称为i18n或国际化)。



在另一种情况下:您正在设置复制复选框的值。不是真实的。
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.


这篇关于Android CheckBox问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆