try
{
//got input from asset that's not a problem
JSONObject obj = new JSONObject(loadJSONFromAsset());
JSONArray m_jArry1 = obj.getJSONArray("check");
int j=0,i,k=0;
while(j<m_jArry1.length()) {
JSONObject jsonObject = m_jArry1.getJSONObject(j);
JSONArray m_jArry = jsonObject.getJSONArray("formules");
ArrayList<Integer> list = new ArrayList<Integer>(m_jArry.length());
for (i = 0; i < m_jArry.length(); i++) {
list.add(i);
}
Collections.shuffle(list);
//shuffled the list for random generation of questions and answer
// so that's not a problem too.
for (i = 0; i < 6; i++) {
JSONObject jo_inside = m_jArry.getJSONObject(list.get(i));
formula_value = jo_inside.getString("ques");
url_value = jo_inside.getString("ans");
/*I want to read question and answer from formula_value &
url_value each time and wait for 6 seconds until the next set arrives...
So I used Handler to make it wait for 6 seconds which isn't working ..
but it's going to the last value directly .*/
handler = new Handler();
handler.postDelayed(new Runnable(){
@Override
public void run() {
textView.setText(formula_value);
editText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
//using this so that there is an action only when done is pressed .
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if(actionId== EditorInfo.IME_ACTION_DONE){
//Clear focus here from edittext
editText.clearFocus();
}
if(editText.getText().equals(url_value)){
total++;
textView1.setText("Correct");
//display correct if right
}
else{
textView1.setText("Wrong");
//display wrong if wrong
}
return false;
}
});
}
},6000);
ici j'ai donné 6 secondes .. ce qui se passe vraiment est que la plaine textView est affiché pendant 6 secondes, puis la dernière question s'apparaît sur l'écran ..Handler ne fonctionne pas comme prévu
Log.d("For and url is ",formula_value+" and "+url_value);
}
j++;
}
}catch (JSONException e) {
e.printStackTrace();
}
voir le journal: ils sont enregistrés rapidement sans attendre .. ne me aident pls