I'm using Parse to pass objects as strings and populate the text of 4 buttons for a quiz app.
Since the response options will vary, I've implemented an if
statement to hide a button in case a string is not available.
Doing some trial runs, I can't get the button to hide when there isn't a string available.
Here's my code:
activity_quiz.xml
<Button
android:layout_width="200dp"
android:layout_height="40dp"
android:text="Hello"
android:id="@+id/firstOption"
android:visibility="invisible"
android:onClick="one"
android:layout_gravity="center_horizontal"
android:background="@drawable/shapes"
android:textColor="#ebf4fa"
android:layout_marginRight="30dp" />
Quiz.java
public class Quiz extends Activity {
TextView questionDisplay;
Button first;
String firstChoice;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_quiz);
first = (Button) findViewById(R.id.firstOption);
first.setTypeface(custom_font);
firstChoice = first.getText().toString();
ParseQuery<ParseObject> vote = ParseQuery.getQuery("quizAndroid");
vote.findInBackground(new FindCallback<ParseObject>() {
@Override
public void done(List<ParseObject> items, ParseException e) {
if (e == null) {
for (ParseObject x : items) {
String display = x.getString("question");
questionDisplay.setText(display);
if (firstChoice.length() > 0) {
firstChoice = x.getString("optionone");
first.setVisibility(View.VISIBLE);
first.setText(firstChoice);
} else {
first.setVisibility(View.INVISIBLE);
}
Aucun commentaire:
Enregistrer un commentaire