I am developing an app to help people know when it is time for a phone upgrade. I ran into a little problem along the way, mainly when trying to test the functionality of the code. I rated all 6 categories and pressed the continue button. Only the rating for the "Game" shows up. I don't know what is going on since I have all six textviews included.
Java:
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="____" />
Your code is fine, try rebuild/clean the project.
If you're using Android Studio, go to Build -> Clean Project and then Build -> Rebuild Project.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.