如何将数据从一个 xml 发送到另一个 xml 布局?
1.第一个活动
: 此Activity
有两个EditTexts
和两个Buttons
。 我需要提供登录 ID 和密码。这里 Buttons
包含登录和取消:
package com.samelayout;
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;
import android.widget.EditText;
public class SameLayoutActivity extends Activity {
/** Called when the activity is first created. */
EditText Myusername;
EditText Mypassword;
Button btnlogin;
Button btncancel;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
btnlogin=(Button)findViewById(R.id.loginbutton);
btncancel=(Button)findViewById(R.id.cancelbutton);
Myusername=(EditText)findViewById(R.id.username);
Mypassword=(EditText)findViewById(R.id.password);
btnlogin.setOnClickListener(new OnClickListener()
{ public void onClick(View v) {
String str1=Myusername.getText().toString();
String str2=Mypassword.getText().toString();
Intent int1=new Intent(getApplicationContext(),Login.class);
Bundle b= new Bundle();
b.putString("userdata", str1);
b.putString("userdata1", str2);
int1.putExtras(b);
int1.putExtras(b);
//(int1);
startActivityForResult(int1, 0);
}
});
btncancel.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
finish();
}
});
}
}
2.second Activity
: 此Activity
从第一个Activity
检索数据。我需要
package com.samelayout;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class Login extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.login);
//Intent int1= getIntent();
Bundle b=this.getIntent().getExtras();
if(b!=null)
{
String str1=b.getString("userdata");
String str2=b.getString("userdata1");
TextView tv1=(TextView)findViewById(R.id.text1);
TextView tv2=(TextView)findViewById(R.id.text2);
tv1.setText(str1);
tv2.setText(str2);
setContentView(tv1);
setContentView(tv2); }
} }
在此处向第二个 xml 文件 3.main.xml
显示用户详细信息:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/Linearlayout"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:weightSum="1"
android:background="@android:color/darker_gray" >
<TextView android:layout_width="fill_parent"
android:text="Employee ID:"
android:layout_height="wrap_content"
android:textColor="#0000FF"
android:textSize="20sp"/>
<EditText android:hint="enter ur ID"
android:singleLine="true"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/username"/>
<TextView android:layout_width="fill_parent"
android:text="Password:"
android:layout_height="wrap_content"
android:textColor="#0000FF"
android:textSize="20dip"/>
<EditText android:singleLine="true"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/password"
android:password="true"/>
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Submit"
android:id="@+id/loginbutton"/>
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Cancel"
android:id="@+id/cancelbutton"/>
</LinearLayout>
4. 可以在此处显示所需的输出:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/Linearlayout"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:weightSum="1"
android:background="@android:color/darker_gray" >
<TextView
android:layout_width="fill_parent"
android:id="@+id/text1"
android:text="Employee Name:"
android:layout_height="wrap_content"
android:textColor="#0000FF"
android:textSize="20sp"/>
<TextView
android:layout_width="fill_parent"
android:id="@+id/text2"
android:text="Employee password:"
android:layout_height="wrap_content"
android:textColor="#0000FF"
android:textSize="20sp"/>
</LinearLayout>
5. 这是我的 Logcat 收到错误
11-22 12:04:27.298: W/KeyCharacterMap(334): No keyboard for id 0
11-22 12:04:27.298: W/KeyCharacterMap(334): Using default keymap: /system/usr/keychars/qwerty.kcm.bin
11-22 12:04:37.738: D/AndroidRuntime(334): Shutting down VM
11-22 12:04:37.738: W/dalvikvm(334): threadid=1: thread exiting with uncaught exception (group=0x40015560)
11-22 12:04:37.758: E/AndroidRuntime(334): FATAL EXCEPTION: main
11-22 12:04:37.758: E/AndroidRuntime(334): android.content.ActivityNotFoundException: Unable to find explicit activity class {com.samelayout/com.samelayout.Login}; have you declared this activity in your AndroidManifest.xml?
11-22 12:04:37.758: E/AndroidRuntime(334): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1405)
11-22 12:04:37.758: E/AndroidRuntime(334): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1379)
11-22 12:04:37.758: E/AndroidRuntime(334): at android.app.Activity.startActivityForResult(Activity.java:2827)
11-22 12:04:37.758: E/AndroidRuntime(334): at com.samelayout.SameLayoutActivity$1.onClick(SameLayoutActivity.java:41)
11-22 12:04:37.758: E/AndroidRuntime(334): at android.view.View.performClick(View.java:2485)
11-22 12:04:37.758: E/AndroidRuntime(334): at android.view.View$PerformClick.run(View.java:9080)
11-22 12:04:37.758: E/AndroidRuntime(334): at android.os.Handler.handleCallback(Handler.java:587)
11-22 12:04:37.758: E/AndroidRuntime(334): at android.os.Handler.dispatchMessage(Handler.java:92)
11-22 12:04:37.758: E/AndroidRuntime(334): at android.os.Looper.loop(Looper.java:123)
11-22 12:04:37.758: E/AndroidRuntime(334): at android.app.ActivityThread.main(ActivityThread.java:3683)
11-22 12:04:37.758: E/AndroidRuntime(334): at java.lang.reflect.Method.invokeNative(Native Method)
11-22 12:04:37.758: E/AndroidRuntime(334): at java.lang.reflect.Method.invoke(Method.java:507)
11-22 12:04:37.758: E/AndroidRuntime(334): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
11-22 12:04:37.758: E/AndroidRuntime(334): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
11-22 12:04:37.758: E/AndroidRuntime(334): at dalvik.system.NativeStart.main(Native Method)
11-22 12:04:42.079: I/Process(334): Sending signal. PID: 334 SIG: 9
11-22 14:46:39.458: W/KeyCharacterMap(377): No keyboard for id 0
11-22 14:46:39.458: W/KeyCharacterMap(377): Using default keymap: /system/usr/keychars/qwerty.kcm.bin
11-22 14:46:42.309: D/AndroidRuntime(377): Shutting down VM
11-22 14:46:42.309: W/dalvikvm(377): threadid=1: thread exiting with uncaught exception (group=0x40015560)
11-22 14:46:42.329: E/AndroidRuntime(377): FATAL EXCEPTION: main
11-22 14:46:42.329: E/AndroidRuntime(377): android.content.ActivityNotFoundException: Unable to find explicit activity class {com.samelayout/com.samelayout.Login}; have you declared this activity in your AndroidManifest.xml?
11-22 14:46:42.329: E/AndroidRuntime(377): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1405)
11-22 14:46:42.329: E/AndroidRuntime(377): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1379)
11-22 14:46:42.329: E/AndroidRuntime(377): at android.app.Activity.startActivityForResult(Activity.java:2827)
11-22 14:46:42.329: E/AndroidRuntime(377): at com.samelayout.SameLayoutActivity$1.onClick(SameLayoutActivity.java:38)
11-22 14:46:42.329: E/AndroidRuntime(377): at android.view.View.performClick(View.java:2485)
11-22 14:46:42.329: E/AndroidRuntime(377): at android.view.View$PerformClick.run(View.java:9080)
11-22 14:46:42.329: E/AndroidRuntime(377): at android.os.Handler.handleCallback(Handler.java:587)
11-22 14:46:42.329: E/AndroidRuntime(377): at android.os.Handler.dispatchMessage(Handler.java:92)
11-22 14:46:42.329: E/AndroidRuntime(377): at android.os.Looper.loop(Looper.java:123)
11-22 14:46:42.329: E/AndroidRuntime(377): at android.app.ActivityThread.main(ActivityThread.java:3683)
11-22 14:46:42.329: E/AndroidRuntime(377): at java.lang.reflect.Method.invokeNative(Native Method)
11-22 14:46:42.329: E/AndroidRuntime(377): at java.lang.reflect.Method.invoke(Method.java:507)
11-22 14:46:42.329: E/AndroidRuntime(377): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
11-22 14:46:42.329: E/AndroidRuntime(377): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
11-22 14:46:42.329: E/AndroidRuntime(377): at dalvik.system.NativeStart.main(Native Method)
11-22 14:48:22.648: D/AndroidRuntime(411): Shutting down VM
11-22 14:48:22.648: W/dalvikvm(411): threadid=1: thread exiting with uncaught exception (group=0x40015560)
11-22 14:48:22.657: E/AndroidRuntime(411): FATAL EXCEPTION: main
11-22 14:48:22.657: E/AndroidRuntime(411): android.content.ActivityNotFoundException: Unable to find explicit activity class {com.samelayout/com.samelayout.Login}; have you declared this activity in your AndroidManifest.xml?
11-22 14:48:22.657: E/AndroidRuntime(411): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1405)
11-22 14:48:22.657: E/AndroidRuntime(411): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1379)
11-22 14:48:22.657: E/AndroidRuntime(411): at android.app.Activity.startActivityForResult(Activity.java:2827)
11-22 14:48:22.657: E/AndroidRuntime(411): at com.samelayout.SameLayoutActivity$1.onClick(SameLayoutActivity.java:38)
11-22 14:48:22.657: E/AndroidRuntime(411): at android.view.View.performClick(View.java:2485)
11-22 14:48:22.657: E/AndroidRuntime(411): at android.view.View$PerformClick.run(View.java:9080)
11-22 14:48:22.657: E/AndroidRuntime(411): at android.os.Handler.handleCallback(Handler.java:587)
11-22 14:48:22.657: E/AndroidRuntime(411): at android.os.Handler.dispatchMessage(Handler.java:92)
11-22 14:48:22.657: E/AndroidRuntime(411): at android.os.Looper.loop(Looper.java:123)
11-22 14:48:22.657: E/AndroidRuntime(411): at android.app.ActivityThread.main(ActivityThread.java:3683)
11-22 14:48:22.657: E/AndroidRuntime(411): at java.lang.reflect.Method.invokeNative(Native Method)
11-22 14:48:22.657: E/AndroidRuntime(411): at java.lang.reflect.Method.invoke(Method.java:507)
11-22 14:48:22.657: E/AndroidRuntime(411): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
11-22 14:48:22.657: E/AndroidRuntime(411): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
11-22 14:48:22.657: E/AndroidRuntime(411): at dalvik.system.NativeStart.main(Native Method)
11-22 14:59:44.668: W/KeyCharacterMap(441): No keyboard for id 0
11-22 14:59:44.668: W/KeyCharacterMap(441): Using default keymap: /system/usr/keychars/qwerty.kcm.bin
11-22 14:59:53.378: D/AndroidRuntime(441): Shutting down VM
11-22 14:59:53.388: W/dalvikvm(441): threadid=1: thread exiting with uncaught exception (group=0x40015560)
11-22 14:59:53.411: E/AndroidRuntime(441): FATAL EXCEPTION: main
11-22 14:59:53.411: E/AndroidRuntime(441): android.content.ActivityNotFoundException: Unable to find explicit activity class {com.samelayout/com.samelayout.Login}; have you declared this activity in your AndroidManifest.xml?
11-22 14:59:53.411: E/AndroidRuntime(441): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1405)
11-22 14:59:53.411: E/AndroidRuntime(441): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1379)
11-22 14:59:53.411: E/AndroidRuntime(441): at android.app.Activity.startActivityForResult(Activity.java:2827)
11-22 14:59:53.411: E/AndroidRuntime(441): at com.samelayout.SameLayoutActivity$1.onClick(SameLayoutActivity.java:38)
11-22 14:59:53.411: E/AndroidRuntime(441): at android.view.View.performClick(View.java:2485)
11-22 14:59:53.411: E/AndroidRuntime(441): at android.view.View$PerformClick.run(View.java:9080)
11-22 14:59:53.411: E/AndroidRuntime(441): at android.os.Handler.handleCallback(Handler.java:587)
11-22 14:59:53.411: E/AndroidRuntime(441): at android.os.Handler.dispatchMessage(Handler.java:92)
11-22 14:59:53.411: E/AndroidRuntime(441): at android.os.Looper.loop(Looper.java:123)
11-22 14:59:53.411: E/AndroidRuntime(441): at android.app.ActivityThread.main(ActivityThread.java:3683)
11-22 14:59:53.411: E/AndroidRuntime(441): at java.lang.reflect.Method.invokeNative(Native Method)
11-22 14:59:53.411: E/AndroidRuntime(441): at java.lang.reflect.Method.invoke(Method.java:507)
11-22 14:59:53.411: E/AndroidRuntime(441): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
11-22 14:59:53.411: E/AndroidRuntime(441): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
11-22 14:59:53.411: E/AndroidRuntime(441): at dalvik.system.NativeStart.main(Native Method)
11-22 15:04:53.512: I/Process(441): Sending signal. PID: 441 SIG: 9
6.android 清单文件:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.samelayout"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="10" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name">
<activity
android:label="@string/app_name"
android:name=".SameLayoutActivity" >
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".Login" >
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
1.First Activity
:
This Activity
has two EditTexts
and two Buttons
.
I need to give login id and password.Here
the Buttons
contained logging in and cancel:
package com.samelayout;
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;
import android.widget.EditText;
public class SameLayoutActivity extends Activity {
/** Called when the activity is first created. */
EditText Myusername;
EditText Mypassword;
Button btnlogin;
Button btncancel;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
btnlogin=(Button)findViewById(R.id.loginbutton);
btncancel=(Button)findViewById(R.id.cancelbutton);
Myusername=(EditText)findViewById(R.id.username);
Mypassword=(EditText)findViewById(R.id.password);
btnlogin.setOnClickListener(new OnClickListener()
{ public void onClick(View v) {
String str1=Myusername.getText().toString();
String str2=Mypassword.getText().toString();
Intent int1=new Intent(getApplicationContext(),Login.class);
Bundle b= new Bundle();
b.putString("userdata", str1);
b.putString("userdata1", str2);
int1.putExtras(b);
int1.putExtras(b);
//(int1);
startActivityForResult(int1, 0);
}
});
btncancel.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
finish();
}
});
}
}
2.second Activity
:
This Activity
retrieves the data from the first Activity
. I need to show user details to second xml file
package com.samelayout;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class Login extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.login);
//Intent int1= getIntent();
Bundle b=this.getIntent().getExtras();
if(b!=null)
{
String str1=b.getString("userdata");
String str2=b.getString("userdata1");
TextView tv1=(TextView)findViewById(R.id.text1);
TextView tv2=(TextView)findViewById(R.id.text2);
tv1.setText(str1);
tv2.setText(str2);
setContentView(tv1);
setContentView(tv2); }
} }
3.main.xml
here:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/Linearlayout"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:weightSum="1"
android:background="@android:color/darker_gray" >
<TextView android:layout_width="fill_parent"
android:text="Employee ID:"
android:layout_height="wrap_content"
android:textColor="#0000FF"
android:textSize="20sp"/>
<EditText android:hint="enter ur ID"
android:singleLine="true"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/username"/>
<TextView android:layout_width="fill_parent"
android:text="Password:"
android:layout_height="wrap_content"
android:textColor="#0000FF"
android:textSize="20dip"/>
<EditText android:singleLine="true"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/password"
android:password="true"/>
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Submit"
android:id="@+id/loginbutton"/>
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Cancel"
android:id="@+id/cancelbutton"/>
</LinearLayout>
4.needed output can be displayed here:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/Linearlayout"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:weightSum="1"
android:background="@android:color/darker_gray" >
<TextView
android:layout_width="fill_parent"
android:id="@+id/text1"
android:text="Employee Name:"
android:layout_height="wrap_content"
android:textColor="#0000FF"
android:textSize="20sp"/>
<TextView
android:layout_width="fill_parent"
android:id="@+id/text2"
android:text="Employee password:"
android:layout_height="wrap_content"
android:textColor="#0000FF"
android:textSize="20sp"/>
</LinearLayout>
5.this is my Logcat getting errors
11-22 12:04:27.298: W/KeyCharacterMap(334): No keyboard for id 0
11-22 12:04:27.298: W/KeyCharacterMap(334): Using default keymap: /system/usr/keychars/qwerty.kcm.bin
11-22 12:04:37.738: D/AndroidRuntime(334): Shutting down VM
11-22 12:04:37.738: W/dalvikvm(334): threadid=1: thread exiting with uncaught exception (group=0x40015560)
11-22 12:04:37.758: E/AndroidRuntime(334): FATAL EXCEPTION: main
11-22 12:04:37.758: E/AndroidRuntime(334): android.content.ActivityNotFoundException: Unable to find explicit activity class {com.samelayout/com.samelayout.Login}; have you declared this activity in your AndroidManifest.xml?
11-22 12:04:37.758: E/AndroidRuntime(334): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1405)
11-22 12:04:37.758: E/AndroidRuntime(334): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1379)
11-22 12:04:37.758: E/AndroidRuntime(334): at android.app.Activity.startActivityForResult(Activity.java:2827)
11-22 12:04:37.758: E/AndroidRuntime(334): at com.samelayout.SameLayoutActivity$1.onClick(SameLayoutActivity.java:41)
11-22 12:04:37.758: E/AndroidRuntime(334): at android.view.View.performClick(View.java:2485)
11-22 12:04:37.758: E/AndroidRuntime(334): at android.view.View$PerformClick.run(View.java:9080)
11-22 12:04:37.758: E/AndroidRuntime(334): at android.os.Handler.handleCallback(Handler.java:587)
11-22 12:04:37.758: E/AndroidRuntime(334): at android.os.Handler.dispatchMessage(Handler.java:92)
11-22 12:04:37.758: E/AndroidRuntime(334): at android.os.Looper.loop(Looper.java:123)
11-22 12:04:37.758: E/AndroidRuntime(334): at android.app.ActivityThread.main(ActivityThread.java:3683)
11-22 12:04:37.758: E/AndroidRuntime(334): at java.lang.reflect.Method.invokeNative(Native Method)
11-22 12:04:37.758: E/AndroidRuntime(334): at java.lang.reflect.Method.invoke(Method.java:507)
11-22 12:04:37.758: E/AndroidRuntime(334): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
11-22 12:04:37.758: E/AndroidRuntime(334): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
11-22 12:04:37.758: E/AndroidRuntime(334): at dalvik.system.NativeStart.main(Native Method)
11-22 12:04:42.079: I/Process(334): Sending signal. PID: 334 SIG: 9
11-22 14:46:39.458: W/KeyCharacterMap(377): No keyboard for id 0
11-22 14:46:39.458: W/KeyCharacterMap(377): Using default keymap: /system/usr/keychars/qwerty.kcm.bin
11-22 14:46:42.309: D/AndroidRuntime(377): Shutting down VM
11-22 14:46:42.309: W/dalvikvm(377): threadid=1: thread exiting with uncaught exception (group=0x40015560)
11-22 14:46:42.329: E/AndroidRuntime(377): FATAL EXCEPTION: main
11-22 14:46:42.329: E/AndroidRuntime(377): android.content.ActivityNotFoundException: Unable to find explicit activity class {com.samelayout/com.samelayout.Login}; have you declared this activity in your AndroidManifest.xml?
11-22 14:46:42.329: E/AndroidRuntime(377): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1405)
11-22 14:46:42.329: E/AndroidRuntime(377): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1379)
11-22 14:46:42.329: E/AndroidRuntime(377): at android.app.Activity.startActivityForResult(Activity.java:2827)
11-22 14:46:42.329: E/AndroidRuntime(377): at com.samelayout.SameLayoutActivity$1.onClick(SameLayoutActivity.java:38)
11-22 14:46:42.329: E/AndroidRuntime(377): at android.view.View.performClick(View.java:2485)
11-22 14:46:42.329: E/AndroidRuntime(377): at android.view.View$PerformClick.run(View.java:9080)
11-22 14:46:42.329: E/AndroidRuntime(377): at android.os.Handler.handleCallback(Handler.java:587)
11-22 14:46:42.329: E/AndroidRuntime(377): at android.os.Handler.dispatchMessage(Handler.java:92)
11-22 14:46:42.329: E/AndroidRuntime(377): at android.os.Looper.loop(Looper.java:123)
11-22 14:46:42.329: E/AndroidRuntime(377): at android.app.ActivityThread.main(ActivityThread.java:3683)
11-22 14:46:42.329: E/AndroidRuntime(377): at java.lang.reflect.Method.invokeNative(Native Method)
11-22 14:46:42.329: E/AndroidRuntime(377): at java.lang.reflect.Method.invoke(Method.java:507)
11-22 14:46:42.329: E/AndroidRuntime(377): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
11-22 14:46:42.329: E/AndroidRuntime(377): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
11-22 14:46:42.329: E/AndroidRuntime(377): at dalvik.system.NativeStart.main(Native Method)
11-22 14:48:22.648: D/AndroidRuntime(411): Shutting down VM
11-22 14:48:22.648: W/dalvikvm(411): threadid=1: thread exiting with uncaught exception (group=0x40015560)
11-22 14:48:22.657: E/AndroidRuntime(411): FATAL EXCEPTION: main
11-22 14:48:22.657: E/AndroidRuntime(411): android.content.ActivityNotFoundException: Unable to find explicit activity class {com.samelayout/com.samelayout.Login}; have you declared this activity in your AndroidManifest.xml?
11-22 14:48:22.657: E/AndroidRuntime(411): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1405)
11-22 14:48:22.657: E/AndroidRuntime(411): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1379)
11-22 14:48:22.657: E/AndroidRuntime(411): at android.app.Activity.startActivityForResult(Activity.java:2827)
11-22 14:48:22.657: E/AndroidRuntime(411): at com.samelayout.SameLayoutActivity$1.onClick(SameLayoutActivity.java:38)
11-22 14:48:22.657: E/AndroidRuntime(411): at android.view.View.performClick(View.java:2485)
11-22 14:48:22.657: E/AndroidRuntime(411): at android.view.View$PerformClick.run(View.java:9080)
11-22 14:48:22.657: E/AndroidRuntime(411): at android.os.Handler.handleCallback(Handler.java:587)
11-22 14:48:22.657: E/AndroidRuntime(411): at android.os.Handler.dispatchMessage(Handler.java:92)
11-22 14:48:22.657: E/AndroidRuntime(411): at android.os.Looper.loop(Looper.java:123)
11-22 14:48:22.657: E/AndroidRuntime(411): at android.app.ActivityThread.main(ActivityThread.java:3683)
11-22 14:48:22.657: E/AndroidRuntime(411): at java.lang.reflect.Method.invokeNative(Native Method)
11-22 14:48:22.657: E/AndroidRuntime(411): at java.lang.reflect.Method.invoke(Method.java:507)
11-22 14:48:22.657: E/AndroidRuntime(411): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
11-22 14:48:22.657: E/AndroidRuntime(411): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
11-22 14:48:22.657: E/AndroidRuntime(411): at dalvik.system.NativeStart.main(Native Method)
11-22 14:59:44.668: W/KeyCharacterMap(441): No keyboard for id 0
11-22 14:59:44.668: W/KeyCharacterMap(441): Using default keymap: /system/usr/keychars/qwerty.kcm.bin
11-22 14:59:53.378: D/AndroidRuntime(441): Shutting down VM
11-22 14:59:53.388: W/dalvikvm(441): threadid=1: thread exiting with uncaught exception (group=0x40015560)
11-22 14:59:53.411: E/AndroidRuntime(441): FATAL EXCEPTION: main
11-22 14:59:53.411: E/AndroidRuntime(441): android.content.ActivityNotFoundException: Unable to find explicit activity class {com.samelayout/com.samelayout.Login}; have you declared this activity in your AndroidManifest.xml?
11-22 14:59:53.411: E/AndroidRuntime(441): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1405)
11-22 14:59:53.411: E/AndroidRuntime(441): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1379)
11-22 14:59:53.411: E/AndroidRuntime(441): at android.app.Activity.startActivityForResult(Activity.java:2827)
11-22 14:59:53.411: E/AndroidRuntime(441): at com.samelayout.SameLayoutActivity$1.onClick(SameLayoutActivity.java:38)
11-22 14:59:53.411: E/AndroidRuntime(441): at android.view.View.performClick(View.java:2485)
11-22 14:59:53.411: E/AndroidRuntime(441): at android.view.View$PerformClick.run(View.java:9080)
11-22 14:59:53.411: E/AndroidRuntime(441): at android.os.Handler.handleCallback(Handler.java:587)
11-22 14:59:53.411: E/AndroidRuntime(441): at android.os.Handler.dispatchMessage(Handler.java:92)
11-22 14:59:53.411: E/AndroidRuntime(441): at android.os.Looper.loop(Looper.java:123)
11-22 14:59:53.411: E/AndroidRuntime(441): at android.app.ActivityThread.main(ActivityThread.java:3683)
11-22 14:59:53.411: E/AndroidRuntime(441): at java.lang.reflect.Method.invokeNative(Native Method)
11-22 14:59:53.411: E/AndroidRuntime(441): at java.lang.reflect.Method.invoke(Method.java:507)
11-22 14:59:53.411: E/AndroidRuntime(441): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
11-22 14:59:53.411: E/AndroidRuntime(441): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
11-22 14:59:53.411: E/AndroidRuntime(441): at dalvik.system.NativeStart.main(Native Method)
11-22 15:04:53.512: I/Process(441): Sending signal. PID: 441 SIG: 9
6.android manifest file:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.samelayout"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="10" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name">
<activity
android:label="@string/app_name"
android:name=".SameLayoutActivity" >
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".Login" >
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在 SameLayoutActivity 中替换此代码,
在您的登录活动中,替换此代码,然后重试并让我知道发生了什么..
清单文件:
In SameLayoutActivity replace this,
In your Login Activity, Replace this code, And try again and let me know what happen ..
Manifest file:
您需要通过用于启动第二个 Activity 的
Intent
传递数据。查看这篇博客文章。You need to pass your data through the
Intent
used to start the 2nd Activity. Check this blog post out.设置数据绑定来轻松实现这一点。
您可以通过在 Build.gradle(:app) 内部
现在,要将数据从一个 xml 发送到另一个 xml,请查看下面的示例。在此,我制作了一个名为 item_top_card.xml 的布局,我想将其包含在另一个具有不同标题的 xml 文件中。一种方法是为不同的标题制作不同的 xml。一种好方法是将标题字符串从一个 xml 传递到另一个 xml,如下所示:
您可以包含要包含在其他 xml 文件中的布局 xml,如上所示。请注意,这里我们在“option”参数中传递字符串。这是参数名称,可以根据您的需要进行更改。以下是 item_top_card.xml 的文件:
You can achieve this easily by data binding by setting
inside your Build.gradle(:app)
Now, to send data from one xml to another, look at the below example. In this, I have made a layout named item_top_card.xml which I want to include it in another xml file with different titles. One way is to make different xml for different titles. A good way is to pass the title string from one xml to another as shown :
You can include the layout xml which you want to include in other xml file as shown above. Notice that here we are passing the string in "option" parameter. This is the parameter name which can be changed as per your needs. Below is the file for item_top_card.xml: