android - How to access arraylist from an other void then it is generated in in Java? -
is possible access arraylist void generated in in java? (i'm making android app, did cutting downwards code massively)
package com.example.example; import ...; public class illustration { @override protected void oncreate(bundle savedinstancestate) { //android things here... arraylist<string> questionid = new arraylist<string>(); questionid.add("1"); questionid.add("2"); questionid.add("3"); questionid.add("4"); questionid.add("5"); questionid.add("6"); questionid.add("7"); questionid.add("8"); questionid.add("9"); questionid.add("10"); collections.shuffle(questionid, new random(system.nanotime())); } private void newquestion() { questionid.get(0); //<-- doesn't find arraylist questionid } } private void setnewquestion() { textview questionnumberlabel; questionnumberlabel = (textview) findviewbyid(r.id.questionnumber); if (questionnumberlabel.gettext().equals("1")) { } } }
is there way create arraylist accessible everywhere in class? again, i'm developing app android, did cutting downwards code bit.
you've declared questionid
local variable in oncreate
method. variable exists duration of method call. want instance variable - i.e. part of state of object, , available within methods.
public class illustration { private arraylist<string> questionid; @override protected void oncreate(bundle savedinstancestate) { questionid = new arraylist<string>(); questionid.add("1"); ... } private void newquestion() { string firstquestion = questionid.get(0); ... } }
java android
No comments:
Post a Comment