改变android上的活动

改变android上的活动,android,xml,android-activity,Android,Xml,Android Activity,我很难在android上改变活动 我启动了我的应用程序(display main.xml)并单击了开始按钮(display listening.xml) 当我按下后退按钮时,应用程序上的背景消失了 [display main.xml] [display listing.xml] 检测显示器。。(未附上图像,因为我的声誉较低:() [显示main.xml(问题)] 以下是我的源代码。 (省略了一些代码。) 请给我一些建议。 对不起,我的英语不好。 提前谢谢 以下是添加的上下文。


我很难在android上改变活动
我启动了我的应用程序(display main.xml)并单击了开始按钮(display listening.xml)
当我按下后退按钮时,应用程序上的背景消失了

[display main.xml]

[display listing.xml]
检测显示器。。(未附上图像,因为我的声誉较低:()

[显示main.xml(问题)]


以下是我的源代码。
(省略了一些代码。)

请给我一些建议。

对不起,我的英语不好。
提前谢谢




以下是添加的上下文。



我试图将充气器更改为setContentView()。
但是,它不起作用。

我单击了开始按钮,并触按了手机上的后退键。
我的手机说“很遗憾,(我的应用程序名称)已停止。”

我重新加载了我的源代码。

[MainActivity.java]

package com.musicg.demo.android;

import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.media.AudioManager;
import android.media.AudioManager.OnAudioFocusChangeListener;
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnCompletionListener;
import android.os.Bundle;
import android.os.Vibrator;
import android.util.Log;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

public class MainActivity extends Activity implements                 OnSignalsDetectedListener {

    static MainActivity mainApp;

    public static final int DETECT_NONE = 0;
    public static final int DETECT_WHISTLE = 1;
    public static int selectedDetection = DETECT_NONE;

    // detection parameters
    private DetectorThread detectorThread;
    private RecorderThread recorderThread;
    private int numWhistleDetected = 0;

    // views
    private View mainView, listeningView, helpView ;
    private Button whistleButton , whistleButton02;

    // alarmVoice()에서 사용하는 변수들  - am, mp, LOG
    private AudioManager am;
    private MediaPlayer mp;

    private String LOG = "My_Tag";

    ImageView imageView01;


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

        mainApp = this;

        // set views
//      LayoutInflater inflater = LayoutInflater.from(this);    // disable inflater

        setContentView(R.layout.main);


//      mainView = inflater.inflate(R.layout.main, null);   // disable inflater
//      listeningView = inflater.inflate(R.layout.listening, null); // disable inflater

//      setContentView(mainView);   // disable inflater

        whistleButton = (Button) this.findViewById(R.id.whistleButton); // Start button
        whistleButton.setOnClickListener(new ClickEvent());

        whistleButton02 = (Button) this.findViewById(R.id.whistleButton02); // ReadMe button
        whistleButton02.setOnClickListener(new ClickEvent());

    }

    private void goHomeView() {
        setContentView(mainView);
        if (recorderThread != null) {
            recorderThread.stopRecording();
            recorderThread = null;
        }
        if (detectorThread != null) {
            detectorThread.stopDetection();
            detectorThread = null;
        }
        selectedDetection = DETECT_NONE;
    }

    private void goListeningView() {
        //setContentView(listeningView);
        setContentView(R.layout.listening);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        menu.add(0, 0, 0, "Exit");
        return super.onCreateOptionsMenu(menu);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
        case 0:
            NotificationManager notiMgr = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
            notiMgr.cancel(999);    // Notification의 고유 id가 999인 것을 찾아서 notification을 종료한다.

            finish();
            break;
        default:
        }
        return super.onOptionsItemSelected(item);
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
            goHomeView();
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }

    class ClickEvent implements OnClickListener {
        public void onClick(View view) {


            if (view == whistleButton) {
                selectedDetection = DETECT_WHISTLE;
                recorderThread = new RecorderThread();
                recorderThread.start();
                detectorThread = new DetectorThread(recorderThread);
                detectorThread.setOnSignalsDetectedListener(MainActivity.mainApp);
                detectorThread.start(); 
                goListeningView();

            }

            if(view == whistleButton02)
            {
                Intent intent = new Intent(MainActivity.this, help.class );
                startActivity(intent);

            }
        }
    }


    private void Threadsleep(DetectorThread detectorThread){
        try
        {
            detectorThread.sleep(1000);
        }

        catch(InterruptedException e)
        {
            e.printStackTrace();
        }

    }

    protected void onDestroy() {
        super.onDestroy();
    }

    @Override
    public void onWhistleDetected() {
        runOnUiThread(new Runnable() {
            public void run() {

                 TextView textView = (TextView)
                 MainActivity.mainApp.findViewById(R.id.detectedNumberText);                 
                 textView.setText(String.valueOf(numWhistleDetected++));

                if (numWhistleDetected > 1) {
                    setEvent();                 
                }
            }
        });

        Threadsleep(detectorThread);
    }

}
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" 
    android:background="@drawable/car">

    <Button 
        android:id="@+id/whistleButton"
        android:layout_width="150dp"
        android:layout_height="40dp"
        android:gravity="center"
        android:text="Start"
        android:textSize="20dp"  
        android:background="#FFFFFFFF"
        android:textColor="#FF000000"
        android:padding="5dp"
        android:layout_centerInParent = "true"      
        />

    <Button
        android:id="@+id/whistleButton02"
        android:layout_width="150dp"
        android:layout_height="40dp"
        android:layout_below="@id/whistleButton"
        android:gravity="center"     
        android:text="ReadMe"
        android:background="#FFFFFFFF"
        android:textColor="#FF000000"
        android:textSize="20dp" 
        android:layout_marginTop="15dp"
        android:padding="5dp"           
        android:layout_centerInParent = "true"
         />

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

    android:layout_width="fill_parent"
    android:layout_height="fill_parent" 
    android:background ="@drawable/worker"
    >

    <TextView
        android:id="@+id/listening"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:layout_centerVertical="true"
        android:layout_centerInParent="true"
        android:textSize="30dp"    
        android:text="Detecting.." />


    <TextView
        android:id="@+id/detectedText"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/listening"
        android:layout_centerInParent="true"       
        android:textSize="20dp" />       

    <TextView
        android:id="@+id/detectedNumberText"
        android:textStyle="bold"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/listening"        
        android:textSize="5dp"
        android:layout_toRightOf="@+id/detectedText"
         />

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

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_marginLeft="112dp"
        android:layout_marginTop="20dp"
        android:text="Read Me...." />

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

    <uses-sdk
        android:minSdkVersion="8" />

    <uses-permission android:name="android.permission.RECORD_AUDIO" />

    <application
        android:icon="@drawable/ear"
        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=".listening"></activity>
             <activity android:name="help"></activity>
    </application>

</manifest>

[main.xml]

package com.musicg.demo.android;

import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.media.AudioManager;
import android.media.AudioManager.OnAudioFocusChangeListener;
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnCompletionListener;
import android.os.Bundle;
import android.os.Vibrator;
import android.util.Log;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

public class MainActivity extends Activity implements                 OnSignalsDetectedListener {

    static MainActivity mainApp;

    public static final int DETECT_NONE = 0;
    public static final int DETECT_WHISTLE = 1;
    public static int selectedDetection = DETECT_NONE;

    // detection parameters
    private DetectorThread detectorThread;
    private RecorderThread recorderThread;
    private int numWhistleDetected = 0;

    // views
    private View mainView, listeningView, helpView ;
    private Button whistleButton , whistleButton02;

    // alarmVoice()에서 사용하는 변수들  - am, mp, LOG
    private AudioManager am;
    private MediaPlayer mp;

    private String LOG = "My_Tag";

    ImageView imageView01;


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

        mainApp = this;

        // set views
//      LayoutInflater inflater = LayoutInflater.from(this);    // disable inflater

        setContentView(R.layout.main);


//      mainView = inflater.inflate(R.layout.main, null);   // disable inflater
//      listeningView = inflater.inflate(R.layout.listening, null); // disable inflater

//      setContentView(mainView);   // disable inflater

        whistleButton = (Button) this.findViewById(R.id.whistleButton); // Start button
        whistleButton.setOnClickListener(new ClickEvent());

