Define setContentView with variable - java

I'm newbie in android, and i'm trying to receive a variable through the Intent function, and according the and depending on the value of the variable is supposed to show a contentview.
Bundle parametros = getIntent().getExtras();
String type = parametros.getString("tipo");
int accao = parametros.getInt("accao");
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (type=="medicamentos") {
Button voltar = (Button) findViewById(R.id.button1);
voltar.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Intent medIntent = new Intent(view.getContext(), Listar.class);
startActivityForResult(medIntent, 0);
}
});
if (accao==1)
setContentView(R.layout.adicionar_medicamentos);
if (accao==2)
setContentView(R.layout.editar_medicamentos);
}
}
What i'm doing wrong? Thanks

protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
String type = getIntent().getString("tipo");
int accao = getIntent().getInt("accao");
if (type != null && type.equals("medicamentos")) {
Button voltar = (Button) findViewById(R.id.button1);
voltar.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Intent medIntent = new Intent(view.getContext(), Listar.class);
startActivityForResult(medIntent, 0);
}
});
if (accao==1)
setContentView(R.layout.adicionar_medicamentos);
if (accao==2)
setContentView(R.layout.editar_medicamentos);
}
}

Use equals() to compare the string.
== compares the Object references not their content.
if(type.equals("medicamentos")) {
....
}

Related

How to make an activity not reload/refresh every time I get into it?

I have an activity and I don't want it to reload every time I get into it. I want it to show the information which had the last time i got into it.
But I also want to have one Button in another activity that will refresh the other activity, so that when i get into it the information has changed. I say that the content changes because the activity show different recyclerviews everytime you get into it.
That is my MainActivity.java:
public class Comida extends AppCompatActivity implements Adaptador2.OnRecipeListener {
private RecyclerView recyclerView1;
List<Entidad2> listItems;
Adaptador2 adaptor;
private Entidad2 entidad1,entidad2,entidad3;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_comida);
recyclerView1 = findViewById(R.id.lv_1);
LinearLayoutManager layoutManager = new LinearLayoutManager(this);
layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
recyclerView1.setLayoutManager(layoutManager);
listItems = new ArrayList<>();
entidad1 = new Entidad2(R.drawable.calabacines_3, "Solomillo a la plancha", " 10 min.", 4, 20);
entidad2 = new Entidad2(R.drawable.patatas_deluxe_especiadas_70523_300_150, "Entrecot", " 15 min.", 2, 50);
entidad3 = new Entidad2(R.drawable.tomate, "Hamburguesa", " 2 min.", 5, 100);
listItems.add(entidad1);
listItems.add(entidad2);
listItems.add(entidad3);
adaptor = new Adaptador2(listItems, this);
recyclerView1.setAdapter(adaptor);
adaptor.notifyDataSetChanged();
pickEntidad();
}
#Override
public void OnRecipe(int priority) {
if (priority == 20) {
Intent in = new Intent(this, Solomillo.class);
startActivity(in);
}
if (priority == 50) {
Intent in = new Intent(this, Entrecot.class);
startActivity(in);
}
if (priority == 100) {
Intent in = new Intent(this, Hamburguesa.class);
startActivity(in);
}
}
private void pickEntidad(){
final int random = new Random().nextInt(101);
int priority1 = entidad1.getPriority();
int priority2 = entidad2.getPriority();
int priority3 = entidad3.getPriority();
listItems.clear();
if(random < priority1){
listItems.add(entidad1);
}else if(random < priority2){
listItems.add(entidad2);
}else if (random <= priority3){
listItems.add(entidad3);
}
adaptor.notifyDataSetChanged();
}
}
And that is my activityWithButton.java:
public class Menu extends AppCompatActivity {
Button boton_start;
Button boton_refresh;
Button boton_prueba;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_menu);
this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
boton_start=(Button) findViewById(R.id.boton_platos);
boton_refresh = (Button) findViewById(R.id.boton_cambiarmenu);
boton_prueba=(Button) findViewById(R.id.boton_menu);
boton_start.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent in = new Intent(Menu.this,Dishes.class);
startActivity(in);
}
});
boton_prueba.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent in = new Intent(Menu.this,Comida.class);
startActivity(in);
}
});
boton_prueba.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
//What to do?
}
});
}
}
Please help I don't know what to do.
Thanks
You have two fairly straight-forward options, SharedPreferences and SavedInstanceState.
SharedPreferences, you can access and save data anywhere context is available within your app assigning a key, value pair to any data to later be retreived. Generally you will want to save the data during certain lifecycle events such as onStop and retreive it somewhere else once the activity returns:
SharedPreferences prefs = context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE);
SharedPreferences.Editor editor = prefs.edit();
#Override
public void onStop() {
super.onStop();
editor.putString("key", "My string");
editor.commit();
}
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
String myValue = editor.getString("key");
}
SavedInstanceState, comes with the onCreate override method in your activities. Utilising the available override method onSaveInstanceState, pass in the required data when the activity is temprarily destroyed to be retreived on its recreation.
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (savedInstanceState != null) {
String myValue = savedInstanceState.getString("key");
}
}
#Override
public void onSaveInstanceState(Bundle outState) {
outState.putString("key", "My string");
super.onSaveInstanceState(outState);
}
Further reading https://developer.android.com/guide/components/activities/activity-lifecycle

