Answer the question
In order to leave comments, you need to log in
How to transfer data to another activity?
Good afternoon, I know that there is a lot of information on the Internet on this issue, but after studying the theory, I switched to practice and nothing happens.
There are two activities: one has a lot of buttons, the other has a lot of text with titles. Headings and buttons have their own id. It is necessary that when you click on a button in one activity, go to the corresponding title in another activity.
public class ActivityBox_3_1 extends AppCompatActivity {
private TextView text1, text2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activitybox_3_1);
Button b1 = findViewById(R.id.butM_1);
Button b2 = findViewById(R.id.butM_2);
text1 =(TextView)findViewById(R.id.Moltext1);
text2 =(TextView)findViewById(R.id.Moltext2);
b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent1 = new Intent(ActivityBox_3_1.this, ActivityBox_3.class);
intent1. putExtra("name", (Parcelable) text1);
startActivity(intent1);
}
});
b2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent2 = new Intent(ActivityBox_3_1.this, ActivityBox_3.class);
intent2.putExtra("name", (Parcelable) text2);
startActivity(intent2);
}
});
}
}
public class ActivityBox_3 extends AppCompatActivity {
SharedPreferences sp;
TextView Moltext1, Moltext2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activitybox_3);
sp = getSharedPreferences("app_data", 0);
SharedPreferences sp = getSharedPreferences("app_data",0);
TextView Moltext1 = findViewById(R.id.Moltext1);
intent intent1 = getIntent();
String text1 = "
" +
" \t\t\tPRAYER IS GOOD UNTIL THE LORD
"+
"\t\t\tLord, I don't know
";
Moltext1.setTextSize(TypedValue.COMPLEX_UNIT_SP,sp.getInt("size",18));
Moltext1.setText(Html.fromHtml(text1));
TextView Moltext2 = findViewById(R.id.Moltext2);
Intent intent2 = getIntent ();
String text2 = " \t\t\tPRAYER BEFORE THE COB OF ALL GOOD WORK
"+
"\t\t\tMerciful God, Father and Lord!
";
Moltext2.setTextSize(TypedValue.COMPLEX_UNIT_SP,sp.getInt("size",18));
Moltext2.setText(Html.fromHtml(text2));
................ .................
Answer the question
In order to leave comments, you need to log in
in the first:
in the second:String name = getIntent().getStringExtra("name");
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question