Android studio html view in ArrayList - java

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

Related

True answer button green [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I make a quizz app.
When the user click the right answer, I want the button to turn green.
But I don't know how.
private TextView countLabel;
private ImageView questionImage;
private Button answerBtn1;
private Button answerBtn2;
private Button answerBtn3;
private Button answerBtn4;
private TextView textView;
private String rightAnswer;
private int rightAnswerCount = 0;
private int quizCount = 1;
ArrayList<ArrayList<String>> quizArray = new ArrayList<>();
String quizData[][] = {
// {"Image Name", "Right Answer", "Choice1", "Choice2", "Choice3"}
{"Aşağıdaki tümcelerle bir paragraf oluşturulduğunda, hangisi son tümce olur ?", "Önce hoşa gidiyor,sonra üşütüyordu insanı.", "Pencereyi ardına kadar açtım.", "Pencereyi ardına kadar açtım.", "Odanın içine gecenin serinliği doldu."},
{"Ben insanın iş görme isteğini ve yaşama çabasını daima canlı tutmasını isterim.Ölüm,bahçeme fidanlarını dikerken bulmalı beni;ama ölüm korkusu,bahçemi yitirme korkusu içinde değil Diyen biri için aşağıdakilerden hangisi söylenemez ?", "Telaşlı olduğu", "Hayatı sevdiği", "Umutlu olduğu", "Çalışkan olduğu"},
{"Bu ayrımın dışında iki toplum birbirini kabullenmiş hatta kaynaşmış olarak yaşıyorlardı. Öylesine ki Feride? nin çocukluğunda bir Rum delikanlısı, dul bir kadının tek oğlu, bir kaza sonucu öldüğünde, bu acıklı olaya türkü yakanlar Türkler olmuşlardır. Yukarıdaki paragrafın konusu aşağıdaki seçeneklerin hangisindedir ?", "İki toplumun kaynaşması", "Rum delikanlısı", "Feride'nin çocukluğu", "Dul bir kadının yası"},
{"Aşağıdaki cümlelerin hangisinde büyük harf yanlış kullanılmıştır ?", "İleride Matematik Öğretmeni olmak istiyor.", "Yazları İzmire gidiyor.", "Üç yıldır Şirinevlerde oturuyor.", "Salim 24 Şubatta doğmuş."},
{"Aşağıdaki kelimelerin hangisinin yazımı doğrudur ?", "pek az", "hiçkimse", "bir az", "herşey"},
};
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
countLabel = findViewById(R.id.countLabel);
questionImage = findViewById(R.id.questionImage);
answerBtn1 = findViewById(R.id.answerBtn1);
answerBtn2 = findViewById(R.id.answerBtn2);
answerBtn3 = findViewById(R.id.answerBtn3);
answerBtn4 = findViewById(R.id.answerBtn4);
textView = findViewById(R.id.textView);
// Create quizArray from quizData.
for (int i = 0; i < quizData.length; i++) {
// Prepare array.
ArrayList<String> tmpArray = new ArrayList<>();
tmpArray.add(quizData[i][0]); // Image Name
tmpArray.add(quizData[i][1]); // Right Answer
tmpArray.add(quizData[i][2]); // Choice1
tmpArray.add(quizData[i][3]); // Choice2
tmpArray.add(quizData[i][4]); // Choice3
// Add tmpArray to quizArray.
quizArray.add(tmpArray);
}
showNextQuiz();
}
public void showNextQuiz() {
// Update quizCountLabel.
countLabel.setText("Soru:" + quizCount);
// Generate random number between 0 and 4 (quizArray's size -1)
Random random = new Random();
int randomNum = random.nextInt(quizArray.size());
// Pick one quiz set.
ArrayList<String> quiz = quizArray.get(randomNum);
// Set Image and Right Answer.
// Array format: {"Image Name", "Right Answer", "Choice1", "Choice2", "Choice3"}
textView.setText(quiz.get(0));
rightAnswer = quiz.get(1);
// Remove "Image Name" from quiz and shuffle choices.
quiz.remove(0);
Collections.shuffle(quiz);
// Set choices.
answerBtn1.setText(quiz.get(0));
answerBtn2.setText(quiz.get(1));
answerBtn3.setText(quiz.get(2));
answerBtn4.setText(quiz.get(3));
// Remove this quiz from quizArray.
quizArray.remove(randomNum);
}
public void checkAnswer(View view) {
// Get pushed button.
Button answerBtn = findViewById(view.getId());
String btnText = answerBtn.getText().toString();
String alertTitle;
if (btnText.equals(rightAnswer)) {
// Correct!!
alertTitle = "Doğru!";
rightAnswerCount++;
} else {
// Wrong
alertTitle = "Yanlış...";
}
// Create Dialog.
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(alertTitle);
builder.setMessage("Cevap : " + rightAnswer);
builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialogInterface, int i) {
if (quizArray.size() < 1) {
// quizArray is empty.
showResult();
} else {
quizCount++;
showNextQuiz();
}
}
});
builder.setCancelable(false);
builder.show();
}
public void showResult() {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Sonuç");
builder.setMessage(rightAnswerCount + " / 5");
builder.setPositiveButton("Tekrar Dene", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialogInterface, int i) {
recreate();
}
});
builder.setNegativeButton("Çıkış", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialogInterface, int i) {
finish();
}
});
builder.show();
}
}
You can use this :
If(rightAnswer){
// If you're in an activity:
answerBtn1.setBackgroundColor(getResources().getColor(R.color.green));
// OR, if you're not:
answerBtn1.setBackgroundColor(Button11.getContext().getResources().getColor(R.color.green));
}
Or, alternatively:
if(rightAnswer){
answerBtn1.setBackgroundColor(Color.GREEN); // From android.graphics.Color
}

