Created
April 9, 2017 08:37
-
-
Save markojerkic/502acc00fabae65520a3a93e487c5774 to your computer and use it in GitHub Desktop.
Setting up the RatingBar
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.markojerkic.viewswitch; | |
import android.support.v7.app.AppCompatActivity; | |
import android.os.Bundle; | |
import android.view.View; | |
import android.widget.Button; | |
import android.widget.RatingBar; | |
import android.widget.TextView; | |
import android.widget.ViewSwitcher; | |
public class MainActivity extends AppCompatActivity { | |
float ratingBarResult; | |
TextView textView; | |
Button switchButton; | |
ViewSwitcher viewSwitcher; | |
RatingBar ratingBar; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
switchButton = (Button) findViewById(R.id.button); | |
viewSwitcher = (ViewSwitcher) findViewById(R.id.viewSwitcher); | |
ratingBar = (RatingBar) findViewById(R.id.ratingBar); | |
textView = (TextView) findViewById(R.id.textView); | |
ratingBar.setMax(10); | |
ratingBar.setOnRatingBarChangeListener(new RatingBar.OnRatingBarChangeListener() { | |
@Override | |
public void onRatingChanged(RatingBar ratingBar, float v, boolean b) { | |
setRatingBarResult(v); //calling the method setRatingBarResult() to set the value | |
} | |
}); | |
switchButton.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View view) { | |
if(viewSwitcher.getCurrentView() == ratingBar) { | |
viewSwitcher.showNext();//if the current view is the RatingBar, then show | |
} //the next one, which is the TextView | |
else { | |
viewSwitcher.showPrevious(); | |
} | |
} | |
}); | |
} | |
public void setRatingBarResult(float l) { | |
ratingBarResult = l; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment