第一个Androd应用-GeoQuiz,它能给出一道道地理问题,用户点击TRUE或FALSE按钮来回答屏幕上的问题,GeoQuiz及时做出反馈,首先我们来看看它完成后的样子
1.首先我们创建一个Android项目
接下来SDK的选择最低版本是4.4我选择的的是7.0,然后继续Next
选择Empty Activity,继续Next
命名activity的子类为Quizactivity,点击finsh.这样就完成了项目的创建
2.接下来就是源码,在activity_quiz.xml添加组件
然后是string.xml
GeoQuiz Canberra is the capital of Australia. The Pacific Ocean is larger than the Atlantic Ocean. The Suez Canal connects the Red Sea and the Indian Ocean. The source of the Nile River is in Egypt. The Amazon River is the longest river in the Americas. Lake Baikal is the world\'s oldest and deepest freshwater lake. True False Next Correct! Incorrect! Are you sure you want to do this? SHOW ANSWER CHEAT! Cheating is wrong. NEXT PTEV
和activity_cheat.xml
3.创建数组对象,与Textview和button交互,对用户的回答做出反应
![](https://images2017.cnblogs.com/blog/1241784/201709/1241784-20170917210312063-1792626596.png)
4.设置监听器@Override public void onClick(View v) { if (mAnswerIsTrue) { mAnswerTextView.setText(R.string.true_button); } else { mAnswerTextView.setText(R.string.false_button); } setAnswerShownResult(true); }