Click here to Skip to main content
15,896,453 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
This is my intent code that is in my DetailActivity. The DetailActivity host the ratingBar with five stars.

public void finish() {
Intent intent = new Intent();
Toast.makeText(NewsDetailActivity.this,
"Rating Bar Clicked",
Toast.LENGTH_LONG).show();
intent.putExtra("title", title);
intent.putExtra("rating", "rating");
setResult(RESULT_OK, intent);
super.finish();

This is the code that is in my mainActivity. The goal is for the user to select the stars to rate. When the back button is pushed to the previous screen which is the mainActivity the alert will prompt amount/value that was selected in the detailActivity.

protected void onActivityResult(int requestCode, int resultCode, Intent data){
super.onActivityResult(requestCode, resultCode, data);
Log.i(TAG,"onActivityResult");

if (resultCode == RESULT_OK ) {
if (data.hasExtra("title") && data.hasExtra("rating")) {
String title = data.getExtras().getString("title");
float action = data.getExtras().getFloat("rating");

Toast.makeText(MainActivity.this, "Lets Go", Toast.LENGTH_LONG).show();

AlertDialog alertDialog = new AlertDialog.Builder(this).create();
alertDialog.setTitle("This is the article rating");
alertDialog.setMessage("rating is how many stars");
alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.dismiss();

}
});
alertDialog.show();
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900