I'm trying to develop an app that consists of multiple arrays and textviews and I've run into a problem.
I have 3 textviews and 2 arrays.
One of my arrays contains sentences. My first question is how can I highlight specific words in each sentence? Ex: "This is my first array item" I need to highlight a word in the string so that when it is displayed in textview1, it will appear like this... "This is my first array item"
My other array contains words. They are displayed in textview2 and should also be highlighted. My next question is how can I replace the current highlighted word in textview1 with the new highlighted word from textview2, and also have a 3rd textview displaying the new sentence? Ex: If the chosen item from my sentence array is "This is a test" (displayed in textview1) And the item from my word array is "website" (displayed in textview2) the result would be "This is a website" (displayed in textview3)
Here is my code so far
import java.util.Random;
import android.app.Activity;
import android.content.res.Resources;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;
import android.widget.Button;
public class Class1 extends Activity implements OnClickListener
{
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_class1);
Button btn_sentence = (Button) findViewById(R.id.btn_sentence );
Button btn_word = (Button) findViewById(R.id.btn_word );
Button btn_newsentence = (Button) findViewById(R.id.btn_newsentence );
final Random ran = new Random();
final Resources res = getResources();
final TextView text1 = (TextView) findViewById(R.id.sentencetext);
final TextView text2 = (TextView) findViewById(R.id.wordtext);
final TextView text3 = (TextView) findViewById(R.id.newsentencetext);
btn_sentence.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
String[] NewText = null;
NewText = res.getStringArray(R.array.sentences);
String strRandom = NewText[ran.nextInt(NewText.length)];
text1.setText(strRandom);
}
});
btn_word.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
String[] NewText2 = null;
NewText2 = res.getStringArray(R.array.words);
String strRandom2 = NewText2[ran.nextInt(NewText2.length)];
text2.setText(strRandom2);
}
});
btn_newsentence.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
**text3.setText(" " + (text1.getText()) + " " + (text2.getText()) + " ");**
}
});
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
}}
The bold text is as close as I've gotten, but all that really does is combine both TexttView1 and textview2, and display it in textview3... which isn't exactly what I want.
Help would be much appreciated ~TylerNormal