大家好我是Java的新手,我正在开发一个平板电脑系统,我在使用ListView时遇到了麻烦。我的ListView有1个带3个RadioButton,RadioGroup携带来自SqlLite的数据,好在那里可以,我随身携带带有windgets的列表和我想要的数据,我通常可以选择RadioButton。 问题是,我想在数据库中保存RadioButton的内容和项目ID,因此选择了RadioButton。
lvPerguntas = (ListView)findViewById(R.id.lvPergunta);
mPerguntasList = new ArrayList<>();
Cursor cPerguntas = DataBase.db.rawQuery("SELECT * FROM tbPerguntas WHERE Id_Topico='"+IdTopico+"'",null);
while (cPerguntas.moveToNext()){
mPerguntasList.add(new Itens_Perguntas(cPerguntas.getInt(0), cPerguntas.getString(2)));
}
adapter = new Adapter_Perguntas(getApplicationContext(), mPerguntasList);
lvPerguntas.setAdapter(adapter);
rg = (RadioGroup)findViewById(R.id.GroupResposta);
lvPerguntas.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, final int position, long id) {
rg.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
switch (checkedId) {
case R.id.rbConforme:
DataBase.db.execSQL("UPDATE tbDados SET Test='"+position+"Conforme' WHERE Id_Dado='1';");
break;
case R.id.rbNConforme:
DataBase.db.execSQL("UPDATE tbDados SET Test='"+position+"Não Conforme' WHERE Id_Dado='1';");
break;
case R.id.rbNAplica:
DataBase.db.execSQL("UPDATE tbDados SET Test='"+position+"Não se aplica' WHERE Id_Dado='1';");
break;
}
}
});
}
});