Reverse text means opposite written of textview for example “12345” this is a textview and if i write this in reverse than textview look like this “54321” also apply in alphabetical text like “sam” in reverse “mas”.

Layout

First of all i create a edittext, textview and button layout to explain clearly.

Layout code

<LinearLayout
xmlns:android=”http://schemas.android.com/apk/res/android
xmlns:app=”http://schemas.android.com/apk/res-auto
xmlns:tools=”http://schemas.android.com/tools
android:layout_width=”match_parent”
android:layout_height=”match_parent”
android:orientation=”vertical”>
<EditText
android:id=”@+id/edittext1″
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:padding=”8dp”
android:textSize=”12sp”
android:textColor=”#000000
android:hint=”Edit Text”
android:textColorHint=”#607D8B”
android:layout_gravity=”center_horizontal|center_vertical”/>
<Button
android:id=”@+id/button1″
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:padding=”8dp”
android:text=”Button”
android:textSize=”12sp”
android:textColor=”#000000
android:layout_gravity=”center_horizontal|center_vertical”/>
<TextView
android:id=”@+id/textview1″
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:padding=”8dp”
android:text=”TextView”
android:textSize=”12sp”
android:textColor=”#000000
android:layout_gravity=”center_horizontal|center_vertical”/>
</LinearLayout>

Button onclick

in button onclick logic se the code to get text from textview and display on textview in reverse form.

Button onclick code

button1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View _view) {
Rvrs = “”;
num = edittext1.getText().toString().length();
for(int _repeat14 = 0; _repeat14 < (int)(edittext1.getText().toString().length()); _repeat14++) {
Rvrs = Rvrs.concat(edittext1.getText().toString().substring((int)(num – 1), (int)(num)));
num–;
}
textview1.setText(Rvrs);
}
});

In this logic add set variable block and value is empty. for input value add set number value get from EditText.

After that add reapet control block. in the reapet control block set reverse value to (edittext1.getText().toString().substring((int)(num – 1), (int)(num)));

Than decrease 1 of value. Set text value in textview.

Sketchcode block