Calling a method immediately after starting intent in android?

Starting Intent then calling Method?
In the two classes, the second one has a StartIntent. Right now it simply starts the intent to the first class. I am wanting to know if it is possible from that same onClickListener to essentially StartIntent for the first class as usual, but then immediately call the defaultMap() method within it.
Sometimes I want to simply start the intent normally, and other times I want to start the intent and then call that method. 1) therefore, I can't just make so that OnCreate of the first class it calls defaultMap, because i don't always want to call it. But also 2) I don't want to JUST call the defaultMap() class. I need to call the full class so that it runs through the onCreate functions THEN goes to the defaultMap
FIRST CLASS USED
public class Daily_Schedule extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_daily__schedule);
......
.......
......
}
public void defaultMap(){
......
.......
......
}
SECOND CLASS USED
public class InRouteDisplay extends AppCompatActivity implements OnMapReadyCallback {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_in_route_display);
home.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent myIntent = new Intent(InRouteDisplay.this, DailySchedule.class);
InRouteDisplay.this.startActivity(myIntent);
}
});
.....
....
.....
}
Try the following: Two ways: 1) Using putExtra() -------- 2) Using SharedPreferences
1)
Demo4.class:-----------
public class Demo4 extends AppCompatActivity {
private Button b;
private final String CALL_DEFAULT_MAP = "call_default_map";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_daily__schedule);
if(getIntent() != null) {//1
if(getIntent().getStringExtra(CALL_DEFAULT_MAP) != null) {
if (getIntent().getStringExtra(CALL_DEFAULT_MAP).equals("true")) {
defaultMap();
}
}
}
b = (Button) findViewById(R.id.b);
b.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent myIntent = new Intent(Demo4.this, Demo5.class);
finish();
startActivity(myIntent);
}
});
}
public void defaultMap() {
Toast.makeText(getApplicationContext(),"defaultMap()---called",Toast.LENGTH_LONG).show();
}
}
Demo5.class------
public class Demo5 extends AppCompatActivity {
private Button home;
private final String CALL_DEFAULT_MAP = "call_default_map";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_in_route_display);
home = (Button) findViewById(R.id.home);
home.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent myIntent = new Intent(Demo5.this, Demo4.class);
myIntent.putExtra(CALL_DEFAULT_MAP,"true");//1
finish();
startActivity(myIntent);
}
});
}
}
2)
Demo4.class---------
public class Demo4 extends AppCompatActivity {
private Button b;
private final String CALL_DEFAULT_MAP = "call_default_map";
private SharedPreferences p;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_daily__schedule);
p = getApplicationContext().getSharedPreferences("p_key",
0);//2
if(p != null){//2
if(p.getBoolean(CALL_DEFAULT_MAP , false)){
defaultMap();
}
}
b = (Button) findViewById(R.id.b);
b.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent myIntent = new Intent(Demo4.this, Demo5.class);
finish();
startActivity(myIntent);
}
});
}
public void defaultMap() {
setBoolean(CALL_DEFAULT_MAP , false);//2
Toast.makeText(getApplicationContext(),"defaultMap()---called",Toast.LENGTH_LONG).show();
}
public void setBoolean(String Name, boolean value)
{
if(p != null){
SharedPreferences.Editor editor = p.edit();
editor.putBoolean(Name, value);
editor.apply();
}
}
}
Demo5.class:----------------
public class Demo5 extends AppCompatActivity {
private Button home;
private final String CALL_DEFAULT_MAP = "call_default_map";
private SharedPreferences p;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_in_route_display);
p = getApplicationContext().getSharedPreferences("p_key",
0);
home = (Button) findViewById(R.id.home);
home.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
setBoolean(CALL_DEFAULT_MAP , true);//2
Intent myIntent = new Intent(Demo5.this, Demo4.class);
finish();
startActivity(myIntent);
}
});
}
public void setBoolean(String Name, boolean value)
{
if(p != null){
SharedPreferences.Editor editor = p.edit();
editor.putBoolean(Name, value);
editor.apply();
}
}
}
No. The sending class doesn't get an instance of the Activity to call it on. What you can do is set a parameter in the intent, USE_DEFAULT_MAP to 1. The activity you launch can look for that variable, and use that to know that it should call defaultMap.
Use if statement inside the Daily_Schedule activity and check the extra whether they are set or null. Use getIntent() method. check the answer of this
From InRouteDisplay activity pass the intent data using putextra before calling InRouteDisplay.this.startActivity(myIntent);
Use this link to how to putextra data to the intent
Use this link's answer to know how to putextra data to the intent

Opening next Activity

I have have a problem here with my code. I want to open the next Activity using submit button but I'm having issues. Can anybody help me on the mistake I am making so that I can implement it? Thanks
public class Chairperson extends Activity implements View.OnClickListener{
TextView textView;
Button submit_btn;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_chairperson);
submit_btn = (Button) findViewById(R.id.submit_btn);
submit_btn.setOnClickListener(this);
textView = (TextView) findViewById(R.id.welcome_txt);
String message = getIntent().getStringExtra("message");
textView.setText(message);
Button submit_btn = (Button) findViewById(R.id.submit_btn);
final TextView submitTextView = (TextView) findViewById(R.id.submitTextView);
final RadioGroup rg1 = (RadioGroup) findViewById(R.id.rg1);
submit_btn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// Get the checked Radio Button ID from Radio Grou[
int selectedRadioButtonID = rg1.getCheckedRadioButtonId();
// If nothing is selected from Radio Group, then it return -1
if
(selectedRadioButtonID != -1) {
RadioButton selectedRadioButton = (RadioButton) findViewById(selectedRadioButtonID);
String selectedRadioButtonText = selectedRadioButton.getText().toString();
submitTextView.setText(selectedRadioButtonText + " selected.");
} else {
submitTextView.setText("Nothing selected .");
}
}
});
}
#Override
public void onClick(View v) {
startActivity(new Intent(this, ViceChairperson.class));
}
}
I have written a code for your button, delete all previous code for submit_btn in your code and replace with this
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addListenerOnButton();
public void addListenerOnButton() {
final Context context = this;
submit_btn = (Button) findViewById(R.id.submit_btn);
submit_btn.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
if (radioGroup.getCheckedRadioButtonId() == -1)
{
Toast.makeText(context, "Select an option.", Toast.LENGTH_LONG).show();
}
else{
Intent intent = new Intent(context, ViceChairperson.class);
startActivity(intent);
finish();
}
}
});
}
}
If you have any issues please let me know.
Just move the line
startActivity(new Intent(getApplicationContext(), ViceChairperson.class));
after the if (selectedRadioButtonID != -1) check. If that check succeeds you start the new activity, if not, nothing is launched.
There's no need for the second onClick method, which is not bound to anything and will never be invoked.

Get certain intents

