I have enabled a button as well as a textField on Android studio.
The button returns the value on logs but somehow the code i've written for the textField returns an error.
Code as follows:
public class MainActivity extends AppCompatActivity {
public void button (View view){
EditText textView = (EditText) findViewById(R.id.textView);// this line is an error.
Log.i("i","info");
}
It is because you are trying to cast TextView
into EditText
which is not possible
If you want to take input from the user then EditText
is your choice
If you want to show some text then TextView
should fit your requirements
Solution
TextView textView = (TextView) findViewById(R.id.textView);
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.