        whistleButton02 = (Button) this.findViewById(R.id.whistleButton02); // ReadMe button
        whistleButton02.setOnClickListener(new ClickEvent());

    }

    private void goHomeView() {
        setContentView(mainView);
        if (recorderThread != null) {
            recorderThread.stopRecording();
            recorderThread = null;
        }
        if (detectorThread != null) {
            detectorThread.stopDetection();
            detectorThread = null;
        }
        selectedDetection = DETECT_NONE;
    }

    private void goListeningView() {
        //setContentView(listeningView);
        setContentView(R.layout.listening);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        menu.add(0, 0, 0, "Exit");
        return super.onCreateOptionsMenu(menu);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
        case 0:
            NotificationManager notiMgr = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
            notiMgr.cancel(999);    // Notification의 고유 id가 999인 것을 찾아서 notification을 종료한다.

            finish();
            break;
        default:
        }
        return super.onOptionsItemSelected(item);
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
            goHomeView();
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }

    class ClickEvent implements OnClickListener {
        public void onClick(View view) {


            if (view == whistleButton) {
                selectedDetection = DETECT_WHISTLE;
                recorderThread = new RecorderThread();
                recorderThread.start();
                detectorThread = new DetectorThread(recorderThread);
                detectorThread.setOnSignalsDetectedListener(MainActivity.mainApp);
                detectorThread.start(); 
                goListeningView();

            }

            if(view == whistleButton02)
            {
                Intent intent = new Intent(MainActivity.this, help.class );
                startActivity(intent);

            }
        }
    }


    private void Threadsleep(DetectorThread detectorThread){
        try
        {
            detectorThread.sleep(1000);
        }

        catch(InterruptedException e)
        {
            e.printStackTrace();
        }

    }

    protected void onDestroy() {
        super.onDestroy();
    }

    @Override
    public void onWhistleDetected() {
        runOnUiThread(new Runnable() {
            public void run() {

                 TextView textView = (TextView)
                 MainActivity.mainApp.findViewById(R.id.detectedNumberText);                 
                 textView.setText(String.valueOf(numWhistleDetected++));

                if (numWhistleDetected > 1) {
                    setEvent();                 
                }
            }
        });

        Threadsleep(detectorThread);
    }

}
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" 
    android:background="@drawable/car">

    <Button 
        android:id="@+id/whistleButton"
        android:layout_width="150dp"
        android:layout_height="40dp"
        android:gravity="center"
        android:text="Start"
        android:textSize="20dp"  
        android:background="#FFFFFFFF"
        android:textColor="#FF000000"
        android:padding="5dp"
        android:layout_centerInParent = "true"      
        />

    <Button
        android:id="@+id/whistleButton02"
        android:layout_width="150dp"
        android:layout_height="40dp"
        android:layout_below="@id/whistleButton"
        android:gravity="center"     
        android:text="ReadMe"
        android:background="#FFFFFFFF"
        android:textColor="#FF000000"
        android:textSize="20dp" 
        android:layout_marginTop="15dp"
        android:padding="5dp"           
        android:layout_centerInParent = "true"
         />

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

    android:layout_width="fill_parent"
    android:layout_height="fill_parent" 
    android:background ="@drawable/worker"
    >

    <TextView
        android:id="@+id/listening"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:layout_centerVertical="true"
        android:layout_centerInParent="true"
        android:textSize="30dp"    
        android:text="Detecting.." />


    <TextView
        android:id="@+id/detectedText"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/listening"
        android:layout_centerInParent="true"       
        android:textSize="20dp" />       

    <TextView
        android:id="@+id/detectedNumberText"
        android:textStyle="bold"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/listening"        
        android:textSize="5dp"
        android:layout_toRightOf="@+id/detectedText"
         />

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

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_marginLeft="112dp"
        android:layout_marginTop="20dp"
        android:text="Read Me...." />

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

    <uses-sdk
        android:minSdkVersion="8" />

    <uses-permission android:name="android.permission.RECORD_AUDIO" />

    <application
        android:icon="@drawable/ear"
        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=".listening"></activity>
             <activity android:name="help"></activity>
    </application>

</manifest>


[listing.xml]

package com.musicg.demo.android;

import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.media.AudioManager;
import android.media.AudioManager.OnAudioFocusChangeListener;
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnCompletionListener;
import android.os.Bundle;
import android.os.Vibrator;
import android.util.Log;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

public class MainActivity extends Activity implements                 OnSignalsDetectedListener {

    static MainActivity mainApp;

