有时单击按钮后,文本消失,有时我必须单击两次才能起作用

时间:2018-08-24 02:01:04

标签: android button

我不知道此按钮有什​​么问题。单击该按钮后,该文本将消失,并且在我单击两次后它开始起作用。所有按钮都相同,并且单击一次后,文本消失了...我需要重新执行项目吗?

Image

这是按钮Onclick。

switch

我为“ SetOnclick”打开了一个方法

@Override
    public void onClick(View v) {
        Save.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                boolean isInserted = myDb.insertData(e_Txn.getText().toString(),
                        e_Name.getText().toString(),
                        e_Amount.getText().toString(),
                        Display_date.getText().toString().trim(),
                        e_Description.getText().toString(),
                        Description.getSelectedItem().toString());

                if (isInserted == true) {
                    Toast.makeText(Donation.this, "Data Inserted", Toast.LENGTH_LONG).show();
                } else {
                    Toast.makeText(Donation.this, "Data not Inserted", Toast.LENGTH_LONG).show();
                }


            }
        });
        New.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                e_Name.getText().clear();
                e_Amount.getText().clear();
                e_Txn.getText().clear();
                e_Description.getText().clear();
            }
        });
    }

3 个答案:

答案 0 :(得分:1)

我不知道根本原因,但我认为您的代码使用了错误的方法,请不要在var data = [{ "name": "bob", "num": 16 }, { "name": "mary", "num": 45 }, { "name": "tyler", "num": 3 }, { "name": "rebecca", "num": 70 }, { "name": "michelle", "num": 81 } ]; console.log(data.sort((a, b) => a.num - b.num).map(e => e.name));方法中b.num - a.num

让它变得简单

setOnClickListener

答案 1 :(得分:1)

您应按如下方式编写onclick方法

@Override
public void onClick(View v) {

    switch (v.getId()) {

        case R.id.Save://relpace Save with the button id
            boolean isInserted = myDb.insertData(e_Txn.getText().toString(),
                    e_Name.getText().toString(),
                    e_Amount.getText().toString(),
                    Display_date.getText().toString().trim(),
                    e_Description.getText().toString(),
                    Description.getSelectedItem().toString());

            if (isInserted == true) {
                Toast.makeText(Donation.this, "Data Inserted", Toast.LENGTH_LONG).show();
            } else {
                Toast.makeText(Donation.this, "Data not Inserted", Toast.LENGTH_LONG).show();
            }

            break;

        case R.id.New://relpace New with the button id
            e_Name.getText().clear();
            e_Amount.getText().clear();
            e_Txn.getText().clear();
            e_Description.getText().clear();
            break;


        default:
            break;
    }

}

答案 2 :(得分:0)

根据我的阅读,您正在list(chain.from_iterable(G.get(x, [0]) for x in indexes)) #[1.0, 7.0, 4.0, 5.0, 0, 3.0, 2.0, 6.0] 方法中再次设置点击监听器,当您在onClick()中设置点击监听器的四个按钮之一被点击时,该方法就会被调用。 例如,您必须在“新建”按钮上单击两次才能执行所需的操作。

要解决此问题,我建议您执行以下操作:

setOnClick()

其他方法应该相同。

我认为,文本消失的原因与您在此处发布的代码无关。也许是由于样式或布局等其他部分引起的。