p.karimdost p.karimdost - 1 year ago 159
Java Question

Set Text From EditText to TextView Using If-Else

I want that if I input a in edittext, text will display string a1 and if I input b in edittext, text will display string b1 and if I input ab, then textView display both string a1 and b1.

public class MainActivity extends Activity {
Button btn;
EditText et;
TextView tv;
protected void onCreate(Bundle savedInstanceState) {
btn =(Button)findViewById(R.id.button);
et =(EditText)findViewById(R.id.editText);
tv =(TextView)findViewById(R.id.textView);

btn.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
String name =et.getText().toString();
String a = "a";
String a1 = "\u00E1";
String b = "b";
String b1 = "\u00DF";

else if (name.equals(b)){


ddb ddb
Answer Source

you should use replaceAll function as below in the onClickListener instead of the if/else branch

name = name.replaceAll(a,a1);
name = name.replaceAll(b,b1);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download