Stumped – Adding a Listener to TextView and Adding a Previous Button to GeoQuiz Challenge
Stumped – Adding a Listener to TextView and Adding a Previous Button to GeoQuiz Challenge
This is only for android proficient tutors.
This is from the 2nd Edition Android Programming Big Nerd Ranch Guide – Chapter 2.
This was for my Listener, added to the Quiz activity:
mQuestionTextView = (TextView)findViewById(R.id.question_text_view); mQuestionTextView.setOnClickListener(new View.OnClickListener(){ @Override public void onClick(View V){ mCurrentIndex = (mCurrentIndex+1)%mQuestionBank.length; updateQueston(); }
I added this to the XML:
<TextView android_id="@+id/question_text_view" android_layout_width="wrap_content" android_layout_height="wrap_content" android_padding="24dp" android_clickable="true"/>
This still isn't functioning as a proper listener :|
In addition, I need to add a ‘previous button’ to pull users back to the previous question, but for some reason my code isn’t working. I could use some help in getting this to work.
In my strings xml file, I added this:
<string name=”prev_question_button”>Previous</string>
Changed the new layout xml to this:
<Button android_id=”@+id/previous_button” android_layout_width=”wrap_content” android_layout_height=”wrap_content” android_text=”@string/prev_question_button” android_drawableLeft=”@drawable/arrow_left” android_drawablePadding=”4dp”/> <Button android_id=”@+id/next_button” android_layout_width=”wrap_content” android_layout_height=”wrap_content” android_text=”@string/next_question_button” android_drawableRight=”@drawable/arrow_right” android_drawablePadding=”4dp”/>
My activity looks like this:
mPrevButton = (Button)findViewById(R.id.prev_button); mPrevButton.setOnClickListener(new View.OnClickListener(){ @Override public void onClick(View v) { if (mCurrentIndex == 0) { mCurrentIndex = mQuestionBank.length – 1; } else { mCurrentIndex = mCurrentIndex – 1; } updateQueston(); } });
I’m getting errors when I build the project… some help would be much appreciated to get this up and running!
Be sure you have maven and updated to the gradle version 3.0.1
Attached is a zip of my progress…