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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T10:49:33+00:00 2026-06-09T10:49:33+00:00

I’ve listview on which when a user clicks an item I show an image

  • 0

I’ve listview on which when a user clicks an item I show an image that user has clicked this item.The listview gets populated from notifications.

Suppose an item gets added in listview.Now I click that item and image is shown in front of it.Now when I enter the new item in the listview nothing will happen(there are 2 items in the listview now). When I add the third item in the listview the image from the item at position 0 hides and is shown in position 1. Why this is happening?

Now to add an image in the listview item. I have to first perform some checks on the next opening activity and if those checks are successful then I place an image in front of that clicked item in the activity.

So to do this what i did is I am sending the clicked item position in the next activity and perform those checks, if those checks are successful I place and image on the onActivityResult function of the previous activity by using that position which I sent to this activity.Meaning that I send that position value back to the previous activity in the onActivityResult function where I place the Image.

The placement of image works fine.But while I recieve notification I add the item in the listview which results in the getView function being called for each item in the listview again to populate the listview.Here the problem occurs i.e the image from the position 0 item in the list goes to the position 1 item.

Please ask if more explanation is needed or something is not clear.

Here’s the code for listview Item Click:

                   TextView tv=(TextView)view.findViewById(R.id.clientip);

                    Intent i=new Intent(getApplicationContext(),ChatPageActivity.class);
                    i.putExtra("AdminEmail",ClientListActivity.AdminEmail);
                    i.putExtra("ClientIp",tv.getText().toString());
                    i.putExtra("ChildAt", position);

                    startActivityForResult(i, 200);

ChildAt is the position I am sending.
After performing checks in the next activity.

@Override
protected void onActivityResult(int requestCode,int resultCode,Intent data)
{
    try {
    super.onActivityResult(requestCode, resultCode, data);
    if(resultCode!= 23)
    {   
        Integer integer=data.getExtras().getInt("ChildAt");
        ImageView imageView=(ImageView)lv.getChildAt(integer).findViewById(R.id.onlineImg);
        imageView.setImageResource(R.drawable.online);
    }

}catch(Exception e)
{
    Log.e("ClientList_onActivityResult",e.getMessage());
}

}

This is the onActivityResult if the code is not equal to 23 it means all the checks in the next activity are correct and you can place the image at the position which is sent back again to this activity from the next activity.

Here’s the getView code of my BaseAdapter class:

@Override
public View getView(int position, View convertView, ViewGroup parent) {

    View view=convertView;

    if(convertView==null)
        view=inflater.inflate(R.layout.activeclientlist,null);

    TextView ip=(TextView)view.findViewById(R.id.clientip);

    String clientip=this.iplist.get(position);

    ip.setText(clientip);


    return view;
}

In the baseADapter I insert item in existing listview using this piece of code..

    this.iplist.add(ip);
    this.notifyDataSetChanged();

Important:
Also I wanted to mention that this behaviour happens in a pattern i.e as i’ve told above the image position changes when i insert the third item.After that it changes again when I’ll add the fifth item and so on.

  • 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-09T10:49:36+00:00Added an answer on June 9, 2026 at 10:49 am

    You should put the code to update the image view within the adapter itself.

    The adapter should also be knowing all the info he needs to draw the data. So instead of having it store a list of Strings, store a list of objects like:

    class Client {
      String ipAddress;
      boolean isConnected;
    }
    

    You then have to change your adapter:

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
    
        View view=convertView;
    
        if (convertView==null) {
            view=inflater.inflate(R.layout.activeclientlist,null);
        }
    
        TextView ip=(TextView)view.findViewById(R.id.clientip);
        ImageView status = (ImageView )view.findViewById(R.id.status);
    
        Client c = getItem(position);
    
    
        ip.setText(c.getIpAddress());
        status.setImageDrawable(c.isConnected() ? R.drawable.ic_status_connected : 0);
    
        return view;
    }
    

    Then just change the code to update the image when the connection status changes:

      if (resultCode!= 23) {   
         Integer i = data.getExtras().getInt("ChildAt");
         ((Client)adapter.getItem(i)).isConnected = true;
         adapter.notifyDataSetChanged();
      }
    

    This way you keep all the code related to representing your data within the adapter. Side effect, it should be correcting your code.

    Also have a look at the ViewHolder pattern to avoid doing findViewById on each row when you have a convertView available.

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I have a text area in my form which accepts all possible characters from
Does anyone know how can I replace this 2 symbol below from the string
I know there's a lot of other questions out there that deal with this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but

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.