我似乎找不到我出错的地方,我想要的是按下图像按钮并进入我的第二个活动,然后单击按钮它会发出声音。任何帮助都会很棒
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 中,所以没关系