    public static final int DETECT_NONE = 0;
    public static final int DETECT_WHISTLE = 1;
    public static int selectedDetection = DETECT_NONE;

    // detection parameters
    private DetectorThread detectorThread;
    private RecorderThread recorderThread;
    private int numWhistleDetected = 0;

    // views
    private View mainView, listeningView, helpView ;
    private Button whistleButton , whistleButton02;

    // alarmVoice()에서 사용하는 변수들  - am, mp, LOG
    private AudioManager am;
    private MediaPlayer mp;

    private String LOG = "My_Tag";

    ImageView imageView01;


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

        mainApp = this;

        // set views
//      LayoutInflater inflater = LayoutInflater.from(this);    // disable inflater

        setContentView(R.layout.main);


//      mainView = inflater.inflate(R.layout.main, null);   // disable inflater
//      listeningView = inflater.inflate(R.layout.listening, null); // disable inflater

//      setContentView(mainView);   // disable inflater

        whistleButton = (Button) this.findViewById(R.id.whistleButton); // Start button
        whistleButton.setOnClickListener(new ClickEvent());

        whistleButton02 = (Button) this.findViewById(R.id.whistleButton02); // ReadMe button
        whistleButton02.setOnClickListener(new ClickEvent());

    }

    private void goHomeView() {
        setContentView(mainView);
        if (recorderThread != null) {
            recorderThread.stopRecording();
            recorderThread = null;
        }
        if (detectorThread != null) {
            detectorThread.stopDetection();
            detectorThread = null;
        }
        selectedDetection = DETECT_NONE;
    }

    private void goListeningView() {
        //setContentView(listeningView);
        setContentView(R.layout.listening);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        menu.add(0, 0, 0, "Exit");
        return super.onCreateOptionsMenu(menu);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
        case 0:
            NotificationManager notiMgr = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
            notiMgr.cancel(999);    // Notification의 고유 id가 999인 것을 찾아서 notification을 종료한다.

            finish();
            break;
        default:
        }
        return super.onOptionsItemSelected(item);
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
            goHomeView();
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }

    class ClickEvent implements OnClickListener {
        public void onClick(View view) {


            if (view == whistleButton) {
                selectedDetection = DETECT_WHISTLE;
                recorderThread = new RecorderThread();
                recorderThread.start();
                detectorThread = new DetectorThread(recorderThread);
                detectorThread.setOnSignalsDetectedListener(MainActivity.mainApp);
                detectorThread.start(); 
                goListeningView();

            }

            if(view == whistleButton02)
            {
                Intent intent = new Intent(MainActivity.this, help.class );
                startActivity(intent);

            }
        }
    }


    private void Threadsleep(DetectorThread detectorThread){
        try
        {
            detectorThread.sleep(1000);
        }

        catch(InterruptedException e)
        {
            e.printStackTrace();
        }

    }

    protected void onDestroy() {
        super.onDestroy();
    }

    @Override
    public void onWhistleDetected() {
        runOnUiThread(new Runnable() {
            public void run() {

                 TextView textView = (TextView)
                 MainActivity.mainApp.findViewById(R.id.detectedNumberText);                 
                 textView.setText(String.valueOf(numWhistleDetected++));

                if (numWhistleDetected > 1) {
                    setEvent();                 
                }
            }
        });

        Threadsleep(detectorThread);
    }

}
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" 
    android:background="@drawable/car">

    <Button 
        android:id="@+id/whistleButton"
        android:layout_width="150dp"
        android:layout_height="40dp"
        android:gravity="center"
        android:text="Start"
        android:textSize="20dp"  
        android:background="#FFFFFFFF"
        android:textColor="#FF000000"
        android:padding="5dp"
        android:layout_centerInParent = "true"      
        />

    <Button
        android:id="@+id/whistleButton02"
        android:layout_width="150dp"
        android:layout_height="40dp"
        android:layout_below="@id/whistleButton"
        android:gravity="center"     
        android:text="ReadMe"
        android:background="#FFFFFFFF"
        android:textColor="#FF000000"
        android:textSize="20dp" 
        android:layout_marginTop="15dp"
        android:padding="5dp"           
        android:layout_centerInParent = "true"
         />

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

    android:layout_width="fill_parent"
    android:layout_height="fill_parent" 
    android:background ="@drawable/worker"
    >

    <TextView
        android:id="@+id/listening"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:layout_centerVertical="true"
        android:layout_centerInParent="true"
        android:textSize="30dp"    
        android:text="Detecting.." />


    <TextView
        android:id="@+id/detectedText"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/listening"
        android:layout_centerInParent="true"       
        android:textSize="20dp" />       

    <TextView
        android:id="@+id/detectedNumberText"
        android:textStyle="bold"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/listening"        
        android:textSize="5dp"
        android:layout_toRightOf="@+id/detectedText"
         />

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

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_marginLeft="112dp"
        android:layout_marginTop="20dp"
        android:text="Read Me...." />

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

    <uses-sdk
        android:minSdkVersion="8" />

    <uses-permission android:name="android.permission.RECORD_AUDIO" />

    <application
        android:icon="@drawable/ear"
        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=".listening"></activity>
             <activity android:name="help"></activity>
    </application>

