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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T22:44:25+00:00 2026-06-04T22:44:25+00:00

I have a MapActivity and ListActivity in one screen, when the user clicks one

  • 0

I have a MapActivity and ListActivity in one screen, when the user clicks one of the Pin on the Map, the clicked location will be on the top of the List and have a different background and divider color.

So I initiate to send the latitude of the clicked Pin and retrieve it on the getView(), if the clicked latitude is same with the displayed latitude on the first entry, it will do something.

I’ve managed to make the first entry of the ListView to have a certain background, but when I scroll down the List, some of the other entries’ background are also changed.

Here is my method:

double selectedLat = WWHApplication.getSelectedLatitude();
            DecimalFormat df = new DecimalFormat("#.#####");

            String dLat = df.format(lat);
            String sLat = df.format(selectedLat);
            if (position == 0) {
                if (dLat.equals(sLat)) {
                    feedViewHolder.layout
                            .setBackgroundResource(R.drawable.list_segment_selected);

                }
            }

How to change the color of the divider and the background of the ListView only on the first item?

Updated

Here’s the getView() method

@Override
        public View getView(final int position, View convertView,
                ViewGroup parent) {
            layoutInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            FeedViewHolder feedViewHolder = null;
            final VideoLocationDB vidLocation = videoLocationsDB[position];
            String url = vidLocation.documentary_thumbnail_url;
            String name = vidLocation.name;
            String title = vidLocation.name;
            String desc = vidLocation.text;
            double lat = vidLocation.latitude;
            double lng = vidLocation.longitude;
            String distance = calculateDistance(lat, lng);

            // System.out.println("ON LOC DISTANCE: "+distance);
            if (convertView == null) {

                // convertView = LocationsListActivity.this.getLayoutInflater()
                // .inflate(R.layout.listitems, null, true);
                convertView = layoutInflater.inflate(R.layout.listitems,
                        parent, false);
                feedViewHolder = new FeedViewHolder();
                feedViewHolder.layout = (LinearLayout) convertView
                        .findViewById(R.id.list_bg);
                feedViewHolder.titleView = (TextView) convertView
                        .findViewById(R.id.txt_title);
                feedViewHolder.descView = (TextView) convertView
                        .findViewById(R.id.txt_list_desc);
                feedViewHolder.more = (TextView) convertView
                        .findViewById(R.id.txt_more);
                feedViewHolder.distanceView = (TextView) convertView
                        .findViewById(R.id.txt_distance);
                feedViewHolder.v = (ImageView) convertView
                        .findViewById(R.id.image);

                Typeface fontRegular = Typeface.createFromAsset(getAssets(),
                        "miso.otf");
                feedViewHolder.titleView.setTypeface(fontRegular);
                Typeface fontLight = Typeface.createFromAsset(getAssets(),
                        "miso-light.otf");
                feedViewHolder.descView.setTypeface(fontLight);
                feedViewHolder.more.setTypeface(fontLight);
                feedViewHolder.distanceView.setTypeface(fontRegular);

                convertView.setTag(feedViewHolder);

            } else {
                feedViewHolder = (FeedViewHolder) convertView.getTag();
            }

            feedViewHolder.v.setTag(url);
            loader.DisplayImage(url, LocationsListActivity.this,
                    feedViewHolder.v, name);

            double selectedLat = WWHApplication.getSelectedLatitude();
            DecimalFormat df = new DecimalFormat("#.#####");

            String dLat = df.format(lat);
            String sLat = df.format(selectedLat);
            if (position == 0) {
                if (dLat.equals(sLat)) {
                    feedViewHolder.layout
                            .setBackgroundResource(R.drawable.list_segment_selected);
                }
            }

            feedViewHolder.titleView.setText(title.toUpperCase());
            feedViewHolder.descView.setText(desc);
            feedViewHolder.more.setText(getString(R.string.de_list_more));
            feedViewHolder.distanceView.setText(distance);

            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-04T22:44:27+00:00Added an answer on June 4, 2026 at 10:44 pm

    I don’t think the stock ListView supports that behavior really.

    You could fake it by setting the dividers on the ListView to 0, and adding in the dividers yourself as “plain” rows. Since you can make a row look like whatever you want, presumably you could inflate a view that looks like whatever kind of divider you want and add it to the list in-between each item. It should be possible to implement that logic in your adapters getView() method.

    EDIT:

    I think it should fix if you add an else block to your if that is changing the color like this:

    if (position == 0) {
        if (dLat.equals(sLat)) {
            feedViewHolder.layout.setBackgroundResource(R.drawable.list_segment_selected);
        }
    }else{
        feedViewHolder.layout.setBackgroundResource(android.R.drawable.list_selector_background);
    
    }
    

    and replace ‘list_normal’ with whatever your default background drawable is. If you didn’t set one probably what you need is something like android.R.drawable.list_selector_background You may have to look in the sdk res drawable folder to find the correct name, I could be wrong on its exact title. I checked, and I think that is the one you need. But I didn’t test it on device.

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

Sidebar

Related Questions

I have 2 classes. One will be a basic instructions screen and on that
I have to call mapactivity from list activity.whenever user click on item on listview,
I have a ListActivity and a MapActivity. I would like to launch either one
I have a MapActivity where i get the current location and i pin a
I have this MapActivity class below showing a map and putting a pin of
I have a MapActivity. If it's set to an appropriate location and zoom level
I have written one MapActivity class that is able to display a set of
In one of my Activities I do have up to six different AsyncTasks that
I have a MapActivity. It shows a Google map with some markers on it.
I have two activities in my Android project: Google Map Activity List Activity I'm

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.