So lets say i have 4 buttons , and each button contains an intent which navigates to an activity.They all navigate to a single same activity . When i click the first button i want that new activity to show "Hi" , When i click the second button i want it to show "Bye" and so on . How do i do that ?
Here is a simple code to start with
public class Intentt extends Activity {
Button b1,b2,b3,b4;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_intentt);
b1 = (Button)findViewById(R.id.button2);
b2 = (Button)findViewById(R.id.button3);
b3 = (Button)findViewById(R.id.button4);
b4 = (Button)findViewById(R.id.button5);
b1.setOnClickListener( new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent i = new Intent(Intentt.this,MainActivity.class);
startActivity(i);
}
});
b2.setOnClickListener( new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent i = new Intent(Intentt.this,MainActivity.class);
startActivity(i);
}
});
b3.setOnClickListener( new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent i = new Intent(Intentt.this,MainActivity.class);
startActivity(i);
}
});
b4.setOnClickListener( new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent i = new Intent(Intentt.this,MainActivity.class);
startActivity(i);
}
});
}
Just pass some data through intent extras, or intent extra Bundle:
Intent i=new Intent(context,MainActivity.class);
i.putExtra(id, 453);
context.startActivity(i);
Example:
Button b1, b2, b3, b4;
Context context = this;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_intentt);
b1 = (Button) findViewById(R.id.button2);
b2 = (Button) findViewById(R.id.button3);
b3 = (Button) findViewById(R.id.button4);
b4 = (Button) findViewById(R.id.button5);
b1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent i = new Intent(context, MainActivity.class);
i.putExtra(MainActivity.ID_ACTION, MainActivity.ACTION_1);
startActivity(i);
}
});
b2.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent i = new Intent(context, MainActivity.class);
i.putExtra(MainActivity.ID_ACTION, MainActivity.ACTION_2);
startActivity(i);
}
});
}
And then in that activity you can switch on that values getting them like that:
String id = intent.getStringExtra("id");
int id = intent.getIntExtra("id",-1);
and then use the if-elseif-else or switch statement(s) to change the actions based on the passed action, so you can display your messages
To properly recieve them you need to set activity's launchMode to "standard" because of this bug in AndroidManifest.xml and create
public static final int ACTION_1 = 1;
public static final int ACTION_2 = 2;
public static final int ACTION_NULL = -1;
public static final String ID_ACTION = "action_id";
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
int id = getIntent().getIntExtra(ID_ACTION, -1);
if (id == ACTION_NULL) {
Log.d("TAG", "id is null");
Toast.makeText(MainActivity.this, "id is null!", Toast.LENGTH_SHORT).show();
} else if (id == ACTION_1) {
Log.i("TAG", "ALLOHA! from button 1");
Toast.makeText(MainActivity.this, "Aloha from button 1!", Toast.LENGTH_LONG).show();
} else if (id == ACTION_2) {
Log.i("TAG", "Hello from button 2");
Toast.makeText(MainActivity.thi,"Hello from button 2!", Toast.LENGTH_LONG).show();
}
}
In each intent you could pass parameterts
Intent i=new Intent(context,SendMessage.class);
i.putExtra("KEY_MESSAGE", "Hola amigo");
In the other activity
Intent i = getIntent();
String message = i.getStringExtra("KEY_MESSAGE")
Toast.make(this,message,Toast.LENGTH_SHORT).show()
Re write the button click listener as follows :
b1.setOnClickListener( new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent i = new Intent(Intentt.this,MainActivity.class);
i.putExtra("Data","Hi");
startActivity(i);
}
});
b2.setOnClickListener( new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent i = new Intent(Intentt.this,MainActivity.class);
i.putExtra("Data","Hello");
startActivity(i);
}
});
b3.setOnClickListener( new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent i = new Intent(Intentt.this,MainActivity.class);
i.putExtra("Data","Bye");
startActivity(i);
}
});
b4.setOnClickListener( new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent i = new Intent(Intentt.this,MainActivity.class);
i.putExtra("Data","See you");
startActivity(i);
}
});
In your MainActivity class onCreate Method, you can access the passed data by :
String passedData = getIntent().getStringExtra("Data");
you can use this passedData to display on screen.
Do it like this:
public class Intentt extends Activity implements View.OnClickListener {
Button b1,b2,b3,b4;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_intentt);
b1 = (Button)findViewById(R.id.button2);
b2 = (Button)findViewById(R.id.button3);
b3 = (Button)findViewById(R.id.button4);
b4 = (Button)findViewById(R.id.button5);
b1.setOnClickListener(this);
b2.setOnClickListener(this);
b3.setOnClickListener(this);
b4.setOnClickListener(this);
}
#Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.button2:
Intent i = new Intent(Intentt.this,MainActivity.class);
i.putExtra('"STRING_I_NEED"', "Hi");
startActivity(i)
break;
case R.id.button3:
Intent i = new Intent(Intentt.this,MainActivity.class);
i.putExtra('"STRING_I_NEED"', "Bye");
startActivity(i)
break;
case R.id.button4:
break;
.
.
.
}
}
}
After that in your mainActivity retrieve string that you sent with:
Bundle extras = getIntent().getExtras();
String s = extras.getString("STRING_I_NEED");

