Intend is the abstract description on an operation that should be performed.Intend helps to moves from one activity to another activity.
Go to File Menu->New->New Project->
then give application name and Company Domain as in the figure here then select next. choose blank activity as in previous project I have given the company name IntendDemo for this project.
Then go to Text view of activity_main.xml
Go to File Menu->New->New Project->
then give application name and Company Domain as in the figure here then select next. choose blank activity as in previous project I have given the company name IntendDemo for this project.
Then go to Text view of 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" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity"> <TextView android:text="@string/hello_world" android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/textView" />
/** adding button to the view*/
<Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="New Button" android:id="@+id/button" android:layout_below="@+id/textView" android:layout_centerHorizontal="true" android:layout_marginTop="85dp" />
</RelativeLayout>
You can drag and drop button from design view:
Now Go to MainActivity.java
package com.broadway.intentdemo; import android.app.AlertDialog; import android.content.DialogInterface; import android.content.Intent; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.widget.Button; import android.widget.Toast; /** Ater AppCompatActivity you should write implements then onclicklistner and enter*/ public class MainActivity extends AppCompatActivity implements View.OnClickListener { private Button btn; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); btn =(Button)findViewById(R.id.button); btn.setOnClickListener(this);/**btn lai onclicklistner sanga set gareko*/ }
public void onClick(View view){ Intent intent = new Intent(getApplicationContext(), SecondActivity.class);/**intent le yauta activity bata aarko activity ma shift garna madat garcha*/ startActivity(intent); } }
Go to AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.broadway.intentdemo" >
<application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" >
<activity android:name=".MainActivity" android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".SecondActivity" android:label="@string/title_activity_second" >
</activity>
</application>
</manifest>
Add this highlighted codeon AndroidManifest.xml that helps to define layout of second activity
Now run your project:


0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.