我已經搜索並嘗試了所有的結果,但無濟於事。我正在製作一個從主屏幕開始並通過按鈕指向新屏幕的程序。我可以通過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);
}
});
}
}
Screen2-
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>
畫面2 XML-
<?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-
<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>
應用程序是一個新的/視頻應用程序,在那裏你可以在屏幕截圖1 RSS源,並在屏幕2視頻...我離開了所有這一切使這些工作,因爲我的東西知道他們的代碼工作正常(嘗試他們作爲主要文件在不同的項目)。這只是從屏幕到屏幕的鏈接(並且在後退按鈕的情況下向後),我需要幫助。
你是否在清單文件中提及screen2 – 2012-07-06 16:16:27
爲了幫助你,你能告訴我們你面臨的問題是什麼嗎?拋出任何異常。 執行以下操作:轉至LogCat或控制檯並向我們顯示此處的跟蹤信息,以幫助我們瞭解問題所在。 也列出你的清單文件。 – Romin 2012-07-06 16:19:11
代碼編譯得很好,問題是什麼也沒有顯示出來......我只是添加了清單文件 – 2012-07-06 16:21:44