make a simple quiz with image as the questions and the answers

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]));

Set timer in android quiz application

I'm a beginner in android application. I want to make android quiz application with a timer. Every question has a timer and resets in every next question. How can I input countdown timer with my java activity?
Here's my code:
public class QuizHistoryActivity extends AppCompatActivity {
private TextView countLabel;
private TextView questionLabel;
private Button answerBtn1, answerBtn2, answerBtn3;
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 [][] = {
{"Question random", "correctanswer",
"choice a", "choice b", "choice c"},
{"Question random", "correct answer",
"choice a,""choice b","choice c"},
};
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_quiz_history);
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);
//Create quizArray from quizdata
for (int i = 0; i < quizData.length; i++) {
//Prepare array
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]);
//Add tmpArray to quizArray
quizArray.add(tmpArray);
}
showNextQuiz();
}
public void showNextQuiz () {
//Update quizCountLabel
countLabel.setText("Question #" + quizCount);
//Generate random number between 0 and 14 (Quiz Array's size -1)
Random random = new Random();
int randomNum = random.nextInt(quizArray.size());
//Pick ine quiz set
ArrayList<String> quiz = quizArray.get(randomNum);
//Set question and right answer
//array format
questionLabel.setText(quiz.get(0));
rightAnswer = quiz.get(1);
//remove "country" from quiz and shuffle choice
quiz.remove(0);
Collections.shuffle(quiz);
//Set Choices
answerBtn1.setText(quiz.get(0));
answerBtn2.setText(quiz.get(1));
answerBtn3.setText(quiz.get(2));
//Remove this quiz from quizArray
quizArray.remove(randomNum);
}
public void checkAnswer (View view) {
//Get pushed button
Button answerBtn = (Button)findViewById(view.getId());
String btnText = answerBtn.getText().toString();
String alertTitle;
if(btnText.equals(rightAnswer)) {
//Correct!
alertTitle = "Correct!";
rightAnswerCount++;
}else {
//Wrong
alertTitle = "Wrong";
}
//create Dialog
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(alertTitle);
builder.setMessage("Answer : \n \t \t" + rightAnswer);
builder.setPositiveButton("Got It!", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialogInterface, int i) {
if (quizCount == QUIZ_COUNT) {
//Show Result
Intent resultintent = new Intent(getApplicationContext(), ResultQuizHistoryActivity.class);
resultintent.putExtra("RIGHT_ANSWER_COUNT", rightAnswerCount);
startActivity(resultintent);
}else {
quizCount++;
showNextQuiz();
}
}
});
builder.setCancelable(false);
builder.show();
}
}
You can use a Chronometer from the Android framework to show the time in the UI, and:
long start = System.currentTimeMillis();
At the beginning of the quiz, and at the end
long end = System.currentTimeMillis();
long timeTranscurredInMillis = end - start;
...to get the time that the quiz lasted.
here is it
CountDownTimer countDown;
countDown= new CountDownTimer(30000, 1000) {
public void onTick(long millisUntilFinished) {
mTextField.setText("seconds remaining: " + millisUntilFinished / 1000);
}
public void onFinish() {
//call nextQuestionMethod here
}
};
countDown.start();
A 30 Sec timer with 1 sec tick , you can change these values according to your choice. Refer to this link for more details.

