Today we have discussed about the intent in android.
In this project there are two xml file.
the main.xml file given below.
main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
<Button
android:text="First Page"
android:id="@+id/close"
android:layout_width="wrap_content"
android:layout_height="wrap_content"></Button>
</LinearLayout>
page.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
<Button
android:text="Second Page"
android:id="@+id/close"
android:layout_width="wrap_content"
android:layout_height="wrap_content"></Button>
</LinearLayout>
Now Java File given below
Intenting.java
package com.android;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class Intenting extends Activity {
private Button NewPage;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
this.NewPage = (Button)this.findViewById(R.id.close);
this.NewPage.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent(Intenting.this, New.class);
startActivity(i);
}
});
}
}
Now Second java file given below.
New.java
package com.android;
import android.app.Activity;
import android.os.Bundle;
public class New extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.page);
}
}
Image For first page
Image For Second Page
11 comments:
Add to manifest file.
Add activity android:name=".New" to manifest file.
ADD
if and.Main is my package in src folder of project. and the New.java file is present in this package then what should I add to manifest file?
Hi, i m getting 3 error after save the file
1)Intenting.java
error like (id cannot be resolved or is not a field)
2) page.xml
error like(
Multiple annotations found at this line:
- error: Error parsing XML: not well-formed (invalid
token))
3) page.xml and main.xml
android:text="Second Page"
[I18N] Hardcoded string "Second Page", should use @string resource
please tell me step by step (if possible plese take screenshot) how can solve this i am the very beginner in java android programming.
Hi all,
Any one can help me.....
hello all..
please somebody help me.. I want to build my application about SMS application. how to make SMS application to activate another application in android? help mee.. :'(
I am not able to navigate from one page to another so please can anyone tell wats the error in this code.
import android.view.View;
import android.widget.TextView;
public class MainActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextView ContactActivity=(TextView) findViewById(R.id.activity_main);
ContactActivity.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
Intent i = new Intent(getApplicationContext(), ContactActivity.class);
startActivity(i);
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
}
every time i click on the button i do not get my next screen but an error msg dat my program has unfortunately stopped working. pls help
Very bad tuts ever i have seennnnnnnnnnnnnnnnnnnnnnnnnnnnnn :FUck
Add activity in AndriodManifest
Post a Comment