Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5984239
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T22:20:47+00:00 2026-05-22T22:20:47+00:00

I have an activity which shows 3 random images from JSON data off the

  • 0

I have an activity which shows 3 random images from JSON data off the Web. Each random image is clickable and leads to its details activity, carrying its title, image, description, etc. The shown images are distinct from each other.

I need to implement SQLite and a Cursor to that activity so that whenever there’s no internet connection, the application reads the image data from the cache on the external storage. I already have the classes of the database, provider and sync. I have an SQLite database with the following columns:

  • BaseColumns._ID
  • Database.Project.C_SMALLIMAGE

Here are the snippets of code that I have so far:

void doSync() {
    Intent serviceIntent = new Intent(this, LooserSync.class);
    startService(serviceIntent);
} 

This method calls the Web service where I put my URL. This is the image is loaded:

public void setViewImage(ImageView v, String value) {
    v.setTag(value);
    loader.DisplayImage(value, context, v);
}

This is my old function that randomizes the images and makes them clickable:

prjcts = new ArrayList<Project>();
int max = prjcts.size();
System.out.println(max);
List<Integer> indices = new ArrayList<Integer>(max);
for(int c = 1; c < max; ++c) {
    indices.add(c);
}
Random r = new Random();
int arrIndex = r.nextInt(indices.size());
int randomIndex1 = indices.get(arrIndex);
indices.remove(arrIndex);

This is what I have in my activity so far:

int arrIndex2 = r.nextInt(indices.size());
int randomIndex2 = indices.get(arrIndex2);
indices.remove(arrIndex2);

int arrIndex3 = r.nextInt(indices.size());
int randomIndex3 = indices.get(arrIndex3);
indices.remove(arrIndex3);

imageLazy(image1, prjcts.get(randomIndex1),Main.this);
imageLazy(image2, prjcts.get(randomIndex2),Main.this);
imageLazy(image3, prjcts.get(randomIndex3),Main.this);

image1.setOnClickListener(new RandomClickListener(randomIndex1));
image2.setOnClickListener(new RandomClickListener(randomIndex2));
image3.setOnClickListener(new RandomClickListener(randomIndex3));

public void imageLazy(final ImageView image,Project pro,Activity activity) {
     String imageurl = pro.smallImageUrl;
     image.setTag(imageurl);
     loader.DisplayImage(imageurl, activity,image);
}

public class RandomClickListener implements View.OnClickListener {
     private final int randomIndex;

     public RandomClickListener(final int randomIndex) {
           this.randomIndex = randomIndex;
     }
     @Override
     public void onClick(View v) {
          Intent top = new Intent(Main.this, DetailsActivity.class);
          top.putExtra("spendino.de.ProjectDetail.position", randomIndex);
          /*
          top.setData(Uri.withAppendedPath(Uri.withAppendedPath(
          LooserProvider.CONTENT_URI, Database.Project.NAME), Long.toString(id)));
           */
          startActivity(top);
     }
}

Here is a function that retrieves the image details:

Uri uri = Uri.withAppendedPath(Uri.withAppendedPath( LooserProvider.CONTENT_URI, Database.Project.NAME), Long .toString(id));

Cursor managedCursor = managedQuery( uri, new String[] { BaseColumns._ID, Database.Project.C_BIGIMAGE }, null, null, "RANDOM() LIMIT 3");

Any suggestions on how to build the code from these snippets?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T22:20:48+00:00Added an answer on May 22, 2026 at 10:20 pm

    for FSM’s sake use ListView with query like this

    Cursor managedCursor = managedQuery( //it seems like you should change your internship
                    uri, //to somthing esier than programming
                    projection,    // Which columns to return.
                    null,          // WHERE clause.
                    null,          // WHERE clause value substitution
                    "RANDOM() LIMIT 3");   
    

    with this query u get top 3 rows from Project table in random order

    EDIT:

    1. use ListView
    2. wrong uri … you didn’t made your homework (by reading this). Try this one. Uri uri = Uri.withAppendedPath( LooserProvider.CONTENT_URI, Database.Project.NAME));
    3. About using Cursors:

      Cursor c = query();

      if(c.moveToFirst()){

      do{
      
          //do something with current row like c.getString(1);
      
      }while(c.moveToNext());
      

      }

    4. but why oh why you don’t using ListView

    EDIT2:
    chang similar lines in my sample for looser to:

        listView.setAdapter(new MySimpleCursorAdapter(this, R.layout.itemrow,
                managedQuery(Uri.withAppendedPath(LooserProvider.CONTENT_URI,
                        Database.Project.NAME), new String[] { BaseColumns._ID,
                        Database.Project.C_PROJECTTITLE,
                        Database.Project.C_ORGANIZATIONTITLE,
                        Database.Project.C_SMALLIMAGE }, null, null, "RANDOM() LIMIT 3"),
                new String[] { Database.Project.C_PROJECTTITLE,
                        Database.Project.C_ORGANIZATIONTITLE,
                        Database.Project.C_SMALLIMAGE }, new int[] {
                        R.id.tName, R.id.tDescription, R.id.iItem }));
    

    you can do Menu->Synchronize to see what happend

    get rid of text from listrow and you got your program

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an activity which shows some List entries. When I click on a
I have a JSON file which is populated to an activity (Main.java). This Activity
I have an activity which shows a Spinner (selection of category of items), a
I have an activity (act2), which can be launched from act1 or act3. If
I have a couple of tables which are used to log user activity for
I have an activity that has a TabHost containing a set of TabSpecs each
I have a web-based application that notifies users of activity on the site via
this is the current state/situation: I have an Activity which binds a Service which
I have a main activity which calls a child one via Intent I =
I want to write a simple program which shows my internet activity over a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.