</manifest>


[help.xml]

package com.musicg.demo.android;

import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.media.AudioManager;
import android.media.AudioManager.OnAudioFocusChangeListener;
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnCompletionListener;
import android.os.Bundle;
import android.os.Vibrator;
import android.util.Log;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

public class MainActivity extends Activity implements                 OnSignalsDetectedListener {

    static MainActivity mainApp;

    public static final int DETECT_NONE = 0;
    public static final int DETECT_WHISTLE = 1;
    public static int selectedDetection = DETECT_NONE;

    // detection parameters
    private DetectorThread detectorThread;
    private RecorderThread recorderThread;
    private int numWhistleDetected = 0;

    // views
    private View mainView, listeningView, helpView ;
    private Button whistleButton , whistleButton02;

    // alarmVoice()에서 사용하는 변수들  - am, mp, LOG
    private AudioManager am;
    private MediaPlayer mp;

    private String LOG = "My_Tag";

    ImageView imageView01;


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

        mainApp = this;

        // set views
//      LayoutInflater inflater = LayoutInflater.from(this);    // disable inflater

        setContentView(R.layout.main);


//      mainView = inflater.inflate(R.layout.main, null);   // disable inflater
//      listeningView = inflater.inflate(R.layout.listening, null); // disable inflater

//      setContentView(mainView);   // disable inflater

        whistleButton = (Button) this.findViewById(R.id.whistleButton); // Start button
        whistleButton.setOnClickListener(new ClickEvent());

