activity_main.xml
---------------------
---------------------
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity"> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Call Activity 2" android:id="@+id/button" android:layout_alignParentTop="true" android:layout_centerHorizontal="true" android:layout_marginTop="156dp" /> </RelativeLayout>MainActivity.Java
-----------------
ackage com.android.anil.explicitintent; import android.content.Intent; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.widget.Button; public class MainActivity extends AppCompatActivity { Button gosecond; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); gosecond=(Button)findViewById(R.id.button); gosecond.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent in=new Intent(MainActivity.this,SecondActivity.class); startActivity(in); } }); } }Output is:
-------------
No comments:
Post a Comment