我有一個文本框(EditText),我將在其中插入文本,以及一個應該計算該文本的長度并將其顯示在另一個文本框中的按鈕。我應該如何編碼那個按鈕?
uj5u.com熱心網友回復:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button b1=findViewById(R.id.b1);
Button b2=findViewById(R.id.b2);
EditText t1=findViewById(R.id.t1);
TextView t2;
t2 = findViewById(R.id.t2);
b1.setOnClickListener(view -> {
int nb=0;
for(int i=0; i<t1.length(); i){
nb ;
}
t2.setText(Integer.toString(nb));
});
b2.setOnClickListener(view -> {
t2.setText(t1.getText().toString());
});
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/422501.html
標籤:
上一篇:更改默認按鈕樣式