        whistleButton02 = (Button) this.findViewById(R.id.whistleButton02); // ReadMe button
        whistleButton02.setOnClickListener(new ClickEvent());

    }

    private void goHomeView() {
        setContentView(mainView);
        if (recorderThread != null) {
            recorderThread.stopRecording();
            recorderThread = null;
        }
        if (detectorThread != null) {
            detectorThread.stopDetection();
            detectorThread = null;
        }
        selectedDetection = DETECT_NONE;
    }

    private void goListeningView() {
        //setContentView(listeningView);
        setContentView(R.layout.listening);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        menu.add(0, 0, 0, "Exit");
        return super.onCreateOptionsMenu(menu);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
        case 0:
            NotificationManager notiMgr = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
            notiMgr.cancel(999);    // Notification의 고유 id가 999인 것을 찾아서 notification을 종료한다.

            finish();
            break;
        default:
        }
        return super.onOptionsItemSelected(item);
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
            goHomeView();
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }

    class ClickEvent implements OnClickListener {
        public void onClick(View view) {


            if (view == whistleButton) {
                selectedDetection = DETECT_WHISTLE;
                recorderThread = new RecorderThread();
                recorderThread.start();
                detectorThread = new DetectorThread(recorderThread);
                detectorThread.setOnSignalsDetectedListener(MainActivity.mainApp);
                detectorThread.start(); 
                goListeningView();

            }

            if(view == whistleButton02)
            {
                Intent intent = new Intent(MainActivity.this, help.class );
                startActivity(intent);

            }
        }
    }


    private void Threadsleep(DetectorThread detectorThread){
        try
        {
            detectorThread.sleep(1000);
        }

        catch(InterruptedException e)
        {
            e.printStackTrace();
        }

    }

    protected void onDestroy() {
        super.onDestroy();
    }

    @Override
    public void onWhistleDetected() {
        runOnUiThread(new Runnable() {
            public void run() {

                 TextView textView = (TextView)
                 MainActivity.mainApp.findViewById(R.id.detectedNumberText);                 
                 textView.setText(String.valueOf(numWhistleDetected++));

                if (numWhistleDetected > 1) {
                    setEvent();                 
                }
            }
        });

        Threadsleep(detectorThread);
    }

}
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" 
    android:background="@drawable/car">

    <Button 
        android:id="@+id/whistleButton"
        android:layout_width="150dp"
        android:layout_height="40dp"
        android:gravity="center"
        android:text="Start"
        android:textSize="20dp"  
        android:background="#FFFFFFFF"
        android:textColor="#FF000000"
        android:padding="5dp"
        android:layout_centerInParent = "true"      
        />

    <Button
        android:id="@+id/whistleButton02"
        android:layout_width="150dp"
        android:layout_height="40dp"
        android:layout_below="@id/whistleButton"
        android:gravity="center"     
        android:text="ReadMe"
        android:background="#FFFFFFFF"
        android:textColor="#FF000000"
        android:textSize="20dp" 
        android:layout_marginTop="15dp"
        android:padding="5dp"           
        android:layout_centerInParent = "true"
         />

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

    android:layout_width="fill_parent"
    android:layout_height="fill_parent" 
    android:background ="@drawable/worker"
    >

    <TextView
        android:id="@+id/listening"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:layout_centerVertical="true"
        android:layout_centerInParent="true"
        android:textSize="30dp"    
        android:text="Detecting.." />


    <TextView
        android:id="@+id/detectedText"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/listening"
        android:layout_centerInParent="true"       
        android:textSize="20dp" />       

    <TextView
        android:id="@+id/detectedNumberText"
        android:textStyle="bold"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/listening"        
        android:textSize="5dp"
        android:layout_toRightOf="@+id/detectedText"
         />

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

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_marginLeft="112dp"
        android:layout_marginTop="20dp"
        android:text="Read Me...." />

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

    <uses-sdk
        android:minSdkVersion="8" />

    <uses-permission android:name="android.permission.RECORD_AUDIO" />

    <application
        android:icon="@drawable/ear"
        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=".listening"></activity>
             <activity android:name="help"></activity>
    </application>

</manifest>


[AndroidManifest.xml]

package com.musicg.demo.android;

import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.media.AudioManager;
import android.media.AudioManager.OnAudioFocusChangeListener;
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnCompletionListener;
import android.os.Bundle;
import android.os.Vibrator;
import android.util.Log;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

public class MainActivity extends Activity implements                 OnSignalsDetectedListener {

    static MainActivity mainApp;

    public static final int DETECT_NONE = 0;
    public static final int DETECT_WHISTLE = 1;
    public static int selectedDetection = DETECT_NONE;

    // detection parameters
    private DetectorThread detectorThread;
    private RecorderThread recorderThread;
    private int numWhistleDetected = 0;

    // views
    private View mainView, listeningView, helpView ;
    private Button whistleButton , whistleButton02;

    // alarmVoice()에서 사용하는 변수들  - am, mp, LOG
    private AudioManager am;
    private MediaPlayer mp;

    private String LOG = "My_Tag";

    ImageView imageView01;


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

        mainApp = this;

        // set views
//      LayoutInflater inflater = LayoutInflater.from(this);    // disable inflater

        setContentView(R.layout.main);


//      mainView = inflater.inflate(R.layout.main, null);   // disable inflater
//      listeningView = inflater.inflate(R.layout.listening, null); // disable inflater

//      setContentView(mainView);   // disable inflater

        whistleButton = (Button) this.findViewById(R.id.whistleButton); // Start button
        whistleButton.setOnClickListener(new ClickEvent());