How to display multiple EditText inputs after pressing Button in one TextView?

I'm in the beginning of my learning how to make apps. I want to make an app which should display randomized inputted tasks to do for the user. Firstly user should choose how many tasks would like to create and then write down tasks in EditText. I am able to create particular amount of EditText but I have no clue how to display all EditText input after pressing button. I have many versions of the code but non of them work. I got stuck and I need advice.
Here is one of my code version for the second activity.
public class TaskActivity extends AppCompatActivity {
LinearLayout containerLayout;
TextView receiverTV;
TextView tv;
TextView displayTaskTv;
EditText et;
Button btn;
Button randomTaskBtn;
int i = 0;
int size;
String inputEditText;
String inputTextView;
String stringsEt[];
String stringsTv [];
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_task);
containerLayout = (LinearLayout) findViewById(R.id.linear_layout);
receiverTV = (TextView) findViewById(R.id.receiver_textView);
Intent intent = getIntent();
int number = intent.getIntExtra("Number", defaultValue);
receiverTV.setText("You have chosen to add: " + number + " tasks!");
createEtTvBtn(number);
createBtn();
createTextView();
}
public void createEtTvBtn(int number) {
for (i = 1; i <= number; i++) {
tv = new TextView(this);
tv.setText("Task nr: " + i);
tv.setPadding(16, 16, 16, 16);
tv.setTextColor(Color.parseColor("#008b50"));
tv.setTextSize(20);
tv.setId(i + value);
containerLayout.addView(tv);
et = new EditText(this);
et.setHint("Enter task nr: " + i);
et.setId(i + value);
et.setLines(2);
containerLayout.addView(et);
btn = new Button(this);
btn.setText("Confirm task nr: " + i);
btn.setId(i + value);
containerLayout.addView(btn);
final List<EditText> allEditText = new ArrayList<EditText>();
final List<TextView>allTextView = new ArrayList<TextView>();
final List<Button>allButton = new ArrayList<Button>();
String[] stringsEditText = new String[(allEditText.size())];
String[] stringsTextView = new String[(allTextView.size())];
String[] stringsBtn = new String[(allButton.size())];
for(int i=0; i < allEditText.size(); i++){
stringsEditText[i] = allEditText.get(i).getText().toString();
}
for (int i=0; i < allTextView.size(); i++) {
stringsTextView[i] = allTextView.get(i).getText().toString();
size = allTextView.get(i).getText().toString().length();
}
for(int i=0; i < allButton.size(); i++){
stringsBtn[i] = allButton.get(i).getText().toString();
}
allTextView.add(tv);
allEditText.add(et);
allButton.add(btn);
allButton.get(0).setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
inputEditText = allEditText.get(0).getText().toString();
stringsEt = new String[] {allEditText.get(0).getText().toString()};
if (inputEditText.length() > 0) {
allTextView.get(0).setText(inputEditText);
allEditText.add(allEditText.get(0));
allEditText.get(0).setText("");
}
else if (inputEditText.length() ==0){
Toast.makeText(TaskActivity.this, "You need to write down your task", Toast.LENGTH_LONG).show();
}
inputTextView = allTextView.get(0).getText().toString();
stringsTv = new String[] {allTextView.get(0).getText().toString()};
if (inputTextView.length() > 0) {
allTextView.get(0).getText();
allTextView.add(allTextView.get(0));
}
}
});
}
}
private Button createBtn() {
randomTaskBtn = new Button(this);
randomTaskBtn.setText("Task");
containerLayout.addView(randomTaskBtn);
randomTaskBtn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
double luckyTask = Math.random();
luckyTask *=size;
int luckyIndex = (int)luckyTask;
displayTaskTv.setText(stringsTv[luckyIndex]);
}
});
return randomTaskBtn;
}
private TextView createTextView() {
displayTaskTv = new TextView(this);
displayTaskTv.setTextSize(20);
displayTaskTv.setTextColor(Color.parseColor("#dd2626"));
displayTaskTv.setText("");
containerLayout.addView(displayTaskTv);
return displayTaskTv;
}
}
Thank you for any constructive advices.
I am sure my code is big mess. I wanted to created more methods but I didn't succeed.
This is what you should do
Step 1 -
Create multiple EditTexts and store each one of them in an ArrayList say myEditTextList.
Step 2- Take data from all edit texts
String str = ""
for(EditText et: myEditTextList) {
str += et.getText().toString();
}
Step 3- Display data in str wherever you want.

Android Share Button

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();
}

Categories

Resources