Create activity and go one to another
AndroidMAnifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.seam.createactivity5">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".Main2Activity">
<intent-filter>
<action android:name="com.example.seam.createactivity5.Main2Activity" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
Main_Activity.xml:<?xml version="1.0" encoding="utf-8"?><android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" x
mlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.seam.createactivity_6.MainActivity">
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"
tools:layout_editor_absoluteX="128dp"
tools:layout_editor_absoluteY="162dp" />
</android.support.constraint.ConstraintLayout>
MainActivity.java:
package com.example.seam.createactivity_6; import android.content.Intent; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.Button; public class MainActivity extends AppCompatActivity { Button bt; protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); stbt(); } public void stbt() { bt=(Button)findViewById(R.id.button); bt.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent i=new Intent(getApplicationContext(),Main2Activity.class); startActivity(i); } }); } }Main2Activity.xml:
<?xml version="1.0" encoding="utf-8"?><android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:app="http://schemas.android.com/apk/res-auto"xmlns:tools="http://schemas.android.com/tools"android:layout_width="match_parent"android:layout_height="match_parent"tools:context="com.example.seam.createactivity_6.Main2Activity"><Buttonandroid:id="@+id/button2"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="Button2"tools:layout_editor_absoluteX="158dp"app:layout_constraintTop_toTopOf="parent"android:layout_marginTop="185dp"app:layout_constraintBottom_toBottomOf="parent"android:layout_marginBottom="8dp" /></android.support.constraint.ConstraintLayout>
Main2Activity.java:package com.example.seam.createactivity_6; import android.content.Intent; import android.os.Bundle; import android.app.Activity; import android.view.View; import android.widget.Button; public class Main2Activity extends Activity { Button bt2; protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main2); setBt2(); } public void setBt2() { bt2=(Button)findViewById(R.id.button2); bt2.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent ii=new Intent(getApplicationContext(),MainActivity.class); startActivity(ii); } }); } }
মন্তব্যসমূহ
একটি মন্তব্য পোস্ট করুন