How can I make it so that it uses whatever is in the edittext, as the text view like if I type “hello” push the button and it sets the textview as “hello” then when you push the button again it erases it?
package com.purelymean.earnings;
import org.w3c.dom.Text;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
public class Main extends Activity{
/**Called when activity is first created. */
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button b = (Button) findViewById(R.id.button);
Text et = (Text) findViewById(R.id.editText1);
TextView tx = (TextView) findViewById(R.id.textView1);
b.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
}
});
}
}
Another way to do it (adding on to La bla bla): For displaying the editText in TextView first create a method that happens when the button is clicked:
In your xml for your button add this:
To get the EditText value put this inside the displayEditText
String editTextValue = et.getText().toString;To display this do the following:
Final solution: