I would like values to be assigned to a variable according to the selection of a given CheckBox in my project.
In an example. If the first checkbox was selected, the following variable was assigned: cont+=1.
If the second checkbox was selected, the following variable would be assigned: cont+=2
.
With this in the other activity a condition based on the value of the cont variable would be displayed.
se cont==1
then a textview was created appearing a certain text and se cont==2
appeared another textview with another text:
NowIwouldalsolikethatifyouselectasecondcheckbox(oneofthetwointhebottompart,"employee" or "unemployed"), in the following activity a new textview is created with the following content appearing:
NotethatIcannotuseasingletextviewwiththe2textsjoined(insequence).
Codes:
MainActivity.java
package genesysgeneration.stack;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
public class MainActivity extends AppCompatActivity implements View.OnClickListener{
public int cont=0;
private Button btnNext;
private CheckBox cbCasado, cbSolteiro, cbEmpregado, cbDesempregado;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btnNext=(Button)findViewById(R.id.btnNext);
btnNext.setOnClickListener(this);
}
public void onClick(View v){
Intent it = new Intent(this, Main2Activity.class);
startActivity(it);
}
}