Screen1:
FirstPage:
Firstpage.xml:
<RelativeLayout>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/editText"/>
<Button
android:text="NextPage"
android:id="@+id/button"
android:onClick="showSecond"/>
</RelativeLayout>
Screen2:
SecondPage.xml:
<RelativeLayout>
<EditText
android:inputType="textName"/>
<Button
android:text="NextPage"
android:onClick="showThird"/>
<Button
android:text="PreviousPage"
android:onClick="showFirst"/>
</RelativeLayout>
Screen3:
ThirdPage:
ThirdPage.xml:
<RelativeLayout>
<EditText
android:inputType="textName"/>
<Button
android:text="FirstPage"
android:onClick="showFirst"/>
<Button
android:text="PreviousPage"
android:onClick="showSecond"/>
</RelativeLayout>
FirstPage.java:
public class FirstPage extends AppCompatActivity{
EditText et;
@override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity.first);
}
public void showSecond(View v)
{
et=(EditText)findViewByID(R.id.editText);
Intent i=new Intent(this,SecondPage.class);
i.putExtra("str1",et.getText().toString());
StartActivity(i);
}
}
SecondPage.java:
public class SecondPage extends AppCompatActivity{
EditText et;
@override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_second);
et=(EditText)findViewById(R.id.editText2);
et.setText(getIntent().getStringExtra("str1"));
}
}
public void showThird(View v)
{
et=(EditText)findViewById(R.id.editText2);
Intent i=new Intent(this,ThirdPage.class);
i.putExtra("str2",et.getText().toString());
startActivity(i);
}
public void showFirst(View v)
{
startActivity(new Intent(this,FirstPage.class));
}
}
ThirdPage.java:
public class ThirdPage extends AppCompatActivity{
EditText et;
@Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_third);
et=(EditText)findViewById(R.id.editText3);
et.setText(getIntent().getStringExtra("str2"));
}
public void showFirst(View v)
{
startActivity(new Intent(this,FirstPage.class));
}
public void showSecond(View v)
{
et=(EditText)findViewById(R.id.editText3);
Intent i=new Intent(this,SecondPage.class);
i.putExtra("str1",et.getText().toString());
startActivity(i);
}
}
In the above program by using intents i moved data from one screen to another screen.
Get Answers For Free
Most questions answered within 1 hours.