我需要帮助来检查我用来回答我的问题的所有 editText 是否为空。我把所有的答案都列在列表中。因此,当我单击问题末尾的提交按钮时,我可以发送所有答案。但我很困惑如何检查我拥有的所有编辑文本。
编辑文本将根据问题的总数出现。
示例:我有 5 个问题,我显示问题 1 页 1 问题。当我单击下一步按钮时,下一页将显示第二个问题,其中包含空白编辑文本。问题完成之前就是这样。我想要的是,当我单击发送/确定时,它将检查所有编辑文本我真的需要帮助,请帮助我.. 谢谢
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();
}
}
});
下一个和上一个部分
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]);
}
当我第一次打开菜单回答问题时
在我点击下一步按钮后