仅显示一个tetview评级

时间:2016-07-18 19:33:32

标签: java android

我正在开发一款应用程序,以帮助人们了解什么时候进行手机升级。我遇到了一个小问题,主要是在尝试测试代码的功能时。我对所有6个类别进行了评分并按下了继续按钮。只显示“游戏”的评级。我不知道发生了什么,因为我已经包含了所有六个文本视图。

Shows only one rating

爪哇:

package com.inducesmile.phoneupgrade;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.RatingBar;
import android.widget.TextView; 

public class Page1 extends Activity {
    TextView tvBatt, tvPerf, tvAttr, tvCam, tvVal, tvGame;
    RatingBar rateBattery, ratePerformance, rateCamera, rateValue, rateGaming, rateAttractiveness;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.page1);
        Init();
    }

    public void Init() {
        tvBatt = (TextView) findViewById(R.id.tvBatt);
        tvPerf = (TextView) findViewById(R.id.tvPerf);
        tvAttr = (TextView) findViewById(R.id.tvAttr);
        tvCam = (TextView) findViewById(R.id.tvCam);
        tvVal = (TextView) findViewById(R.id.tvVal);
        tvGame = (TextView) findViewById(R.id.tvGame);
        rateBattery = (RatingBar) findViewById(R.id.rateBatt);
        rateCamera = (RatingBar) findViewById(R.id.rateCam);
        rateGaming = (RatingBar) findViewById(R.id.rateGame);
        rateValue = (RatingBar) findViewById(R.id.rateValue);
        ratePerformance = (RatingBar) findViewById(R.id.Performance);
        rateAttractiveness = (RatingBar) findViewById(R.id.rateAttr);
    }

    public void onButtonClick(View v) {
        if (v.getId() == R.id.btnCont) {
            String strBatt = String.valueOf(rateBattery.getRating());
            tvBatt.setText(strBatt);
            String strAttr = String.valueOf(rateAttractiveness.getRating());
            tvAttr.setText(strAttr);
            String strCam = String.valueOf(rateCamera.getRating());
            tvCam.setText(strCam);
            String strPerf = String.valueOf(ratePerformance.getRating());
            tvPerf.setText(strPerf);
            String strGame = String.valueOf(rateGaming.getRating());
            tvGame.setText(strGame);
            String strVal = String.valueOf(rateValue.getRating());
            tvVal.setText(strVal);
        }
    }
}

的xml:

<?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:onClick="onButtonClick"
android:background="#FFF000">

 <TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textAppearance="?android:attr/textAppearanceMedium"
    android:text="How Important Are These Features to You?"
    android:id="@+id/textView2"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:textStyle="bold"
    android:textColor="#000000"/>

<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Continue"
    android:textColor="#FFFFFF"
    android:id="@+id/btnCont"
    android:background="@drawable/buttonshape"
    android:onClick="onButtonClick"
    android:layout_below="@+id/Performance"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="34dp" />

<RatingBar
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/rateBatt"
    android:layout_alignParentRight="true"
    android:layout_alignParentEnd="true"
    android:stepSize="0.5"
    android:layout_below="@+id/textView2" />

<RatingBar
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/rateGame"
    android:stepSize="0.5"
    android:layout_below="@+id/rateBatt"
    android:layout_alignParentRight="true"
    android:layout_alignParentEnd="true" />

<RatingBar
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/rateCam"
    android:layout_alignLeft="@+id/rateGame"
    android:layout_alignStart="@+id/rateGame"
    android:stepSize="0.5"
    android:layout_below="@+id/rateGame" />

<RatingBar
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/rateAttr"
    android:layout_alignParentRight="true"
    android:layout_alignParentEnd="true"
    android:stepSize="0.5"
    android:layout_below="@+id/rateCam" />

<RatingBar
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/rateValue"
    android:layout_below="@+id/rateAttr"
    android:layout_alignParentRight="true"
    android:layout_alignParentEnd="true" />

<RatingBar
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/Performance"
    android:layout_below="@+id/rateValue"
    android:layout_alignParentRight="true"
    android:layout_alignParentEnd="true" />

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textAppearance="?android:attr/textAppearanceSmall"
    android:text="Battery Life:"
    android:id="@+id/textView3"
    android:layout_below="@+id/textView2"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:layout_marginTop="21dp"
    android:textStyle="bold"/>

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textAppearance="?android:attr/textAppearanceSmall"
    android:text="Gaming:"
    android:id="@+id/textView4"
    android:layout_alignTop="@+id/rateGame"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:layout_marginTop="16dp"
    android:textStyle="bold"/>

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textAppearance="?android:attr/textAppearanceSmall"
    android:text="Camera:"
    android:id="@+id/textView5"
    android:layout_below="@+id/rateGame"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:layout_marginTop="11dp"
    android:textStyle="bold"/>

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textAppearance="?android:attr/textAppearanceSmall"
    android:text="Attractiveness:"
    android:id="@+id/textView6"
    android:layout_marginTop="14dp"
    android:layout_alignTop="@+id/rateAttr"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:textStyle="bold"/>

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textAppearance="?android:attr/textAppearanceSmall"
    android:text="Value:"
    android:id="@+id/textView7"
    android:layout_alignTop="@+id/rateValue"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:layout_marginTop="11dp"
    android:textStyle="bold"/>

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textAppearance="?android:attr/textAppearanceSmall"
    android:text="Performance:"
    android:id="@+id/textView8"
    android:layout_below="@+id/rateValue"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:layout_marginTop="12dp"
    android:textStyle="bold"/>

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/tvBatt"
    android:layout_alignTop="@+id/textView3"
    android:layout_toRightOf="@+id/textView3"
    android:layout_toEndOf="@+id/textView3"
    android:text="____" />

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/tvGame"
    android:layout_alignBottom="@+id/textView4"
    android:layout_toRightOf="@+id/textView4"
    android:layout_toEndOf="@+id/textView4"
    android:text="____" />

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/tvCam"
    android:layout_alignBottom="@+id/textView5"
    android:layout_toRightOf="@+id/textView5"
    android:layout_toEndOf="@+id/textView5"
    android:text="____" />

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/tvAttr"
    android:layout_below="@+id/textView6"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:text="____" />

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/tvVal"
    android:layout_alignBottom="@+id/textView7"
    android:layout_toRightOf="@+id/textView7"
    android:layout_toEndOf="@+id/textView7"
    android:text="____" />

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/tvPerf"
    android:layout_alignBottom="@+id/textView8"
    android:layout_toRightOf="@+id/textView8"
    android:layout_toEndOf="@+id/textView8"
    android:text="____" />

1 个答案:

答案 0 :(得分:0)

您的代码很好,请尝试重建/清理项目。

如果您使用的是Android Studio,请转到Build - &gt;清洁项目然后构建 - &gt;重建项目。