Note that there are some explanatory texts on larger screens.

plurals
  1. POVisibility ArrayList inside function
    primarykey
    data
    text
    <p>I've a problem with an ArrayList. I declare the ArrayList inside a class. I populate it inside the OnCreate method. On the Oncreate method i call a function and inside this function i access to the ArrayList, but it's empty.... It's starnge: </p> <pre><code>public class List_themeActivity extends Activity{ String[] array ; ArrayList &lt;String&gt;bdd_checked = new ArrayList&lt;String&gt;(); private SQLiteDatabase bdd; private ListView listView_listebase; ListView msgList; ArrayList&lt;MessageDetails&gt; details; AdapterView.AdapterContextMenuInfo info; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.list_theme); List&lt;String&gt; bdd_checked = readList (this, "animal"); initDB("LSPCC4.db"); [...] } } protected void initDB(String BD_NAME){ int lg_bdd_checked=0; lg_bdd_checked=this.bdd_checked.size(); } </code></pre> <p>Someone can help me? thx</p> <p>Edit: Sorry the ArrayList is empty in iniDB().</p> <p>Thanks to maqjav, the problem is solved, i've done this:</p> <p>Before:</p> <pre><code>List&lt;String&gt; bdd_checked = readList (this, "animal"); </code></pre> <p>After:</p> <pre><code>bdd_checked = (ArrayList&lt;String&gt;) readList (this, "animal"); </code></pre> <p>and i've casted due to readList():</p> <p>public static List readList (Context context, String prefix) { SharedPreferences prefs = context.getSharedPreferences("YourApp", Context.MODE_PRIVATE);</p> <pre><code>int size = prefs.getInt(prefix+"_size", 0); List&lt;String&gt; data = new ArrayList&lt;String&gt;(size); for(int i=0; i&lt;size; i++) data.add(prefs.getString(prefix+"_"+i, null)); return data; </code></pre> <p>} </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload