I am making this app, and in the design part, I Placed a Plain Text, the Id is TEXT1, and I want the String A to be equal to what ever the user place in the Plain Text(TEXT1), but it doesn't work...
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_fullscreen);
final Text TEXT1=(Text)findViewById(R.id.TEXT1);
final Button TRANSLATE=(Button)findViewById(R.id.TRANSLATE);
TRADUCIR.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String A;
A=(Text)findViewById(TEXT1); // ERROR IS IN HERE!
Toast.makeText(getApplicationContext(), A,Toast.LENGTH_LONG).show();
}
});
Instead of Text
, you probably meant to use TextView
.
And to get its contents, use getText()
, ie
String text = (TextView)findViewById(TEXT1).getText().toString();
You must replace Text by TextView and use this :
A = TEXT1.getText().toString();
instead of this :
A=(Text)findViewById(TEXT1);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.