Search code examples
androidandroid-layouteclipse-juno

How to navigate from first.xml to second.xml file with the click of login button which is present in first.xml in android application


Please help me .I want to navigate from my first page to second with the click of login button which is designed in first.xml


Solution

  • you have to create two activities and launch your other activity by using intents.and the intent must be defined in your manifest

    e.g

    public class Your_first_class extends Activity {
    private Button btn;
    public TextView txt;
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.info);
        btn=(Button)findViewById(R.id.buy);
    
        btn.setOnClickListener(new OnClickListener(){
    
            @Override
            public void onClick(View v) {
                 Intent myIntent = new Intent(Your_first_class.this, Your_second_class.class);
                 startActivity(myIntent);
    
            }
    
        });
    

    In your manifest declare it like this

    <activity android:name=".Your_first_class" android:label="@string/app_name"></activity>
    
    <activity android:name=".Your_second_class" android:label="@string/app_name"></activity>
    

    you can also look at this http://developer.android.com/training/basics/firstapp/starting-activity.html for more info on launching other activities with intents