Android Form Reset?

后端 未结 3 1392
半阙折子戏
半阙折子戏 2021-01-26 22:16

I have a simple calculator that has six EditText views where users will enter numbers to perform a simple math function. This app will satisfy a repetitive task wherein the user

3条回答
  •  执笔经年
    2021-01-26 22:41

    My answer is just a better way but it still a kind of hard code. Anyone could find another way faster, please share.

    protected void clearForm() {
        Button btnClear = (Button) findViewById(R.id.btn_clear_text);
        btnClear.setOnClickListener(new View.OnClickListener() {            
            @Override
            public void onClick(View v) {
    
                EditText temp;      
                final int[] txtId = new int[] {
                    R.id.txt_s_free_word,
                    R.id.txt_s_property_name,
                    R.id.txt_s_ad_expense_from,
                    R.id.txt_s_ad_expense_to,
                    R.id.txt_s_station
                };
    
                for (int i = 0; i < txtId.length; i++) {
                    temp = (EditText) findViewById(txtId[i]);
                    temp.setText(null);
                }
            }
        });
    }
    

提交回复
热议问题