I need to display 3 random images from SQLite database horizontally. Since it's impossible to make a horizontal ListView
, I made 3 ListViews next to each other inside a horizontally oriented LinearLayout
:
final ListView g = (ListView)findViewById(R.id.lstText1);
final ListView h = (ListView)findViewById(R.id.lstText2);
final ListView i = (ListView)findViewById(R.id.lstText3);
g.setOnItemClickListener(this);
h.setOnItemClickListener(this);
i.setOnItemClickListener(this);
// Set the adapter to our custom adapter (below)
g.setAdapter(new MySimpleCursorAdapter(this, R.layout.toplist,
managedQuery(Uri.withAppendedPath(Provider.CONTENT_URI,
Database.Project.NAME), new String[] { BaseColumns._ID,
Database.Project.C_SMALLIMAGE}, null, null, "RANDOM() LIMIT 1"),
new String[] { Database.Project.C_SMALLIMAGE }, new int[] {R.id.image1}));
h.setAdapter(new MySimpleCursorAdapter(this, R.layout.toplist,
managedQuery(Uri.withAppendedPath(Provider.CONTENT_URI,
Database.Project.NAME), new String[] { BaseColumns._ID,
Database.Project.C_SMALLIMAGE}, null, null, "RANDOM() LIMIT 1"),
new String[] { Database.Project.C_SMALLIMAGE }, new int[] {R.id.image1}));
i.setAdapter(new MySimpleCursorAdapter(this, R.layout.toplist,
managedQuery(Uri.withAppendedPath(Provider.CONTENT_URI,
Database.Project.NAME), new String[] { BaseColumns._ID,
Database.Project.C_SMALLIMAGE}, null, null, "RANDOM() LIMIT 1"),
new String[] { Database.Project.C_SMALLIMAGE }, new int[] {R.id.image1}));
Everything works, except the random shown images should be distinct from each other. Since I use 3 different ListViews, sometimes they show the same random images. How can I solve my problem? Maybe by modifying "RANDOM() LIMIT 1"
?