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 9045979
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T11:30:41+00:00 2026-06-16T11:30:41+00:00

this app will get get son from server. The value that I want to

  • 0

this app will get get son from server. The value that I want to use is categoryid. you know clearly in the code below.

How can I use categoryid that from json to make condition to change imageview?

Hint: my ImageView is in ImageAdapter class

and I want to use condition that,

    if(catetgoryid == 1){
       imageview.setImageResource(R.drawable.image1)
    } elseif (categoryid == 2 {
        imageview.setImageResource(R.drawable.image2)
    } else {
     imageview.setImageResorce(R.drawable.image3)
    }

JSON

{
"count": 54,
"data": [
    {
        "userid": "24",
        "cardid": "114",
        "title": "meeting now!",
        "carddate": "2012-12-26",
        "categoryid": "2",
        "cardimage": "http://xxx.xxx/data/card/thum/9589266f7983dbe72ff8481800f51ef9.jpg",
        "public": "1",
        "user": {
            "user_id": "24",
            "firstname": "kong",
            "lastname": "kea",
            "email": "xxx",
            "picture": "http://xxx.xxx/data/profiles/thum/default.png",
            "friend_status": "NOT_FRIEND"
        }
    }
]

}

MainActivity. this is MainActivity that get get json categoryid

@Override
    protected Void doInBackground(String... params) {

        String url = "http://xxx.xxx.xxx/card/all/30/0/?token=57LzEsmBeykLbDCD04wTgK9WWV2XjJY0XBdqVU0HQvjIdu5EtTWOT1IQ1AYNwxt6Q5bG6FG73uvzLQSDGAIezwc8VcopEp0s63uzbdVgLSfts0TLmuVDOgyfn4lX";
        JSONArray data = null;

        try {

            JSONObject jsonObject = new JSONObject(getJSONUrl(url));

            MyArrList = new ArrayList<HashMap<String, Object>>();
            HashMap<String, Object> map;
            data = jsonObject.getJSONArray("data");
            for (int i = 0; i < data.length(); i++) {
                JSONObject c = data.getJSONObject(i);
                map = new HashMap<String, Object>();

                // Thumbnail Get ImageBitmap To Object
                map.put("cardimage", (String) c.getString("cardimage"));
                map.put("ImageThumBitmap",(Bitmap) loadBitmap(c.getString("cardimage")));

                map.put("categoryid",(String)c.getString("categoryid"));  // use it for condition 

                MyArrList.add(map);
            }

        } catch (JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        return null;
    }

Use condition here

public class ImageAdapter extends BaseAdapter {
    private Context context;
    private ArrayList<HashMap<String, Object>> MyArr = new ArrayList<HashMap<String, Object>>();

    public ImageAdapter(Context c,ArrayList<HashMap<String, Object>> myArrList) {
        context = c;
        MyArr = myArrList;
    }

    public int getCount() {
        return MyArr.size();
    }

    public Object getItem(int position) {
        return position;
    }

    public long getItemId(int position) {
        return position;
    }

    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        viewHolder = new ViewHolder();

        LayoutInflater inflater = (LayoutInflater) context
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);

        if (convertView == null) {
            convertView = inflater.inflate(R.layout.grid_item, null);
        }
            viewHolder.categoryCard = (ImageView) convertView.findViewById(R.id.category_card);

            // ====================== use codition here ===============
            viewHolder.categoryCard.setImageResource(R.drawable.card_beauty);  
            viewHolder.imageView = (ImageView) convertView.findViewById(R.id.imageView1);

        try {
            viewHolder.imageView.setImageBitmap((Bitmap) MyArr.get(position).get("ImageThumBitmap"));
        } catch (Exception e) {
            viewHolder.imageView.setImageResource(android.R.drawable.ic_menu_report_image);
        }

        return convertView;

    }

}
  • 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-06-16T11:30:44+00:00Added an answer on June 16, 2026 at 11:30 am

    In your getView() method, try something like this. In the below method, you are sending the imageview along with the categoryid:
    // Convert the category id to integer from String by using Integer.parseInt(categoryId); or you can compare with string itself in your if conditions like categoryId.equals(“1”); and so on…

    public View getView(int position, View convertView, ViewGroup parent) {
            ViewHolder viewHolder;
            viewHolder = new ViewHolder();
    ........................
    ...........................
    
    viewHolder.imageView = (ImageView) convertView.findViewById(R.id.imageView1);
    putDefaultImage(categoryid, viewHolder.imageView);
    .............................
    }
    
     private void putDefaultImage(int categoryid, ImageView imageview)
        {
             if(catetgoryid == 1){
           imageview.setImageResource(R.drawable.image1)
        } elseif (categoryid == 2) {
            imageview.setImageResource(R.drawable.image2)
        } else {
         imageview.setImageResource(R.drawable.image3)
        }
    

    Hope this helps.

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

Sidebar

Related Questions

In this app I want that as I click on button the data from
I've been asked to create an app that will get data back from a
This is about a web app that serves images. Since the same request will
Suppose I run an application, after some time this app will get closed by
My wp7 app will get an array of image URLs from the web ,
I've written an iOS app that I want to port to android. This app
I am developing an application where my app will get data from some other
Hello was just wondering if my app will get rejected using the following code:
I try to write a Facebook app. This app will communicate with a rfid
I have installed an app on my iPod touch. Will this app expire when

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.