mardi 9 août 2016

Randomize array of questions while reading from text file android

This is a android quiz app code snippet which load the question from text file. I want to shuffle the question and answer after every next click so how can i implement random function ? http://ift.tt/2aSoHIM

http://ift.tt/2bckROQ

 private void loadQuestions() throws Exception {
        try {
        InputStream questions = this.getBaseContext().getResources()
                .openRawResource(R.raw.questions);
        bReader = new BufferedReader(new InputStreamReader(questions));
        StringBuilder quesString = new StringBuilder();
        String aJsonLine = null;
        while ((aJsonLine = bReader.readLine()) != null) {
            quesString.append(aJsonLine);
        }
        Log.d(this.getClass().toString(), quesString.toString());
        JSONObject quesObj = new JSONObject(quesString.toString());
        quesList = quesObj.getJSONArray("Questions");
        Log.d(this.getClass().getName(),
                "Num Questions " + quesList.length());
        } catch (Exception e){

        } finally {
            try {
                bReader.close();
            } catch (Exception e) {
                Log.e("", e.getMessage().toString(), e.getCause());
            }

        }


    }







http://ift.tt/2aSoHIM




Aucun commentaire:

Enregistrer un commentaire