The scenario I have now is, I am going to start 2 activity to get some String value, then on the 3rd activity, I will capture the String value and then I will compare the captured String and change the image source
example:
- choose programme
- choose day (monday~friday)
- captured the String pass from programme to day, and combine both and pass to activity with ImageView
once again i have edited the code.
1st activity
enter code here
public class TestSchedule extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_test_schedule);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.test_schedule, menu);
return true;
}
public void SSD(View view){
String programme = "SSD";
Intent intent = new Intent(TestSchedule.this,TextDay.class);
intent.putExtra("prog", programme);
startActivity(intent);
}
public void EIS(View view){
String programme = "EIS";
Intent intent = new Intent(TestSchedule.this,TextDay.class);
intent.putExtra("prog", programme);
startActivity(intent);
}
public void IS(View view){
String programme = "IS";
Intent intent = new Intent(TestSchedule.this,TextDay.class);
intent.putExtra("prog", programme);
startActivity(intent);
}
public void IT(View view){
String programme = "IT";
Intent intent = new Intent(TestSchedule.this,TextDay.class);
intent.putExtra("prog", programme);
startActivity(intent);
}
}
2nd activity
public class TextDay extends Activity {
String programme;
private void getData(){
Bundle extras = getIntent().getExtras();
if(extras != null){
programme = extras.getString("prog");
}
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_text_day);
getData();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.text_day, menu);
return true;
}
public void monday(View view){
if(programme.equals("SSD")){
String programDay = "SSDMon";
Intent intent = new Intent(TextDay.this, TestShow.class);
intent.putExtra("progDay", programDay);
startActivity(intent);
}
if(programme.equals("EIS")){
String programDay = "EISMon";
Intent intent = new Intent(TextDay.this, TestShow.class);
intent.putExtra("progDay", programDay);
startActivity(intent);
}
if(programme.equals("IS")){
String programDay = "ISMon";
Intent intent = new Intent(TextDay.this, TestShow.class);
intent.putExtra("progDay", programDay);
startActivity(intent);
}
if(programme.equals("IT")){
String programDay = "ITMon";
Intent intent = new Intent(TextDay.this, TestShow.class);
intent.putExtra("progDay", programDay);
startActivity(intent);
}
}
}
3rd activity which will capture and change the image source
enter code here
public class TestShow extends Activity {
ImageView image;
String table;
private void getData(){
Bundle extras = getIntent().getExtras();
if(extras != null){
table = extras.getString("progDay");
}
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_test_show);
getData();
image = (ImageView) findViewById(R.id.showTimeTable);
if(table.equals("SSDMonday")){
image.setImageResource(R.drawable.ssd_mon);
}
if(table.equals("EISMonday")){
image.setImageResource(R.drawable.eis_mon);
}
if(table.equals("ISMonday")){
image.setImageResource(R.drawable.is_mon);
}
if(table.equals("ITMonday")){
image.setImageResource(R.drawable.it_mon);
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.test_show, menu);
return true;
}
}