        whistleButton02 = (Button) this.findViewById(R.id.whistleButton02); // ReadMe button
        whistleButton02.setOnClickListener(new ClickEvent());

    }

    private void goHomeView() {
        setContentView(mainView);
        if (recorderThread != null) {
            recorderThread.stopRecording();
            recorderThread = null;
        }
        if (detectorThread != null) {
            detectorThread.stopDetection();
            detectorThread = null;
        }
        selectedDetection = DETECT_NONE;
    }

    private void goListeningView() {
        //setContentView(listeningView);
        setContentView(R.layout.listening);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        menu.add(0, 0, 0, "Exit");
        return super.onCreateOptionsMenu(menu);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
        case 0:
            NotificationManager notiMgr = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
            notiMgr.cancel(999);    // Notification의 고유 id가 999인 것을 찾아서 notification을 종료한다.

            finish();
            break;
        default:
        }
        return super.onOptionsItemSelected(item);
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
            goHomeView();
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }

    class ClickEvent implements OnClickListener {
        public void onClick(View view) {


            if (view == whistleButton) {
                selectedDetection = DETECT_WHISTLE;
                recorderThread = new RecorderThread();
                recorderThread.start();
                detectorThread = new DetectorThread(recorderThread);
                detectorThread.setOnSignalsDetectedListener(MainActivity.mainApp);
                detectorThread.start(); 
                goListeningView();

            }

            if(view == whistleButton02)
            {
                Intent intent = new Intent(MainActivity.this, help.class );
                startActivity(intent);

            }
        }
    }


    private void Threadsleep(DetectorThread detectorThread){
        try
        {
            detectorThread.sleep(1000);
        }

        catch(InterruptedException e)
        {
            e.printStackTrace();
        }

    }

    protected void onDestroy() {
        super.onDestroy();
    }

    @Override
    public void onWhistleDetected() {
        runOnUiThread(new Runnable() {
            public void run() {

                 TextView textView = (TextView)
                 MainActivity.mainApp.findViewById(R.id.detectedNumberText);                 
                 textView.setText(String.valueOf(numWhistleDetected++));

                if (numWhistleDetected > 1) {
                    setEvent();                 
                }
            }
        });

        Threadsleep(detectorThread);
    }

}
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" 
    android:background="@drawable/car">

    <Button 
        android:id="@+id/whistleButton"
        android:layout_width="150dp"
        android:layout_height="40dp"
        android:gravity="center"
        android:text="Start"
        android:textSize="20dp"  
        android:background="#FFFFFFFF"
        android:textColor="#FF000000"
        android:padding="5dp"
        android:layout_centerInParent = "true"      
        />

    <Button
        android:id="@+id/whistleButton02"
        android:layout_width="150dp"
        android:layout_height="40dp"
        android:layout_below="@id/whistleButton"
        android:gravity="center"     
        android:text="ReadMe"
        android:background="#FFFFFFFF"
        android:textColor="#FF000000"
        android:textSize="20dp" 
        android:layout_marginTop="15dp"
        android:padding="5dp"           
        android:layout_centerInParent = "true"
         />

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

    android:layout_width="fill_parent"
    android:layout_height="fill_parent" 
    android:background ="@drawable/worker"
    >

    <TextView
        android:id="@+id/listening"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:layout_centerVertical="true"
        android:layout_centerInParent="true"
        android:textSize="30dp"    
        android:text="Detecting.." />


    <TextView
        android:id="@+id/detectedText"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/listening"
        android:layout_centerInParent="true"       
        android:textSize="20dp" />       

    <TextView
        android:id="@+id/detectedNumberText"
        android:textStyle="bold"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/listening"        
        android:textSize="5dp"
        android:layout_toRightOf="@+id/detectedText"
         />

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

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_marginLeft="112dp"
        android:layout_marginTop="20dp"
        android:text="Read Me...." />

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

    <uses-sdk
        android:minSdkVersion="8" />

    <uses-permission android:name="android.permission.RECORD_AUDIO" />

    <application
        android:icon="@drawable/ear"
        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=".listening"></activity>
             <activity android:name="help"></activity>
    </application>

</manifest>

首先,在onCreate()中使用
setContentView(R.layout.main)
而不是像Akhil提到的那样在onCreate中使用

还要将背景图像设置为活动,请在main.xml中的根容器中使用
android:background=“@drawable/image\u name”

如果尝试在lisenter中动态切换图像。 试着让我们知道它是否有效


此外,为了更好地了解main.xml的内容,您可以在
onCreate()中使用
setContentView()
来显示main.xml的内容
?您可以为省略的图像提供url,出现的问题与您省略的代码有关
static main activity main app;
nono您不这样做这是一个省略的图像url。您想运行的两个活动是否有单独的布局XML?我尝试了您的建议。但是..它不起作用…我更新了请看我的密码。