<tfoot id='RecsK'></tfoot>

      <legend id='RecsK'><style id='RecsK'><dir id='RecsK'><q id='RecsK'></q></dir></style></legend>
      • <bdo id='RecsK'></bdo><ul id='RecsK'></ul>
      <i id='RecsK'><tr id='RecsK'><dt id='RecsK'><q id='RecsK'><span id='RecsK'><b id='RecsK'><form id='RecsK'><ins id='RecsK'></ins><ul id='RecsK'></ul><sub id='RecsK'></sub></form><legend id='RecsK'></legend><bdo id='RecsK'><pre id='RecsK'><center id='RecsK'></center></pre></bdo></b><th id='RecsK'></th></span></q></dt></tr></i><div id='RecsK'><tfoot id='RecsK'></tfoot><dl id='RecsK'><fieldset id='RecsK'></fieldset></dl></div>

      <small id='RecsK'></small><noframes id='RecsK'>

    1. 在 Android 中从一个活动移动到另一个活动

      时间:2023-08-29

      <legend id='LPRW7'><style id='LPRW7'><dir id='LPRW7'><q id='LPRW7'></q></dir></style></legend>

              <tbody id='LPRW7'></tbody>

                <bdo id='LPRW7'></bdo><ul id='LPRW7'></ul>

              • <small id='LPRW7'></small><noframes id='LPRW7'>

                <tfoot id='LPRW7'></tfoot>

              • <i id='LPRW7'><tr id='LPRW7'><dt id='LPRW7'><q id='LPRW7'><span id='LPRW7'><b id='LPRW7'><form id='LPRW7'><ins id='LPRW7'></ins><ul id='LPRW7'></ul><sub id='LPRW7'></sub></form><legend id='LPRW7'></legend><bdo id='LPRW7'><pre id='LPRW7'><center id='LPRW7'></center></pre></bdo></b><th id='LPRW7'></th></span></q></dt></tr></i><div id='LPRW7'><tfoot id='LPRW7'></tfoot><dl id='LPRW7'><fieldset id='LPRW7'></fieldset></dl></div>
                本文介绍了在 Android 中从一个活动移动到另一个活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                我想从一项活动转移到另一项活动(使用虚拟设备).当我点击按钮移动时,我的模拟器会出现一个对话框,显示 不幸的是 SMS1 已停止工作(SMS1 是我的应用程序名称).

                I want to move from one activity to another (using virtual device). When I click on button to move, My emulator ones a dialog box showing unfortunately SMS1 has stopped working (SMS1 is my app name).

                谁能帮我更正我的代码?

                Can anybody help me in correcting my code?

                MainActivity.java:

                package com.example.sms1;
                
                 import android.os.Bundle;
                 import android.app.Activity;
                 import android.content.Intent;
                 import android.view.Menu;
                 import android.view.View;
                 import android.view.View.OnClickListener;
                 import android.widget.Button;
                 import android.widget.TextView;
                
                 public class MainActivity extends Activity implements OnClickListener
                 {
                
                Button b1;
                TextView tv1;
                 @Override
                 protected void onCreate(Bundle savedInstanceState)
                 {
                    super.onCreate(savedInstanceState);
                    setContentView(R.layout.activity_main);
                    b1 = (Button) findViewById(R.id.button1);
                    tv1 = (TextView) findViewById(R.id.textView1);
                
                    b1.setOnClickListener(this);
                
                 }
                
                @Override
                public boolean onCreateOptionsMenu(Menu menu)
                {
                    // Inflate the menu; this adds items to the action bar if it is present.
                    getMenuInflater().inflate(R.menu.main, menu);
                    return true;
                }
                
                @Override
                public void onClick(View v)
                {
                    // TODO Auto-generated method stub
                    Intent i = new Intent(getApplicationContext(),NextActivity.class);
                    startActivity(i);
                    setContentView(R.layout.avtivity_next);
                }
                
                
                
                }
                

                这是 NextActivity

                package com.example.sms1;
                
                import android.os.Bundle;
                import android.app.Activity;
                import android.view.Menu;
                import android.widget.TextView;
                
                public class NextActivity extends Activity {
                
                TextView tv1;
                @Override
                protected void onCreate(Bundle savedInstanceState) {
                    super.onCreate(savedInstanceState);
                    setContentView(R.layout.avtivity_next);
                    tv1 = (TextView) findViewById(R.id.textView1);
                }
                
                
                @Override
                public boolean onCreateOptionsMenu(Menu menu) {
                    // Inflate the menu; this adds items to the action bar if it is present.
                    getMenuInflater().inflate(R.menu.main, menu);
                    return true;
                }
                
                }
                

                Manifest.XML

                <?xml version="1.0" encoding="utf-8"?>
                <manifest xmlns:android="http://schemas.android.com/apk/res/android"
                package="com.example.sms1"
                android:versionCode="1"
                android:versionName="1.0" >
                
                <uses-sdk
                    android:minSdkVersion="8"
                    android:targetSdkVersion="17" />
                
                <application
                    android:allowBackup="true"
                    android:icon="@drawable/ic_launcher"
                    android:label="@string/app_name"
                    android:theme="@style/AppTheme" >
                    <activity
                        android:name="com.example.sms1.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>
                </application>
                
                </manifest>
                

                NextActivityLayout

                <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:paddingBottom="@dimen/activity_vertical_margin"
                android:paddingLeft="@dimen/activity_horizontal_margin"
                android:paddingRight="@dimen/activity_horizontal_margin"
                android:paddingTop="@dimen/activity_vertical_margin"
                tools:context=".NextActivity" >
                
                <TextView
                    android:id="@+id/textView1"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="next activity" />
                
                
                
                </RelativeLayout>
                

                MainActivity 布局

                <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:paddingBottom="@dimen/activity_vertical_margin"
                android:paddingLeft="@dimen/activity_horizontal_margin"
                android:paddingRight="@dimen/activity_horizontal_margin"
                android:paddingTop="@dimen/activity_vertical_margin"
                tools:context=".MainActivity" >
                
                <TextView
                    android:id="@+id/textView1"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/hello_world" />
                
                <Button
                    android:id="@+id/button1"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_below="@+id/textView1"
                    android:layout_marginTop="80dp"
                    android:layout_toRightOf="@+id/textView1"
                    android:text="Button" />
                
                </RelativeLayout>
                

                推荐答案

                你还没有在 AndroidManifest.xml 文件中定义 NextActivity.

                You haven't defined NextActivity in the AndroidManifest.xml file.

                </activity>标签之后添加这些行.它应该可以工作.

                Add these lines in android manifest after</activity> tag. It should work.

                <activity
                    android:name=".NextActivity" >
                </activity>
                

                最终代码将是

                <application
                    android:allowBackup="true"
                    android:icon="@drawable/app_icon"
                    android:label="@string/app_name" >
                    <activity
                        android:name=".MainActivity"
                        android:label="Main Activity" >
                        <intent-filter>
                            <action android:name="android.intent.action.MAIN" />
                
                            <category android:name="android.intent.category.LAUNCHER" />
                        </intent-filter>
                    </activity>
                    <activity
                        android:name=".NextActivity" >
                    </activity>
                </application>
                

                这篇关于在 Android 中从一个活动移动到另一个活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:Android 模拟器 - 创建用户帐户时遇到问题 下一篇:Android 模拟器屏幕仅占实际 android 模拟器屏幕的一

                相关文章

                最新文章

                <tfoot id='iJ65l'></tfoot>
              • <legend id='iJ65l'><style id='iJ65l'><dir id='iJ65l'><q id='iJ65l'></q></dir></style></legend>

                <small id='iJ65l'></small><noframes id='iJ65l'>

              • <i id='iJ65l'><tr id='iJ65l'><dt id='iJ65l'><q id='iJ65l'><span id='iJ65l'><b id='iJ65l'><form id='iJ65l'><ins id='iJ65l'></ins><ul id='iJ65l'></ul><sub id='iJ65l'></sub></form><legend id='iJ65l'></legend><bdo id='iJ65l'><pre id='iJ65l'><center id='iJ65l'></center></pre></bdo></b><th id='iJ65l'></th></span></q></dt></tr></i><div id='iJ65l'><tfoot id='iJ65l'></tfoot><dl id='iJ65l'><fieldset id='iJ65l'></fieldset></dl></div>
                • <bdo id='iJ65l'></bdo><ul id='iJ65l'></ul>