Reputation: 3
I have one activity with 5 buttons. Each button should show up one activity (total 5 different activities). I tried many methods for multiple buttons but my app does not work. The first button of the activity starts its linked activity without any problem (btEtiologia and the activity is Etiology), but the second button still won't show up, and returns to the Main Activity (that is home layout). When I restart the app, I try with the second button, and third buttons and works, but the fourth button won´t show up and returns to the main activity. I have dowloaded the app on a samsung galaxy S2 and is the same than emulator. ¿Is anything wrong with my code?
Here is the java code of Inicio:
package com.example.protesis;
import android.support.v7.app.ActionBarActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
public class Inicio extends ActionBarActivity implements View.OnClickListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_inicio);
Button btInformacion = (Button) findViewById(R.id.btInformacion);
btInformacion.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Toast.makeText(getBaseContext(), "Esta aplicación esta basada en el manejo de las infecciones de prótesis articulares de la IDSA", Toast.LENGTH_SHORT).show();
}
});
findViewById(R.id.btEtiologia).setOnClickListener(this);
findViewById(R.id.btAlgoritmo).setOnClickListener(this);
findViewById(R.id.btAntibioiv).setOnClickListener(this);
findViewById(R.id.btAntibioral).setOnClickListener(this);
findViewById(R.id.btRetirada).setOnClickListener(this);
}
public void onClick(View arg0){
// create a general intent
Intent intent = null;
// define an intent for all cases
switch(arg0.getId()){
case R.id.btEtiologia:
// Setting intent for first button
intent = new Intent(this,Etiology.class);
break;
case R.id.btAlgoritmo:
// Setting intent for second button
intent = new Intent(this,Algoritmo.class);
break;
case R.id.btAntibioiv:
// Setting intent for third button
intent = new Intent(this,Antibioiv.class);
break;
case R.id.btAntibioral:
// Setting intent for fourth button
intent = new Intent(this,Antibioral.class);
break;
case R.id.btRetirada:
// Setting intent for fourth button
intent = new Intent(this,Retirada.class);
break;
}
this.startActivity(intent);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.inicio, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
The main activity code is:
package com.example.protesis;
import android.support.v7.app.ActionBarActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
public class MainActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button btInicio = (Button) findViewById(R.id.btInicio);
btInicio.setOnClickListener(new View.OnClickListener(){
public void onClick(View v) {
Intent intent = new Intent(v.getContext(), Inicio.class);
startActivityForResult(intent, 0);
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
Upvotes: 0
Views: 132
Reputation: 711
As per you code, your images are dragging the code to OutOfMemory exception. Though the images which you are using of 120 dpi, their size is double to 640*480. please change image sizes then the problem will be solved. I have changed the all the 5 image sizes and now i am able to navigate to all the screens by clicking the buttons. Make the images to around 640*480 in ldpi folder.
Upvotes: 1