我试图在此代码上放置评级栏明星而不是微调器,但一次又一次地出现错误。请有人帮帮我。谢谢
<RatingBar
android:id="@+id/review_rating"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:numStars="3"
android:stepSize="1.0"
android:entries="@array/rating"
android:rating="2.0" />
</RatingBar>
AddReviewActivity.class
package com.example.facilitiesreviewapp;
public class AddReviewActivity extends ActionBarActivity {
String id;
@Override
protected void onCreate(Bundle savedInstanceState) {
setTitle("Add Reviews");
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_add_review);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.add_review, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
Intent intent;
if (id == R.id.search_station) {
intent = new Intent(this, SearchActivity.class);
startActivity(intent);
}
else if (id == R.id.add_station) {
intent = new Intent(this, AddStationActivity.class);
startActivity(intent);
}
return super.onOptionsItemSelected(item);
}
public void onResume() {
super.onResume();
Intent intent = getIntent();
id = intent.getStringExtra(SearchActivity.EDITID);
}
public void saveReview(View view) {
//Get fields
EditText dateView = (EditText) findViewById(R.id.review_date);
EditText commentView = (EditText) findViewById(R.id.review_comments);
ratingBar ratingView = (ratingBar) findViewById(R.id.review_rating);
Spinner featureView = (Spinner) findViewById(R.id.review_feature);
//Get Content
String review_date = dateView.getText().toString();
String review_comment = commentView.getText().toString();
String review_rating = ratingView.getSelectedItem().toString();
String review_feature = featureView.getSelectedItem().toString();
//Validation
boolean errors = false;
String error_msg = "";
if (review_date.equals("")) {
errors = true;
error_msg += "Date field is required";
}
if (errors) {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage(error_msg).setTitle("Error in submission");
AlertDialog dialog = builder.create();
dialog.show();
}
else {
DbHandler dbh = new DbHandler(this);
SQLiteDatabase db = dbh.getWritableDatabase();
ContentValues values = new ContentValues();
values.put(DbHandler.ReviewHandler.COLUMN_NAME_STATION_ID, id);
values.put(DbHandler.ReviewHandler.COLUMN_NAME_DATE, review_date);
values.put(DbHandler.ReviewHandler.COLUMN_NAME_FEATURE, review_feature);
values.put(DbHandler.ReviewHandler.COLUMN_NAME_RATING, review_rating);
values.put(DbHandler.ReviewHandler.COLUMN_NAME_COMMENTS, review_comment);
long newRowID = db.insert(DbHandler.ReviewHandler.Table_Name, "", values);
db.close();
dbh.close();
Intent intent = new Intent(this, ReviewsActivity.class);
intent.putExtra(SearchActivity.EDITID, id);
startActivity(intent);
}
}
}