1

#solved# When i build there is no error but upoun search for a specific text in edit text and hit the search button no changes are made i.e no highlights on my text.Please help.Below are my codes

// my java code
public void onClick(View v) {
                String textTOHighlight=etText.getText().toString();
  //delete this line  String replacedWith = "<span style='background-color:yellow'>"+textTOHighlight+"</span>";
                String originalText=textView.getText().toString();
// delete this line  String modifiedText=originalText.replaceAll(textTOHighlight,replacedWith);
                textView.setText(Html.fromHtml(modifiedText));
//added this and it works
String modifiedText=originalText.replaceAll(textTOHighlight, "<font color='red'>"+textTOHighlight+"</font>");
                textView.setText(Html.fromHtml(modifiedText));
// strings.xml
<string-array name="chapters">
<item>this is just an example for first item</item>
<item>this is the second example <item>
</string-array>
// activity
 <EditText
        android:layout_width="100dp"
        android:layout_height="wrap_content"
        android:id="@+id/et_text"
        android:hint="Enter text"
        android:padding="7dp"
        android:layout_marginTop="10dp"
        android:background="@drawable/bg_round"/>
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/search"
        android:text="Search"
        android:layout_marginTop="10dp"
        android:layout_marginStart="120dp"/>

    <TextView
        android:id="@+id/textv"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginTop="90dp"
        android:scrollbars="vertical"
        android:background="@drawable/bg_round"/>
newbie77
  • 35
  • 7

0 Answers0