如何检查答案全部EDITTEXT(空或不),我把名单中 [英] how to check all editText (empty or not) for answer that I put in list

查看:171
本文介绍了如何检查答案全部EDITTEXT(空或不),我把名单中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要帮助来检查,我用它来回答我的问题,如果是空的或不是所有EDITTEXT。我把所有的答案列表。所以我可以把我所有的答案,当我点击问题的最后提交按钮。但我弄糊涂了如何检查所有的EditText我有。

所述的EditText将根据总的问题出现。
例子:我有5个问题,我展示的问题1页1个问题。当我点击下一步按钮,下一个页面将显示问题二号空白的EditText。它就是这样,直到问题被完成。我想是,当我点击发送/ OK,它会检查所有的EditText我真的需要帮助,请帮助我..谢谢

I need help to check all editText that I use to answer my question if is it empty or not. I put all the answer in list. so i can send all my answers when I click the submit button at the end of question. but I got confused how to check all edittext that I have.
the edittext will appear according the total of the questions.
example: i have 5 questions,and i show the question 1 page 1 question. when i click next button, the next page will show question number two with blank edittext. it is like that until the question is done. what i want is, when i click send/ok, it will check all edittext I really need help, please help me.. thank you

String[] answerCollection;
String[] questionCollection;
private int questionPos = 0;
private EditText jawaban;

final Button kirim = (Button) findViewById(R.id.kirim);
                kirim.setOnClickListener(new OnClickListener() {

                    public void onClick(View v) {
                        // TODO Auto-generated method stub
                        if(v == kirim){
                            AlertDialog.Builder builder = new Builder(TugasSoal.this);
                            builder.setMessage("Apakah Anda yakin akan mengirim jawaban Anda? Anda tidak dapat mengakses kembali tugas yang sudah dikirim");
                            builder.setTitle("Confirmation Dialog");

                            builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
                                public void onClick(DialogInterface dialog, int which) {
                                                        // do something after confirm

                                    String finalAnswer = "";
                                    answerCollection[questionPos] = jawaban.getText().toString();

                                    for(int i = 0;i <answerCollection.length;i++){
                                        finalAnswer += (i+1) + "." + answerCollection[i] + "\n\n"; 
                                    }

                                    ArrayList<NameValuePair> postParameters = new ArrayList<NameValuePair>();
                                    postParameters.add(new BasicNameValuePair("jawab", finalAnswer));


                                    String response = null;

                                    try {
                                        linkurl = new Koneksi(TugasSoal.this);
                                        SERVER_URL = linkurl.getUrl();
                                        SERVER_URL += "/mobile/tugasKirimTeks.php?idtgs="+param2+"&idu="+param3;
                                       response = CourseHttpClient.executeHttpPost(SERVER_URL, postParameters);

                                       String res = response.toString();

                                       res = res.trim();

                                       res = res.replaceAll("\\s+","");
                                       if(res.equals("1")){
                                           createDialog("Selamat", "Jawaban Anda Berhasil Dikirim");
                                           finish();
                                       }else
                                       {
                                           createDialog("Maaf", "Jawaban Anda Gagal Terkirim");
                                       }
                                    }

                                    catch (Exception e) {

                                       jawaban.setText(e.toString());

                                    }
                                }

                            }); 

                            builder.setNegativeButton("CANCEL", new DialogInterface.OnClickListener() {
                                public void onClick(DialogInterface dialog, int which) {
                                    dialog.cancel();
                                }
                            }); 

                            builder.create().show();    
                        }
                     }
                });

下一个和prevpart

next and prevpart

prev.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    answerCollection[questionPos] = jawaban.getText().toString();

                    if(questionPos > 0){
                        questionPos -=1;
                        RefreshQuestionandAnswer();
//                      next.setEnabled(true);
//                      if(questionPos == 0)
//                          back.setEnabled(false);
                    }
                }
            });

            next.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    answerCollection[questionPos] = jawaban.getText().toString();

                    if(questionPos < questionCollection.length - 1) {
                        questionPos +=1;
                        RefreshQuestionandAnswer();
//                      prev.setEnabled(true);
//                      if(questionPos == questionCollection.length - 1)
//                          next.setEnabled(false);
                    }
                }
            });

显示部分问题

linkurl = new Koneksi(this);
            SERVER_URL = linkurl.getUrl();
            SERVER_URL += "/mobile/TugasSoal.php?idc="+param1+"&ida="+param2+"&idu="+param3;

            HttpClient httpClient = new DefaultHttpClient();
            HttpPost httpPost = new HttpPost(SERVER_URL);

            //parameter
            ArrayList<NameValuePair> param = new ArrayList<NameValuePair>();{
            try {
               //add parameter
                httpPost.setEntity(new UrlEncodedFormEntity(param));

              HttpResponse httpRespose = httpClient.execute(httpPost);
              HttpEntity httpEntity = httpRespose.getEntity();

              //read content
              InputStream in = httpEntity.getContent();
              BufferedReader read = new BufferedReader(new InputStreamReader(in));

              String content = "";
              String line = "";

              while((line = read.readLine())!=null){
                 content += line;
              }

              Log.d("ADBUG", "content: "+content);


              //json
              if(!content.equals("null")){

                 try {
                    JSONArray jArr = new JSONArray(content);
                    String namaTugas="";
                    String detailTugas="";

                    JSONObject jsonObj = jArr.getJSONObject(0);
                    namaTugas = jsonObj.getString("name");
                    detailTugas = jsonObj.getString("description");

                    questionCollection = detailTugas.split("\n");
                    answerCollection = new String[questionCollection.length];
                    judulTugas.setText(namaTugas);

                    RefreshQuestionandAnswer();

                 } catch (JSONException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                 }

              }else{
                 Toast.makeText(this, "Error", Toast.LENGTH_LONG).show();
              }

           } catch (ClientProtocolException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
           } catch (IOException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
           }

            }

        }

        private void RefreshQuestionandAnswer()
        {
            jawaban.setText(answerCollection[questionPos]);
            isiTugas.setText(questionCollection[questionPos]);
        }

当我第一次打开菜单为回答这个问题

when I first open the menu for answer the question

在我点击下一步按钮

推荐答案

有关部分previous问题显示答案:结果
我会做一个ArrayList是这样的:

For the "Show answer of previous question" part:
I would make an ArrayList something like:

    List answerList = new ArrayList(); 


    next.setOnClickListener(new OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        answerCollection[questionPos] = jawaban.getText().toString();

                        if(questionPos < questionCollection.length - 1) {
                            if (answerCollection.get(questionPos).toString().equals("")){
                                answerList.add(questionPos, "0");//You check if the user has enetered an answer, if yes, it put a 1 into the array, if not, a 0
                            } else {
                                answerList.add(questionPos, "1");
                            }
                            questionPos +=1;
                            RefreshQuestionandAnswer();
    //                      prev.setEnabled(true);
    //                      if(questionPos == questionCollection.length - 1)
    //                      next.setEnabled(false);
                        }
                    }
                });

然后在发送按钮,检查零的ArrayList中。

Then at the send button, check the Arraylist on zero's.

for (int i = 0; i < answerList.size(); i++){
    if (answerList.get(i).toString().equals("0")){
        //no answer is given to question number i      
    }
}

像这样

这篇关于如何检查答案全部EDITTEXT(空或不),我把名单中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