so i want to make a simple quiz with android studio. and then i have already make the quiz and it work so well. my quiz use text as the questions and the answers. instead of using text, i want to make an image as the questions and the answers as well. any suggestion to do that ? (sorry i'm very new to programming, and also this is my first semester)
here's the code of my previous quiz (text as the question and the answers)
code for question bank :
public class QuestionBank {
private String textQuestions [] = {
"1. What is the most populated country in the world ?",
"2. Who is the first president of USA ?",
"3. What animal that can fly ?",
"4. 1000 + 945 = ?",
"5. What year now ?"
};
// array of multiple choices for each question
private String multipleChoice [][] = {
{"Russia", "China", "USA", "Brazil"},
{"Obama", "Vladimir Putin", "George Washington", "Donald Trump"},
{"Fish", "Cat", "Bird", "Snake"},
{"1999", "2018", "1945", "2000"},
{"1999", "2000", "2010", "2018"}
};
private String mCorrectAnswers[] = {"China", "George Washington", "Bird",
"1945", "2018"};
public int getLength(){
return textQuestions.length;
}
public String getQuestion(int a) {
String question = textQuestions[a];
return question;
}
public String getChoice(int index, int num) {
String choice0 = multipleChoice[index][num-1];
return choice0;
}
public String getCorrectAnswer(int a) {
String answer = mCorrectAnswers[a];
return answer;
}
}
and here is the code for quiz activity code :
public class QuizActivity extends AppCompatActivity {
private QuestionBank mQuestionLibrary = new QuestionBank();
private TextView mScoreView;
private TextView mQuestionView;
private Button mButtonChoice1;
private Button mButtonChoice2;
private Button mButtonChoice3;
private Button mButtonChoice4;
private String mAnswer;
private int mScore = 0;
private int mQuestionNumber = 0;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_quiz);
mScoreView = (TextView)findViewById(R.id.score);
mQuestionView = (TextView)findViewById(R.id.question);
mButtonChoice1 = (Button)findViewById(R.id.choice1);
mButtonChoice2 = (Button)findViewById(R.id.choice2);
mButtonChoice3 = (Button)findViewById(R.id.choice3);
mButtonChoice4 = (Button)findViewById(R.id.choice4);
updateQuestion();
updateScore(mScore);
}
private void updateQuestion(){
//
if(mQuestionNumber<mQuestionLibrary.getLength() ){
mQuestionView.setText(mQuestionLibrary.getQuestion(mQuestionNumber));
mButtonChoice1.setText(mQuestionLibrary.getChoice(mQuestionNumber, 1));
mButtonChoice2.setText(mQuestionLibrary.getChoice(mQuestionNumber, 2));
mButtonChoice3.setText(mQuestionLibrary.getChoice(mQuestionNumber, 3));
mButtonChoice4.setText(mQuestionLibrary.getChoice(mQuestionNumber,4));
mAnswer = mQuestionLibrary.getCorrectAnswer(mQuestionNumber);
mQuestionNumber++;
}
else {
Toast.makeText(QuizActivity.this, "It was the last question!",
Toast.LENGTH_SHORT).show();
Intent intent = new Intent(QuizActivity.this,
HighestScoreActivity.class);
intent.putExtra("score", mScore); // pass the current score to
the second screen
startActivity(intent);
}
}
private void updateScore(int point) {
mScoreView.setText("" + mScore+"/"+mQuestionLibrary.getLength());
}
public void onClick(View view) {
//all logic for all answers buttons in one method
Button answer = (Button) view;
// if the answer is correct, increase the score
if (answer.getText() == mAnswer){
mScore = mScore + 1;
Toast.makeText(QuizActivity.this, "Benar!",
Toast.LENGTH_SHORT).show();
}else
Toast.makeText(QuizActivity.this, "Salah!",
Toast.LENGTH_SHORT).show();
updateScore(mScore);
updateQuestion();
}
}
Instead of your string arrays ,write an array which stores the images from the drawable folder like this
private Integer[] mThumbIds = {
R.drawable.sample_2, R.drawable.sample_3,
R.drawable.sample_4, R.drawable.sample_5,
R.drawable.sample_6, R.drawable.sample_7,
R.drawable.sample_0, R.drawable.sample_1,
R.drawable.sample_2, R.drawable.sample_3,
R.drawable.sample_4, R.drawable.sample_5,
R.drawable.sample_6, R.drawable.sample_7
};
Then in your xml instead of TextView you can use ImageView and instead of button you can use ImageButton.After that ,you can set your ImageView and ImageButton like
imageview= (ImageView)findViewById(R.id.imageView);
imageview.setImageDrawable(getResources().getDrawable(mThumbIds[1]));
Related
The program is supposed to use the premade question and answers and check if the true or false button is pressed. It has a main activity file and one class file called Question, but when it's ran the output says that "error: local variable questions is accessed from within inner class; needs to be declared final", how do I fix it? adding the final keyword in front of the array list declaration doesn't work, thanks.
public class MainActivity extends Activity {
private TextView display_question;
private TextView display_result;
private static int rand_int;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Random random = new Random();
display_question = findViewById(R.id.txt_question);
display_result = findViewById(R.id.txt_result);
ArrayList<Question> questions; //in class method
questions = Question.getQuestions(); //in class method, arraylist
rand_int = random.nextInt(4);
display_question.setText(questions.get(rand_int).getQuestion());// where i is an integer
Button btn_true = findViewById(R.id.btn_true);
btn_true.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
boolean input = true;
String output = "correct answer";
String output2 = "incorrect answer";
if (questions.get(rand_int).isAnswer()==input){
display_result.setText(output);
}
else {
display_result.setText(output2);
}
}
});
Button btn_false = findViewById(R.id.btn_false);
btn_false.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
boolean input = false;
String output = "correct answer";
String output2 = "incorrect answer";
if (questions.get(rand_int).isAnswer()==input){
display_result.setText(output);
}
else {
display_result.setText(output2);
}
}
});
Button btn_next = findViewById(R.id.btn_next);
btn_next.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
rand_int = random.nextInt(4);
display_question.setText(questions.get(rand_int).getQuestion());// where i is an integer
}
});
}
}
Question class:
import java.util.ArrayList;
public class Question {
private String question;
private boolean answer;
private Question(String question, boolean answer) {
this.question = question;
this.answer = answer;
}
public String getQuestion() {
return question;
}
public boolean isAnswer() {
return answer;
}
public static ArrayList<Question> getQuestions(){
ArrayList<Question> questions = new ArrayList<>();
questions.add(new Question("B", false));
questions.add(new Question("A", true));
questions.add(new Question("c", false));
questions.add(new Question("d", false));
questions.add(new Question("e", true));
return questions;
}
}
I am making a math quiz where a mathematical question will be asked in the form of a formula. I put my questions in an ArrayList:
public class DEasy extends AppCompatActivity {
private TextView countLabel;
private TextView questionLabel;
private Button answerBtn1;
private Button answerBtn2;
private Button answerBtn3;
private Button answerBtn4;
private String rightAnswer;
private int rightAnswerCount = 0;
private int quizCount = 1;
static final private int QUIZ_COUNT = 10;
ArrayList<ArrayList<String>> quizArray = new ArrayList<>();
String quizData[][] = {
{"x", "1", "0", "x", "-1"},
{"x²", "2x", "x", "2/x²", "2x²"},
{"64", "0", "1", "64", "8"},
{"x² + 5x", "2x + 5", "7x", "2x", "½x + 5"},
{"19x", "19", "x", "0", "x + 19"},
{"642", "34", "97", "5x-2", "1"}
};
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_deasy);
countLabel = (TextView) findViewById(R.id.countLabel);
questionLabel = (TextView) findViewById(R.id.questionLabel);
answerBtn1 = (Button) findViewById(R.id.answerBtn1);
answerBtn2 = (Button) findViewById(R.id.answerBtn2);
answerBtn3 = (Button) findViewById(R.id.answerBtn3);
answerBtn4 = (Button) findViewById(R.id.answerBtn4);
for (int i = 0; i < quizData.length; i++) {
ArrayList<String> tmpArray = new ArrayList<>();
tmpArray.add(quizData[i][0]);
tmpArray.add(quizData[i][1]);
tmpArray.add(quizData[i][2]);
tmpArray.add(quizData[i][3]);
tmpArray.add(quizData[i][4]);
quizArray.add(tmpArray);
}
showNextQuiz();
}
public void showNextQuiz() {
countLabel.setText( getString(R.string.question) + " " + quizCount + ".");
Random random = new Random();
int randomNum = random.nextInt(quizArray.size());
ArrayList<String> quiz = quizArray.get(randomNum);
questionLabel.setText(quiz.get(0));
rightAnswer = quiz.get(1);
quiz.remove(0);
Collections.shuffle(quiz);
answerBtn1.setText(quiz.get(0));
answerBtn2.setText(quiz.get(1));
answerBtn3.setText(quiz.get(2));
answerBtn4.setText(quiz.get(3));
quizArray.remove(randomNum);
}
public void checkAnswer(View view){
Button answerBtn = (Button) findViewById(view.getId());
String btnText = answerBtn.getText().toString();
String alertTitle;
if (btnText.equals(rightAnswer)){
alertTitle = "Correct";
rightAnswerCount++;
}
else {
alertTitle = "Wrong";
}
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(alertTitle);
builder.setMessage("Answer: " + rightAnswer);
builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialogInterface, int i) {
if (quizCount == QUIZ_COUNT){
Intent intent = new Intent(getApplicationContext(), DResult.class);
intent.putExtra("RIGHT_ANSWER_COUNT", rightAnswerCount);
startActivity(intent);
}
else{
quizCount++;
showNextQuiz();
}
}
});
builder.setCancelable(false);
builder.show();
}
}
As you can see I tried to make the formula x^2, this wil not be shown as x with a small exponent 2 but as x^2. This x^2 is not what I want. How can I used for example html in this arraylist to achieve this goal. Or is there another way?
Thanks aton!
Here in replacement of "^" we can use this: "∧".
So now replace code at where you accessing this string array in Adapter as:
Html.fromHtml(quizArray[][])
Thanks and happy coding
EDITED:
Here change it as:
questionLabel.setText(Htm.fromHtml(quiz.get(0)));
Just it will work
can you help me please
I have a quiz application and i get the questions and answers from database ..answers must put in two diminution string array .. i am adding them first in an array-list by for loop .. and then i have to convert this array-list to string array .. and this is the problem .. i am getting this exception
java.lang.ArrayStoreException: source[0] of type java.util.ArrayList cannot be stored in destination array of type java.lang.String[][]
package com.example.asd.cloudproject;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
import com.kosalgeek.asynctask.AsyncResponse;
import com.kosalgeek.asynctask.PostResponseAsyncTask;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
public class QuizActivity extends AppCompatActivity implements AsyncResponse {
// private QuestionLibrary mQuestionLibrary = new QuestionLibrary();
private TextView mScoreView;
private TextView mQuestionView;
private Button mButtonChoice1;
private Button mButtonChoice2;
private Button mButtonChoice3;
private String mAnswer;
private int mScore = 0;
private int mQuestionNumber = 0;
String username;
String password;
UserSessionManager session;
private String mChoices [][];
private String mQuestions [];
private String mCorrectAnswers[];
ArrayList<String> quetionArrayList= new ArrayList<String>();
ArrayList<String> answerArrayList= new ArrayList<String>();
ArrayList<String> correctArrayList= new ArrayList<String>();
//List<String[]> listOfLists = new ArrayList<>();
ArrayList<ArrayList<String>> listOfLists = new ArrayList<ArrayList<String>>();
ArrayList<String> temp = new ArrayList<String>(); // added ()
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_quiz);
mScoreView = (TextView)findViewById(R.id.score);
mQuestionView = (TextView)findViewById(R.id.question);
mButtonChoice1 = (Button)findViewById(R.id.choice1);
mButtonChoice2 = (Button)findViewById(R.id.choice2);
mButtonChoice3 = (Button)findViewById(R.id.choice3);
//check user login
session =new UserSessionManager(getApplicationContext());
if (session.checkLogin())
finish();
HashMap<String,String> user =session.getUserDetails();
username=user.get(UserSessionManager.KEY_NAME);
password=user.get(UserSessionManager.KEY_PASSWORD);
HashMap postdata=new HashMap();
postdata.put("user_name",username);
postdata.put("password",password);
PostResponseAsyncTask task=new PostResponseAsyncTask(this,postdata);
task.execute("http://10.0.2.2/quiz.php");
// updateQuestion();
//Start of Button Listener for Button1
mButtonChoice1.setOnClickListener(new View.OnClickListener(){
#Override
public void onClick(View view){
//My logic for Button goes in here
if (mButtonChoice1.getText() == mAnswer){
mScore = mScore + 1;
updateScore(mScore);
updateQuestion();
//This line of code is optiona
Toast.makeText(QuizActivity.this, "correct", Toast.LENGTH_SHORT).show();
}else {
Toast.makeText(QuizActivity.this, "wrong", Toast.LENGTH_SHORT).show();
updateQuestion();
}
}
});
//End of Button Listener for Button1
//Start of Button Listener for Button2
mButtonChoice2.setOnClickListener(new View.OnClickListener(){
#Override
public void onClick(View view){
//My logic for Button goes in here
if (mButtonChoice2.getText() == mAnswer){
mScore = mScore + 1;
updateScore(mScore);
updateQuestion();
//This line of code is optiona
Toast.makeText(QuizActivity.this, "correct", Toast.LENGTH_SHORT).show();
}else {
Toast.makeText(QuizActivity.this, "wrong", Toast.LENGTH_SHORT).show();
updateQuestion();
}
}
});
//End of Button Listener for Button2
//Start of Button Listener for Button3
mButtonChoice3.setOnClickListener(new View.OnClickListener(){
#Override
public void onClick(View view){
//My logic for Button goes in here
if (mButtonChoice3.getText() == mAnswer){
mScore = mScore + 1;
updateScore(mScore);
updateQuestion();
//This line of code is optiona
Toast.makeText(QuizActivity.this, "correct", Toast.LENGTH_SHORT).show();
}else {
Toast.makeText(QuizActivity.this, "wrong", Toast.LENGTH_SHORT).show();
updateQuestion();
}
}
});
//End of Button Listener for Button3
}
private void updateQuestion(){
mQuestionView.setText(getQuestion(mQuestionNumber));
mButtonChoice1.setText(getChoice1(mQuestionNumber));
mButtonChoice2.setText(getChoice2(mQuestionNumber));
mButtonChoice3.setText(getChoice3(mQuestionNumber));
mAnswer = getCorrectAnswer(mQuestionNumber);
mQuestionNumber++;
}
private void updateScore(int point) {
mScoreView.setText("" + mScore);
}
///////////////////////////////////////
#Override
public void processFinish(String s) {
String[] separated = s.split("#");
int i =separated.length;
String[] items;
String[] answers;
// String[][] Choices = new String[0][];
// String[] separated = s.split("$");
//Integer COUNT = stringArrayList.size();
for (int t = 0; t <i; t++) {
items=separated[t].split(":");
String vquestion=items[0].toString();
String vanswer=items[1].toString();
String vcorrect=items[2].toString();
quetionArrayList.add(vquestion);
answerArrayList.add(vanswer);
correctArrayList.add(vcorrect);
}
int y=answerArrayList.size();
String[] ans = new String[y];
ans = answerArrayList.toArray(ans);
///////////
mQuestions =new String[quetionArrayList.size()];
mQuestions = quetionArrayList.toArray(mQuestions);
mCorrectAnswers=new String[correctArrayList.size()];
mCorrectAnswers = correctArrayList.toArray(mCorrectAnswers);
////////////////////////
for(int x=0 ; x<y ; x++){
answers=ans[x].split("&");
temp.add(answers[0]);
temp.add(answers[1]);
temp.add(answers[2]);
temp.add(answers[3]);
listOfLists.add(temp);
temp.clear();
}
///// here is the problem //////
mChoices = new String[4][listOfLists.size()];
mChoices = listOfLists.toArray(mChoices);
//String ch =mChoices[2][1].toString();
}
public String getQuestion(int a) {
String question = mQuestions[a];
return question;
}
public String getChoice1(int a) {
String choice0 = mChoices[a][0];
return choice0;
}
public String getChoice2(int a) {
String choice1 = mChoices[a][1];
return choice1;
}
public String getChoice3(int a) {
String choice2 =mChoices[a][2];
return choice2;
}
public String getCorrectAnswer(int a) {
String answer = mCorrectAnswers[a];
return answer;
}
}
I have a trivia game that displays 10 questions and they each have a 10 second timer. I have 2 problems that do not function correctly.
Firstly, If the timer runs out on a question, it displays the next question but the timer does not reset. The textviews stay at "Time's up!" and "Time Elapsed: 10000" instead of restarting the timer on the new question that is displayed.
Lastly, on the Results page the correct score is not displayed in the textview. The percentage textview displays correctly but the score textview displays "android.widget.TextView#416473c" or some other random memory location.
The program never crashes just functions incorrectly. Any code structure or other suggestions is much appreciated! This is my first android mobile app attempt and I am slowly and strugglingly through it. Yet enjoying it! :)
QuesteionView.java
public class QuestionView extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.questionviewmain);
answer1 = (Button)findViewById(R.id.answer1);
answer2 = (Button)findViewById(R.id.answer2);
answer3 = (Button)findViewById(R.id.answer3);
answer4 = (Button)findViewById(R.id.answer4);
question = (TextView)findViewById(R.id.question);
queries = getIntent().getParcelableArrayListExtra("queries");
timer = (TextView)findViewById(R.id.timer);
timeElapsedView = (TextView)findViewById(R.id.timeElapsedView);
cdTimer = new Timer(startTime, interval);
loadQuestion();
}
public void loadQuestion() {
if(i == 9) {
endQuiz();
} else {
if(!timerHasStarted) {
cdTimer.start();
timerHasStarted = true;
} else {
cdTimer.cancel();
timerHasStarted = false;
}
answer = queries.get(i).getCorrectAnswer();
question.setText(queries.get(i).getQuery());
answer1.setText(queries.get(i).getA1());
answer2.setText(queries.get(i).getA2());
answer3.setText(queries.get(i).getA3());
answer4.setText(queries.get(i).getA4());
answer1.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
queries.get(i).setSelectedAnswer(0);
if(answer == 0) {
correctAnswers++;
nextQuestion();
} else {
wrongAnswers++;
nextQuestion();
}
}
});
//same type of code for buttons for answers 2 through 4.
}
}
public void nextQuestion() {
score = score + timeElapsed;
i++;
loadQuestion();
}
public class Timer extends CountDownTimer {
public Timer(long startTime, long interval) {
super(startTime, interval);
}
public void onFinish() {
if(i == 9) {
cdTimer.cancel();
} else {
timer.setText("Time's up!");
timeElapsedView.setText("Time Elapsed: " + String.valueOf(startTime));
wrongAnswers++;
nextQuestion();
}
}
public void onTick(long millisUntilFinished) {
timer.setText("Time remain: " + Long.toString(millisUntilFinished));
timeElapsed = startTime - millisUntilFinished;
timeElapsedView.setText("Time Elapsed: " + Long.toString(timeElapsed));
}
}
public void endQuiz() {
Intent intent = new Intent(QuestionView.this, Results.class);
intent.putExtra("correctAnswers", correctAnswers);
intent.putExtra("wrongAnswers", wrongAnswers);
intent.putExtra("score", score);
intent.putParcelableArrayListExtra("queries", queries);
startActivity(intent);
}
}
Results.java
public class Results extends Activity {
QuestionView qv = new QuestionView();
ArrayList<Question> queryList = qv.getQueries();
int cAnswers;
int wAnswers;
long score;
ArrayList<Question> qs;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.resultsmain);
cAnswers = getIntent().getIntExtra("correctAnswers", -1);
wAnswers = getIntent().getIntExtra("wrongAnswers", -1);
score = getIntent().getLongExtra("score", -1);
qs = getIntent().getParcelableArrayListExtra("queries");
Button mainmenuBtn = (Button)findViewById(R.id.mainmenuBtn);
mainmenuBtn.setText("Main Menu");
mainmenuBtn.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
restart();
}
});
showResults();
}
public void showResults() {
ArrayList<TextView> tList = new ArrayList<TextView>(9);
TextView header = (TextView)findViewById(R.id.header);
header.setText("SUMMARY");
TextView percentage = (TextView)findViewById(R.id.percentage);
percentage.setText(Integer.toString(10 * cAnswers) + "%");
TextView score = (TextView)findViewById(R.id.score);
String s = "" + score;
score.setText(s);
TextView q1 = (TextView)findViewById(R.id.q1);
TextView q2 = (TextView)findViewById(R.id.q2);
TextView q3 = (TextView)findViewById(R.id.q3);
TextView q4 = (TextView)findViewById(R.id.q4);
TextView q5 = (TextView)findViewById(R.id.q5);
TextView q6 = (TextView)findViewById(R.id.q6);
TextView q7 = (TextView)findViewById(R.id.q7);
TextView q8 = (TextView)findViewById(R.id.q8);
TextView q9 = (TextView)findViewById(R.id.q9);
TextView q10 = (TextView)findViewById(R.id.q10);
tList.add(q1);
tList.add(q2);
tList.add(q3);
tList.add(q4);
tList.add(q5);
tList.add(q6);
tList.add(q7);
tList.add(q8);
tList.add(q9);
tList.add(q10);
for(int i = 0; i < tList.size(); i++) {
tList.get(i).setText(qs.get(i).getQuery());
if(qs.get(i).getSelectedAnswer() == qs.get(i).getCorrectAnswer()) {
tList.get(i).setTextColor(Color.GREEN);
} else {
tList.get(i).setTextColor(Color.RED);
}
}
}
public void restart() {
Intent intent = new Intent(Results.this, MainMenu.class);
startActivity(intent);
}
}
From all of that code, this is what I think is happening
Firstly, If the timer runs out on a question, it displays the next question but the timer does not reset. The textviews stay at "Time's up!" and "Time Elapsed: 10000" instead of restarting the timer on the new question that is displayed.
This appears to be due to you not setting your timerHasStarted variable to false after the time runs out so I would set that to false probably when you load your next question or after you show the results.
Lastly, on the Results page the correct score is not displayed in the textview. The percentage textview displays correctly but the score textview displays "android.widget.TextView#416473c" or some other random memory location.
This is because you are setting your q variables to the textview and getting the id. You need something like q1.getText().toString()
You have multiple variables with the same name score. So change it to
TextView score2 = (TextView)findViewById(R.id.score);
String s = "" + score;
score2.setText(s);
the score displays not what you expected because you assigned the String s = "" + score where score is what you named for the Textview which obviously not an integer and not equivalent to the score that the user has. :)
EDIT*: FOR hovanessyan
private String getWheelValue(int id) {
WheelView wheel = getWheel(R.id.passw_1);
int index = wheel.getCurrentItem();
((ArrayWheelAdapter<String>) wheel.getViewAdapter()).getItemText(index).toString();
final String values = getWheelValue(R.id.passw_1) + " " + getWheelValue(R.id.passw_2) + " " + getWheelValue(R.id.passw_3);
First, your code will not compile because of :
initWheel(R.id.passw_2, new String[] { "Are", "Going", ""Went });
initWheel(R.id.passw_3, new String[] { "There", "Here", ""Away });
Your button is not clicking, because in the presented code, you never call getWheelValue()
You should get reference to your button and attach onClickListener, in your onCreate() method.
You should start your changes with something like...
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.passw_layout);
initWheel(R.id.passw_1, new String[] { "You", "Me", "Us" });
initWheel(R.id.passw_2, new String[] { "Are", "Going", "Went" });
initWheel(R.id.passw_3, new String[] { "There", "Here", "Away" });
Button mix = (Button) findViewById(R.id.btn_mix);
mix.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
mixWheel(R.id.passw_1);
mixWheel(R.id.passw_2);
mixWheel(R.id.passw_3);
}
});
Button share = (Button) findViewById(R.id.btn_share);
share.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// call some other methods before that I guess...
String values = getAllWheelValues();
startActivity(createEmailIntent(values));
}
});
}
private Intent createEmailIntent(String values) {
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setType("text/plain");
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, getResources().getString(R.string.Subject));
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, values);
return emailIntent;
}
EDIT:
I think you should have something like, and call getAllWheelValues() in the onClick() of share button:
private String getAllWheelValues() {
String val1 = getWheelValue(R.id.passw_1);
String val2 = getWheelValue(R.id.passw_2);
String val3 = getWheelValue(R.id.passw_3);
return val1+" "+val2+" "+val3;
}
private String getWheelValue(int id) {
WheelView wheel = getWheel(id);
int index = wheel.getCurrentItem();
return ((ArrayWheelAdapter<String>) wheel.getViewAdapter()).getItemText(index).toString();
}