Android 新屏幕按钮不工作

Android 新屏幕按钮不工作,android,button,Android,Button,我已经搜索并尝试了所有的结果,但没有结果。我正在制作一个程序,从主屏幕开始,通过按钮指向新屏幕。我可以通过setContentView(R.layout.screen2)进入下一个屏幕;但是我的数据从连接到xml文件的java文件中永远不会传输。我不认为xml文件注册了与java文件的关联(因为我甚至尝试创建后退按钮,无论我输入什么代码,它们都不会返回到上一个屏幕)。意图使得按钮甚至不会进入下一个屏幕。我已经做了一个星期了,我仍然不知道如何解决这个问题 主要活动- package com.wun

我已经搜索并尝试了所有的结果,但没有结果。我正在制作一个程序,从主屏幕开始,通过按钮指向新屏幕。我可以通过setContentView(R.layout.screen2)进入下一个屏幕;但是我的数据从连接到xml文件的java文件中永远不会传输。我不认为xml文件注册了与java文件的关联(因为我甚至尝试创建后退按钮,无论我输入什么代码,它们都不会返回到上一个屏幕)。意图使得按钮甚至不会进入下一个屏幕。我已经做了一个星期了,我仍然不知道如何解决这个问题

主要活动-

package com.wunapp.newsvideoapp;




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 MainActivity extends Activity {





@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);


        Button videoNext = (Button) findViewById(R.id.videoButton) ; 
        videoNext.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
              //setContentView(R.layout.screen2);



                  Intent i = new Intent(MainActivity.this, Screen2.class);
               // i.setClassName("rahul.application.WunApp", "rahul.application.WunApp.screen1");
                startActivity(i);
            }
        });

        Button newsNext = (Button) findViewById(R.id.newsButton);
        newsNext.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
            //setContentView(R.layout.screen1);
            Intent intent = new Intent(MainActivity.this, Screen1.class);   
            startActivity(intent);

            }
        });



}

}
屏幕2-

package com.wunapp.newsvideoapp;


//import java.io.IOException;


import java.io.File;

import android.net.Uri;

import android.os.Bundle;
import android.os.Environment;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.graphics.PixelFormat;
import android.view.Menu;
import android.widget.MediaController;
import android.widget.VideoView;

import android.media.AudioManager;
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnPreparedListener;

public class Screen2 extends Activity {


    VideoView videoView;
    @Override
  public void onCreate(Bundle savedInstanceState) 
    {
      super.onCreate(savedInstanceState);

      setContentView(R.layout.screen2);

 Button back = (Button)this.findViewById(R.id.backButton);
        back.setOnClickListener(new OnClickListener() {

            public void onClick(View v) {
            setContentView(R.layout.activity_main);

            }
        });

...[code]
}
}
主要活动xml-

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <EditText
        android:id="@+id/editText1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:ems="10"
        android:text="@string/welcome" >

        <requestFocus />
    </EditText>

    <TextView
        android:id="@+id/textView5"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

    <TextView
        android:id="@+id/textView6"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

    <TextView
        android:id="@+id/textView7"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >
    </RelativeLayout>

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="0.25" >

        <TextView
            android:id="@+id/textView2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_alignParentTop="true" />

        <Button
            android:id="@+id/videoButton"
            android:layout_width="156dp"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:layout_centerVertical="true"
            android:text="@string/videoButton" />

        <Button
            android:id="@+id/newsButton"
            android:layout_width="152dp"
            android:layout_height="wrap_content"
            android:layout_alignLeft="@+id/videoButton"
            android:layout_below="@+id/textView2"
            android:layout_marginTop="33dp"
            android:text="@string/newsButton" />

    </RelativeLayout>

    <TextView
        android:id="@+id/textView4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >
    </RelativeLayout>

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >
    </RelativeLayout>

</LinearLayout>

Screen2XML-

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"

    android:layout_height="fill_parent" 
    android:paddingLeft="2dp" android:paddingRight="2dp"
    android:paddingTop="2dp" android:paddingBottom="2dp"
    android:layout_width="fill_parent" android:orientation="vertical">


    <VideoView
        android:id="@+id/VideoView"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true" />

<Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/backButton" />





</RelativeLayout>

显示-

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.wunapp.newsvideoapp"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="12"
        android:targetSdkVersion="15" />
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".MainActivity"
            android:label="@string/title_activity_main" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>


该应用程序是一个新的/视频应用程序,您可以在screen1中获取RSS提要,在screen2中获取视频。。。我省略了所有使这些工作的东西,因为我知道它们的代码工作得很好(在不同的项目中尝试将它们作为主文件)。我需要帮助的只是从一个屏幕到另一个屏幕的链接(如果是后退按钮,则是向后链接)。

您需要将其他活动添加到清单中

<activity
    android:name=".Screen1" android:label="Screen1Label" >
</activity>
<activity
    android:name=".Screen2" android:label="Screen2Label" >
</activity>

您需要将其他活动添加到清单中

<activity
    android:name=".Screen1" android:label="Screen1Label" >
</activity>
<activity
    android:name=".Screen2" android:label="Screen2Label" >
</activity>

您的
AndroidManifest.xml
指示只有一个主要活动。您需要在清单中定义Screen1和Screen2活动

例如:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.wunapp.newsvideoapp"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="12"
        android:targetSdkVersion="15" />
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".MainActivity"
            android:label="@string/title_activity_main" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name=".Screen1"
            android:label="@string/title_activity_screen1" >
        </activity>
        <activity
            android:name=".Screen2"
            android:label="@string/title_activity_screen2" >
        </activity>
    </application>

</manifest>

您的
AndroidManifest.xml
指示只有一个主要活动。您需要在清单中定义Screen1和Screen2活动

例如:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.wunapp.newsvideoapp"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="12"
        android:targetSdkVersion="15" />
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".MainActivity"
            android:label="@string/title_activity_main" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name=".Screen1"
            android:label="@string/title_activity_screen1" >
        </activity>
        <activity
            android:name=".Screen2"
            android:label="@string/title_activity_screen2" >
        </activity>
    </application>

</manifest>

像这样更改清单文件

<application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name=".MainActivity"
        android:label="@string/title_activity_main" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
  <activity
        android:name=".Screen2" />
</application>

像这样更改清单文件

<application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name=".MainActivity"
        android:label="@string/title_activity_main" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
  <activity
        android:name=".Screen2" />
</application>

我添加新活动的做法如下:

  • 单击AndroidManifest.xml
  • 单击应用程序节点选项卡(屏幕左下角 (屏幕)
  • 单击添加并选择活动作为选项
  • 单击名称链接并输入您的活动名称

  • 这将向您的项目和清单中添加新活动。

    添加新活动的做法如下:

  • 单击AndroidManifest.xml
  • 单击应用程序节点选项卡(屏幕左下角 (屏幕)
  • 单击添加并选择活动作为选项
  • 单击名称链接并输入您的活动名称

  • 这将向您的项目和清单中添加一个新活动。

    您是否在清单文件中提到screen2要帮助您解决问题,您能告诉我们您面临的问题是什么吗?正在抛出的任何异常。执行以下操作:转到LogCat或Console,并在此处向我们显示跟踪,以帮助我们了解问题所在。同时列出清单文件。代码编译得很好,问题是没有显示任何内容。。。我刚刚添加了清单文件。您是否在清单文件中提到了screen2?为了帮助您,您能告诉我们您面临的问题是什么吗?正在抛出的任何异常。执行以下操作:转到LogCat或Console,并在此处向我们显示跟踪,以帮助我们了解问题所在。同时列出清单文件。代码编译得很好,问题是没有显示任何内容。。。我刚刚添加了清单文件非常感谢大家!!正如你们所看到的,我是一个新手,但你们真的帮助了我,从来不知道你们也必须改变舱单。非常感谢你们!!正如你们所看到的,我是一个新手,但你们都真的帮了我的忙,从来都不知道你们也必须改变清单。