Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to select one of records on one field SQLite Android randomly
    primarykey
    data
    text
    <p>I've SQLite database table like this :</p> <pre><code>_id || Column1 || Column2 || 1 || test1 || a,b,c,d,e,f || 2 || test2 || g,h,i,j,k,l || 3 || test3 || m,n,o,p,q,r || </code></pre> <p>How do I select one random of Column2 from this table?</p> <p>I want the result like this :</p> <pre><code>_id || Column1 || Column2 || 1 || test1 || d || 2 || test2 || k || 3 || test3 || r || </code></pre> <p>assumed that d, k, r is random value of Column2 for each records.</p> <p>Thanks</p> <p>UPDATES : I've create CustomAdapter and add some View like this :</p> <pre><code> @Override public View newView(Context context, Cursor cursor, ViewGroup parent) { Cursor c = getCursor(); final LayoutInflater inflater = LayoutInflater.from(context); View v = inflater.inflate(layout, parent, false); int column2Name= c.getColumnIndex(DBAdapter.COLUMN2); String col2Name= c.getString(column2Name); String[] temp; Random random = new Random(); temp = col2Name.split(","); String col2 = temp[random.nextInt(temp.length)]; TextView col2_name = (TextView) v.findViewById(R.id.column2_label); if (col2_name != null) { col2_name .setText(col2); } return v; } @Override public void bindView(View v, Context context, Cursor c) { int column2Name= c.getColumnIndex(DBAdapter.COLUMN2); String col2Name= c.getString(column2Name); String[] temp; Random random = new Random(); temp = col2Name.split(","); String col2 = temp[random.nextInt(temp.length)]; TextView col2_name = (TextView) v.findViewById(R.id.column2_label); if (col2_name != null) { col2_name .setText(col2); } } </code></pre> <p>Now, just use that customAdapter on your activity, so that column2 can be show as 1 random value.</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