Im doing an App on Android Studio and im trying to add all my checkbox IDs into an array, so i can use it , without doing it manually. I tried to do it on another way, but i didn´t find nothing on google that help me,
So here is my goal:
I want to get all my Checkbox ids, so i can get their text. And i don´t want to do it manually because i got alot of checkboxs.
I tried to write a code by myself but i´m getting an message error. Here is my code:
CheckBox[] MinhaCheckBox;
SharedPreferences Dados;
String MinhaPasta = "Pasta";
String valor;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void btn_Gerar(View v)
{
Dados = getSharedPreferences(MinhaPasta,0);
SharedPreferences.Editor Edita = Dados.edit();
int IDTexBoz[] = {R.id.checkBox,R.id.checkBox2,R.id.checkBox3,R.id.checkBox4,R.id.checkBox5,
R.id.checkBox6,R.id.checkBox7,R.id.checkBox8};
for(int i = 0 ; i < IDTexBoz.length; i++)
{
*//I GOT AN ERRO HERE. please help me.*
* // when i try to put mycheckbox on my array, i got th error!*
MinhaCheckBox[i] = (CheckBox)findViewById(IDTexBoz[i]);
}
for (int a= 0; a < MinhaCheckBox.length;a++)
{
if(MinhaCheckBox[a].isChecked())
valor += MinhaCheckBox[a].getText().toString() + ";";
}
Edita.putString("Dado", valor);
Edita.commit();
Intent MeuIntent = new Intent(this,Main2Activity.class);
startActivity(MeuIntent);
}
}
Aucun commentaire:
Enregistrer un commentaire