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

  • SEARCH
  • Home
  • 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 4550028
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T16:26:28+00:00 2026-05-21T16:26:28+00:00

I have a JSON file which is populated to an activity (Main.java). This Activity

  • 0

I have a JSON file which is populated to an activity (Main.java).

This Activity shows 3 random images from the URL on my JSON entries.

What I want to do is: I have 13 different entries on the my JSON, whenever I click the shown random picture it goes to another activity (ProjectDetail.java) containing the picture,title,and description depends on the item I click based on its entry on the JSON.

What do I have in is by using extra by I don’t know exactly how to perform that since I’m using JSON. What should I add into my top_listener method on my Main class and what should I add into my ProjectDetail class?

Main.java

   public class Main extends Activity {
            /** Called when the activity is first created. */
            
            ArrayList<Project> prjcts=null;
            private ImageThreadLoader imageLoader = new ImageThreadLoader();
            private final static String TAG = "MediaItemAdapter";
            
            
            @Override
            public void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
                setContentView(R.layout.main);
                
                prjcts = new ArrayList<Project>();
                WebService webService = new WebService("http://liebenwald.spendino.net/admanager/dev/android/projects.json");
                Map<String, String> params = new HashMap<String, String>();
                params.put("var", "");
                String response = webService.webGet("", params);
                
                try
                {
                    Type collectionType = new TypeToken<ArrayList<Project>>(){}.getType();
                    List<Project> lst= new Gson().fromJson(response, collectionType);
                    for(Project l : lst)
                    {
                        prjcts.add(l);
                        ConstantData.projectsList.add(l);
                    }
                }
                catch(Exception e)
                {
                    Log.d("Error: ", e.getMessage());
                }
                
                final Button project = (Button) findViewById(R.id.btn_projectslist);
                final Button infos = (Button) findViewById(R.id.btn_infos);
                final Button contact = (Button) findViewById(R.id.btn_contact);
                project.setOnClickListener(project_listener);
                infos.setOnClickListener(infos_listener);
                contact.setOnClickListener(contact_listener);
                
                ImageView image1;
                ImageView image2;
                ImageView image3;
                
                try {
                    image1 = (ImageView)findViewById(R.id.top1);
                    image2 = (ImageView)findViewById(R.id.top2);
                    image3 = (ImageView)findViewById(R.id.top3);
                  } catch( ClassCastException e ) {
                    Log.e(TAG, "Your layout must provide an image and a text view with ID's icon and text.", e);
                    throw e;
                  }
        
        
                  Bitmap cachedImage1 = null;
                  Bitmap cachedImage2 = null;
                  Bitmap cachedImage3 = null;
                  
                  //randomize the index of image entry
                  
                  int max = prjcts.size();
                  List<Integer> indices = new ArrayList<Integer>(max);
                  for(int c = 0; c < max; ++c)
                  {
                      indices.add(c);
                  }
                  
                  int arrIndex = (int)((double)indices.size() * Math.random());
                  int randomIndex1 = indices.get(arrIndex);
                  indices.remove(arrIndex);
                  
                  
                  int randomIndex2 = indices.get(arrIndex);
                  indices.remove(arrIndex);
                  
                
                  int randomIndex3 = indices.get(arrIndex);
                  indices.remove(arrIndex);
                  
             
                  
                  setImage(cachedImage1, image1, prjcts.get(randomIndex1));
                  setImage(cachedImage2, image2, prjcts.get(randomIndex2));
                  setImage(cachedImage3, image3, prjcts.get(randomIndex3));
                  
                  image1.setOnClickListener(top_listener);
                  image2.setOnClickListener(top_listener);
                  image3.setOnClickListener(top_listener);
            }
           
            
            
            public void setImage(Bitmap cachedImage, final ImageView image, Project pro)
            {
                //Bitmap cachedImage1 = null;
                try {
                    cachedImage = imageLoader.loadImage(pro.smallImageUrl, new ImageLoadedListener() 
                    {
                        public void imageLoaded(Bitmap imageBitmap)
                        {
                            image.setImageBitmap(imageBitmap);
                            //notifyDataSetChanged();                
                        }
                    });
                } catch (MalformedURLException e) {
                    Log.e(TAG, "Bad remote image URL: " + pro.smallImageUrl, e);
                }
                if( cachedImage != null ) {
                    image.setImageBitmap(cachedImage);
                  }
            }
            
            
            private OnClickListener top_listener = new OnClickListener() {
                public void onClick(View v) {
                            Intent top = new Intent(Main.this, InfosActivity.class);
                            startActivity(top);
                }
                };

