用逗号分隔所有非空值的EditText。

huangapple go评论71阅读模式
英文:

Separate all EditText with non Empty value by a comma

问题

I'm a beginner in java and sql and I want to sort some information of my table.
我是Java和SQL的初学者,我想对我的表格中的一些信息进行排序。

I have connected the database to my java project.
我已经将数据库连接到我的Java项目中。

I want to take all the values of EditText in one column of my table.
我想获取表格中一个列中EditText的所有值。

I want to take all non-empty values and separate them by a comma ",".
我想获取所有非空值并用逗号“,”分隔它们。

The problem is that it takes all the values of the EditText even when they are empty.
问题是它获取EditText的所有值,即使它们为空也是如此。

I'm looking for this kind of result in my table :
我希望在我的表格中得到这种结果:

Column : Manque
列:Manque

Row : Example Value 1, Example Value 3, Example Value 7
行:示例值1,示例值3,示例值7

But actually I have this,
但实际上我有以下结果,

Column : Manque
列:Manque

Row : Example Value 1, , Example Value 3, , , , Example Value 7
行:示例值1,,示例值3,,,,示例值7

private Controle3 controle3;

private void init() {
    // 初始化代码部分
}

private void ecouteValidation() {
    // 点击验证按钮的代码部分
}

/**
 * Affichage du message
 *
 */
private void afficheResult(String immatriculation, String name, String manque) {
    // 显示结果的代码部分
}

以上是翻译的部分,不包括代码。

英文:

I'm a beginner in java and sql and I want to sort some information of my table.
I have connected the database to my java project. I want to take all the values of EditText in one column of my table. I want to take all non Empty values and separate them by a comma " ,". The problem is that it takes all the values of the EditText even when they are empty.

I'm looking for this kind of result in my table :

Column : Manque

Row : Example Value 1, Example Value 3, Example Value 7

But actually I have this,

Column : Manque

Row : Example Value 1, , Example Value 3, , , , Example Value 7

'''

private Controle3 controle3;

private  void init() {
    nb1 = (EditText) findViewById(R.id.nb1);
    nb2 = (EditText) findViewById(R.id.nb2);
    nb3 = (EditText) findViewById(R.id.nb3);
    nb4 = (EditText) findViewById(R.id.nb4);
    nb5 = (EditText) findViewById(R.id.nb5);
    nb6 = (EditText) findViewById(R.id.nb6);
    nb7 = (EditText) findViewById(R.id.nb7);
    nb8 = (EditText) findViewById(R.id.nb8);
    nb9 = (EditText) findViewById(R.id.nb9);
    nb10 = (EditText) findViewById(R.id.nb10);
    nb11 = (EditText) findViewById(R.id.nb11);
    nb12 = (EditText) findViewById(R.id.nb12);
    nb13 = (EditText) findViewById(R.id.nb13);
    nb14 = (EditText) findViewById(R.id.nb14);
    nb15 = (EditText) findViewById(R.id.nb15);
    nb16 = (EditText) findViewById(R.id.nb16);
    nb17 = (EditText) findViewById(R.id.nb17);
    nb18 = (EditText) findViewById(R.id.nb18);
    nb19 = (EditText) findViewById(R.id.nb19);
    nb20 = (EditText) findViewById(R.id.nb20);
    nb21 = (EditText) findViewById(R.id.nb21);
    nb22 = (EditText) findViewById(R.id.nb22);
    nb23 = (EditText) findViewById(R.id.nb23);
    nb24 = (EditText) findViewById(R.id.nb24);



    ecouteValidation();
    this.controle3 = Controle3.getInstance(this);
    recupProfil();


}





private void ecouteValidation(){
    ((Button) findViewById(R.id.btnValid)).setOnClickListener(new Button.OnClickListener() {

        public void onClick(View v) {
            // Toast.makeText(FirstActivity.this, "test", Toast.LENGTH_SHORT).show();
            //Log.d("message", "clic ok sur le bouton Valid ******************");
            String immatriculation = null;
            String name = null;
            String manque = null;

                        try {
                            immatriculation = txtImmat.getText().toString();
                            name = txtname.getText().toString();




                        } catch (Exception e) {};

            if(nb1.getText().toString().isEmpty() && nb2.getText().toString().isEmpty() && nb3.getText().toString().isEmpty() && nb4.getText().toString().isEmpty() && nb5.getText().toString().isEmpty() && nb6.getText().toString().isEmpty() && nb7.getText().toString().isEmpty() && nb8.getText().toString().isEmpty() && nb9.getText().toString().isEmpty() && nb10.getText().toString().isEmpty() && nb11.getText().toString().isEmpty() && nb12.getText().toString().isEmpty() && nb13.getText().toString().isEmpty() && nb14.getText().toString().isEmpty() && nb15.getText().toString().isEmpty() && nb16.getText().toString().isEmpty() && nb17.getText().toString().isEmpty() && nb18.getText().toString().isEmpty() && nb19.getText().toString().isEmpty() && nb20.getText().toString().isEmpty() && nb21.getText().toString().isEmpty() && nb22.getText().toString().isEmpty() && nb23.getText().toString().isEmpty() && nb24.getText().toString().isEmpty()){
                manque =  "COMPLET";
            }else {

                for(nb1.getText().toString().isEmpty()){


                    manque = nb1.getText().toString() + nb2.getText().toString() + " " + nb3.getText().toString() + " " + nb4.getText().toString() + " " + nb5.getText().toString() + " " + nb6.getText().toString() + " " + nb7.getText().toString() + " " + nb8.getText().toString() + " " + nb9.getText().toString() + " " + nb10.getText().toString() + " " + nb11.getText().toString() + " " + nb12.getText().toString() + " " + nb13.getText().toString() + " " + nb14.getText().toString() + " " + nb15.getText().toString() + " " + nb16.getText().toString() + " " + nb17.getText().toString() + " " + nb18.getText().toString() + " " + nb19.getText().toString() + " " + nb20.getText().toString() + " " + nb21.getText().toString() + " " + nb22.getText().toString() + " " + nb23.getText().toString() + " " + nb24.getText().toString();
                }
            }






                        if (name.isEmpty() || immatriculation.isEmpty()) {
                            Toast.makeText(MaterielVSLActivity.this, "Saisie incorrecte", Toast.LENGTH_SHORT).show();
                        } else {
                            afficheResult(immatriculation, name, manque);
                            Toast.makeText(MaterielVSLActivity.this, "OK", Toast.LENGTH_SHORT).show();
                        }
                    }
                });

            }

            /**
             * Affichage du message
             *
             */
            private void afficheResult(String immatriculation, String name, String manque){
                this.controle3.creerProfil(immatriculation, name, manque, this);
            }

}'''

答案1

得分: 0

你可以将所有的EditText添加到一个数组中:

EditText[] editTexts = {nb1, nb2, nb3...};
String content;

然后循环遍历数组,检查项目内容是否不为空,如果不为空,则将其添加到content中:

for (EditText myEditText : editTexts) {
    if (!myEditText.getText().toString().isEmpty()) {
        content += myEditText.getText().toString() + ",";
    }
}
英文:

You can add all your EditTexts to an array

EditText[] editTexts ={nb1,nb2,nb3...};
String content;

and loop the array check if the item content is not empty add it to the content

for(EditText myEditText : editTexts){
    if(!myEditText.getText().toString().isEmpty()){
        content += myEditText.getText().toString() + ","
    }
}

huangapple
  • 本文由 发表于 2020年7月29日 19:14:41
  • 转载请务必保留本文链接:https://go.coder-hub.com/63152335.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定