dimanche 2 août 2015

displaying all values of arraylist to a textview

Actually i am developing an app where i have to generate random values from an arraylist1 and save the generated values to the arraylist2. then display all the values of arraylist2 to a multiline textview on the screen.but after trying to open the app the app crashes with the usual message of "unfortunately the app has been closed" dont ask for the logcat. as i know there's a certain problem with the code. here's my code.

final Random randomGenerator = new Random();
ArrayList<String>obj;
ArrayList<String>rndmObj;
public String item=null;
private void randObjFunc(){
    int index=0;
    while(index <10){
        item = obj.get(randomGenerator.nextInt(obj.size()));
        rndmObj.add(index, item);
        obj.remove(obj.indexOf(item));
        index++;
    }
    dispRndmObj();
}


private void dispRndmObj(){
    for (int i=0; i<rndmObj.size();i++){
        ((TextView) findViewById(R.id.tvObjectList1))
        .setText(rndmObj.get(i).toString());
    }        

}

hoping for quick and some useful suggestions, guidance and code snippet as a new bee here!




Aucun commentaire:

Enregistrer un commentaire