按下按钮声音

时间:2012-04-15 01:47:27

标签: android

我似乎无法找到我出错了我想要的是按下图像按钮并转到我的第二个活动,并点击按钮它发出声音。任何帮助都会很棒

package my.solo;

import android.app.Activity;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.text.method.ScrollingMovementMethod;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class SoloActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        final MediaPlayer mpButtonClick = 
                MediaPlayer.create(this,R.raw.button_click);

        TextView textView = (TextView)findViewById(R.id.text_view);
        textView.setMovementMethod(new ScrollingMovementMethod()); 

        Button next = (Button) findViewById(R.id.imageButton1);
        next.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
                Intent intent = new Intent(SoloActivity.this
                        , model_page.class);
                startActivity(intent);

                mpButtonClick.start();
            }
        }
    )
}

XML

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/pt5"
    android:orientation="vertical" >
    <RelativeLayout android:id="@+id/relativeLayout1"
        android:layout_width="match_parent"
        android:layout_height="fill_parent" >
        <TextView android:id="@+id/text_view"
            android:layout_width="415dp"
            android:layout_height="209dp"
            android:layout_marginLeft="300dp"
            android:layout_marginTop="50dp"
            android:maxLines="300"
            android:scrollbars="vertical"
            android:singleLine="false"
            android:text="@string/disclamer"
            android:textColor="@android:color/secondary_text_dark_nodisable"/>
        <ImageButton android:id="@+id/imageButton1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_centerHorizontal="true"
            android:layout_marginBottom="98dp"
            android:src="@drawable/stbtn2" 
            android:background="@null"/>
        <TextView android:id="@+id/textView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_centerHorizontal="true"
            android:layout_marginBottom="35dp"
            android:text="@string/P69"
            android:textSize="25dp"
            android:textStyle="bold"
            android:typeface="serif"/>
    </RelativeLayout>
</LinearLayout>

我已将第二项活动放入MF,这样就可以了

http://imageshack.us/g/638/bugjd.png/

1 个答案:

答案 0 :(得分:0)

在清单文件中有你的model_page活动吗?