我试图在textview中显示用户的评分,而我得到的只是“进程意外终止”错误。有三项活动。包含评分栏的活动的XML编码为

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
tools:context=".RatingActivity" >

 <TextView
     android:id="@+id/textView3"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:layout_centerHorizontal="true"
     android:layout_centerVertical="true"
     android:hint="@string/hello_world"
     android:textAppearance="?android:attr/textAppearanceLarge" />

</RelativeLayout>


Java编码是:

package com.example.myfirstapp;

import android.app.Activity;

import android.os.Bundle;
import android.widget.RatingBar;
import android.widget.TextView;

public class RatingActivity extends Activity
{

@Override
protected void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_rating);
    RatingBar ratingBar1=(RatingBar)findViewById(R.id.ratingBar1);
    TextView textView3 =(TextView) findViewById(R.id.textView3);
                textView3.setTextSize(40);
                textView3.setText("Rating is :"+ratingBar1.getRating());

}

}


我究竟做错了什么?我是android应用程序开发的新手。请帮助,在此先感谢。

最佳答案

RatingBar mBar = (RatingBar) findViewById(R.id.mRatingBar);
mBar.setOnClickListener(onclickbutton1);

public void onClick(View v) {

    RatingBar bar = (RatingBar) v;
    statusMessage.setText("value is " + bar.getRating());
}

07-27 22:00