ProjectDetail.java

public class ProjectDetail extends Activity implements OnClickListener{
    
    
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.project);
        
        Button weitersagen = (Button) findViewById(R.id.btn_weitersagen);
        weitersagen.setOnClickListener(this);
 
        Button sms = (Button) findViewById(R.id.btn_sms_spenden);
        sms.setOnClickListener(this);
        
        int position = getIntent().getExtras().getInt("spendino.de.ProjectDetail.position");
        Project project = ConstantData.projectsList.get(position);
      

      try {
          ImageView projectImage = (ImageView)findViewById(R.id.project_image);
          Bitmap bitmap = BitmapFactory.decodeStream((InputStream)new URL(project.bigImageUrl).getContent());
          projectImage.setImageBitmap(bitmap); 
        } catch (MalformedURLException e) {
          e.printStackTrace();
        } catch (IOException e) {
          e.printStackTrace();
        } 

      TextView project_title = (TextView)findViewById(R.id.txt_project_title);
      project_title.setText(project.project_title);
      
      TextView organization_title = (TextView)findViewById(R.id.txt_organization_title);
      organization_title.setText(Html.fromHtml("von " +project.organization_title));

      TextView project_description = (TextView)findViewById(R.id.txt_project_description);
      project_description.setText(Html.fromHtml(project.project_description));
        
    }
     

I also have this ConstantData.java, the index which holds my JSON properties:

 public class ConstantData{

   public static String project_title = "project title";
   public static String organization_title = "organization title";
   public static String keyword = "keyword";
   public static String short_code = "short code";
   public static String project_description = "description";
   public static String smallImageUrl = "smallImageUrl";
   public static String bigImageUrl = "bigImageUrl";
   public static String price= "price";
   public static String country= "country";



    public static ArrayList<Project> projectsList = new ArrayList<Project>();
    
    
    public int describeContents() {
        return 0;
    }

    public void writeToParcel(Parcel out, int flags) {
        out.writeString(project_title);
        out.writeString(organization_title);
        out.writeString(keyword);
        out.writeString(short_code);
        out.writeString(project_description);
        out.writeString(smallImageUrl);
        out.writeString(bigImageUrl);
        out.writeString(price);
        out.writeString(country);
    }

    public static final Parcelable.Creator<ConstantData> CREATOR
            = new Parcelable.Creator<ConstantData>() {
        public ConstantData createFromParcel(Parcel in) {
            return new ConstantData(in);
        }

        public ConstantData[] newArray(int size) {
            return new ConstantData[size];
        }
    };
    
    private ConstantData(Parcel in) {
        project_title = in.readString();
        organization_title = in.readString();
        keyword = in.readString();
        short_code = in.readString();
        project_description = in.readString();
        smallImageUrl = in.readString();
        bigImageUrl = in.readString();
        price = in.readString();
        country = in.readString();
    }
}
  • 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-21T16:26:29+00:00Added an answer on May 21, 2026 at 4:26 pm

    You could make the class ConstantData serializable by extending from Parcelable and implementing a couple of methods (see the documentation). Then you could pass a constantData instance as an extra by doing

    intent.putExtra("jsonData", constantDataInstance);
    

    and retrieving it from the other activity (in it’s onCreate() method) with

    getIntent().getExtras().getParcelable("jsonData");
    

    Otherwise you could just past as extra every field independently, but it would be a mess. This way is not only more easy to read and everything, but “well designed”.

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

Sidebar

Related Questions

I have a web service that queries data from this json file, but I
I have a ListBox that gets populated with items read from a JSON response.
So, I have a json file and I want to get the names of
I have created a json object from ruby with cobravsmongoose, however the attributes have
I have a primarily Ajax-driven site, the content of which is populated by making
I'm having a tough time with this one, I have a class which populates
I want to ask some questions about the JSP and JSON file. I have
I have a JSON array with ActiveRecord objects. These objects can be reconstructed using
I have a JSON as follows { columns : [RULE_ID,COUNTRY_CODE], RULE_ID : [1,2,3,7,9,101,102,103,104,105,106,4,5,100,30], COUNTRY_CODE
I have one JSON that is coming in a string format. I need to

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.