Passing an integer from one .java class used within an IF statement to another .java class using an Intent

I am new to Android and I am trying to pass an integer value from one .java class to another using an Intent. The integer is declared within the first .java file and used within an IF statement to produce a score;
public class Diabetes_Question_1 extends Activity {
public int Total = 0;
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.diabetes_question_1);
Button btnBack = (Button) findViewById(R.id.btnBack1);
btnBack.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
startActivity(new Intent(Diabetes_Question_1.this, Diabetes_Question_2.class));
}
});
final RadioButton rb1 = (RadioButton) findViewById(R.id.btnDQ1Radio1);
final RadioButton rb2 = (RadioButton) findViewById(R.id.btnDQ1Radio2);
final RadioButton rb3 = (RadioButton) findViewById(R.id.btnDQ1Radio3);
Button btnNext = (Button) findViewById(R.id.btnNext1);
btnNext.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
if(rb1.isChecked()==true) {
Total = 1;
} else if (rb2.isChecked()==true) {
Total = 2;
} else if (rb3.isChecked()==true) {
Total = 3;
} else {
Total = 4;
}
Toast.makeText(Diabetes_Question_1.this, String.valueOf(Total), Toast.LENGTH_SHORT).show();
Intent i = new Intent(Diabetes_Question_1.this, Diabetes_Question_3.class);
i.putExtra("totalScore", Total);
startActivity(i);
}
});
}
}
Once this score has been produced I would like to pass it onto another .java class so the score can be added to based on the next IF statement;
public class Diabetes_Question_3 extends Activity {
Bundle extras = getIntent().getExtras();
int Total3 = extras.getInt("totalScore");
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.diabetes_question_3);
Button btnBack = (Button) findViewById(R.id.btnBack2);
btnBack.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
startActivity(new Intent(Diabetes_Question_3.this, Diabetes_Question_1.class));
}
});
final RadioButton rb1 = (RadioButton) findViewById(R.id.btnDQ3Radio1);
final RadioButton rb2 = (RadioButton) findViewById(R.id.btnDQ3Radio2);
final RadioButton rb3 = (RadioButton) findViewById(R.id.btnDQ3Radio3);
Button btnNext = (Button) findViewById(R.id.btnNext3);
btnNext.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
startActivity(new Intent(Diabetes_Question_3.this, Diabetes_Question_4.class));
if(rb1.isChecked()==true) {
Total3 = + 1;
} else if (rb2.isChecked()==true) {
Total3 = + 1;
} else if (rb3.isChecked()==true) {
Total3 = + 1;
} else {
Total3 = + 1;
}
Toast.makeText(Diabetes_Question_3.this, String.valueOf(Total3), Toast.LENGTH_SHORT).show();
}
});
}
}
I know the IF statement works as I have a toast to show this. However moving onto the next .java class is where the problem is and I am struggling to improve the code.
I am giving the following error message;
FATAL EXCEPTION: Main java.lang.RuntimeException: Unable to instantiate activity ComponentInfo {PACKAGE NAME} java.lang.NullPointerExcpetion
Any help will be greatly appreciated.
Put this.
Bundle extras = getIntent().getExtras();
int Total3 = extras.getInt("totalScore");
inside the onCreate method of Diabetes_Question_3 activity.
You should follow the naming convention of Java.
int total3 = 0; //Instance variable.
Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.diabetes_question_3);
.........
Bundle extras = getIntent().getExtras();
total3 = extras.getInt("totalScore");

Categories

Resources