I'm making a Madlibs app. I need to bold the information the user entered in the output story. However, I am not quite sure how to bold only those certain strings within the textview. It is worth noting my app replaces all "wx" in a story with each string. That is how the the story is created. If someone can help me replace the all "wx" in the story with a bold string instead of a regular one it would be appreciated. Thank you.
public void gather() {
ViewGroup layout = (ViewGroup) view.findViewById(R.id.anskey_clover);
View[] views = new View[layout.getChildCount()];
int[] ids = new int[layout.getChildCount()];
for (int i = 0; i < layout.getChildCount(); i++) {
ids[i] = layout.getChildAt(i).getId();
}
for (int i = 0; i < layout.getChildCount(); i++) {
BootstrapEditText au = (BootstrapEditText) view.findViewById(ids[i]);
stringbuffer.append(au.getText().toString() + "\n");
}
//setContentView(outLayout);
//TextView outview = (TextView) view.findViewById(outviewid);
//outview.setText(stringbuffer.toString());
}
public void postIt() {
String str = "let's go to the park";
String str2;
String newstr = null;
//setContentView(outLayout);
TextView outview = (TextView) view.findViewById(outviewid);
str = (String) outview.getText();
stringviews = stringbuffer.toString().split("\n"); // turns the
// stringbuffer from
// getAllXml() into
// an array and
// assigns to
// stringviews.
for (int i = 0; i < stringviews.length; i++) {
str2 = stringviews[i];
newstr = str.replaceFirst("wx", str2); // replaces all the "wx"s in
// the
// main_class_activity_out
// textview with values from
// strinvgviews.
str = newstr;
}
outview.setText(newstr);
ScrollView textScroll = (ScrollView) view.findViewById(R.id.scrollView1);
//textScroll.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
textScroll.getLayoutParams().width = LayoutParams.FILL_PARENT;
textScroll.getLayoutParams().height = LayoutParams.FILL_PARENT;
//textScroll.setPadding(0, 0, 0, 250);
stringbuffer.delete(0, stringbuffer.length());
}
0 comments:
Post a Comment