我想当我在EditText中写5然后我点击按钮我希望TextView更改为5,然后如果我写6并再次单击按钮我希望TextView更改为11 ...
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="how much do you want to add ?"
android:id="@+id/editText" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="0"
android:textSize="50sp"
android:layout_centerHorizontal="true"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true"
android:layout_marginTop="86dp"
android:id="@+id/TextView" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/add"
android:onClick="add"
android:layout_below="@id/editText"
android:hint="add"/>
答案 0 :(得分:0)
您可以查看以下代码段。确保添加条件/检查输入始终为数字:
yourbtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(yourtxtview.getText().toString().trim().length()>0 ){
if(youredtText.getText().toString().trim().length()>0){
yourtxtview.setText(String.valueOf(Integer.valueOf(yourtxtview.getText().toString())
+Integer.valueOf(youredtText.getText().toString())));
}else{
yourtxtview.setText(String.valueOf(Integer.valueOf(yourtxtview.getText().toString())+
0));
}
}else if(youredtText.getText().toString().trim().length()>0){
yourtxtview.setText(String.valueOf(Integer.valueOf(youredtText.getText().toString())+
0));
}
}
});
答案 1 :(得分:0)
class SearchPresenter<T>(val network: Network) : BasePresenter<SearchView<T>>()