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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T02:01:54+00:00 2026-05-23T02:01:54+00:00

For the navigation in my Android app I am using a ListView and create

  • 0

For the navigation in my Android app I am using a ListView and create and set a BaseAdapter for it in the onCreate method of the activity.

The BaseAdapter accesses an ArrayList to retrieve elements (cache.getNavigation()):

public class NavigationAdapter extends BaseAdapter {
    Context mContext;

    public NavigationAdapter(Context c) {
        mContext = c;
    }

    @Override
    public int getCount() {
        return cache.getNavigation() != null ? cache.getNavigation().size()
                : 0;
    }

    @Override
    public Object getItem(int position) {
        return cache.getNavigation() != null ? cache.getNavigation().get(
                position) : 0;
    }

    @Override
    public long getItemId(int position) {
        return cache.getNavigation() != null ? cache.getNavigation().get(
                position).getId() : 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View v;
        if (convertView == null) {
            LayoutInflater li = getLayoutInflater();

                v = li.inflate(R.layout.list_nav_icon, null);
                TextView tv = (TextView) v.findViewById(R.id.list_nav_text);
                tv.setText(((TemplateInstanceDto) getItem(position))
                        .getName());

                ImageView icon = (ImageView) v
                        .findViewById(R.id.list_nav_icon);
                byte[] binary = ((TemplateInstanceDto) getItem(position))
                        .getIcon();
                Bitmap bm = BitmapFactory.decodeByteArray(binary, 0,
                        binary.length);
                icon.setImageBitmap(bm);

                ImageView arrow = (ImageView) v
                        .findViewById(R.id.list_nav_arrow);
                arrow.setImageResource(R.drawable.arrow);


        } else {
            v = convertView;
        }
        return v;
    }
}

So the navigation is built on startup from the cache.
Meanwhile I start an AsyncTask that retrieves the navigation ArrayList from a server and when it has changed it saves the new navigation into the cache:

private class RemoteTask extends
        AsyncTask<Long, Integer, List<TemplateInstanceDto>> {
    protected List<TemplateInstanceDto> doInBackground(Long... ids) {
        try {
            RemoteTemplateInstanceService service = (RemoteTemplateInstanceService) ServiceFactory
                    .getService(RemoteTemplateInstanceService.class,
                            getClassLoader());

            List<TemplateInstanceDto> templates = service
                    .findByAccountId(ids[0]);

            return templates;
        } catch (Exception e) {
            return null;
        }
    }

    protected void onPostExecute(List<TemplateInstanceDto> result) {
        if (result != null && result.size() > 0) {
            cache.saveNavigation(result);
            populateData();
        } else {
            Toast text = Toast.makeText(ListNavigationActivity.this,
                    "Server communication failed.", 3);
            text.show();
        }
    }
}

When I do nothing more in populateData(), the ListView doesn´t update. When I call ((BaseAdapter) ListView.getAdapter()).notifyDataSetChanged() the View is updated, but the order is inverted. The first item is the last and the last is the first and so on.

Held needed! Thanks in advance.

  • 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-23T02:01:55+00:00Added an answer on May 23, 2026 at 2:01 am

    the problem lies with getView() function.
    through different calls of the method, the View objects are cached, though not coupled with the position.

    with proper logs, you can also see this behavior as:

     pos1: View1 
     pos2: View2
     pos3: View3
     pos3: View1
     pos2: View2
     pos1: View3
    

    thats why the list is getting inverted.
    Solution: on each call of getView, set values in Value even if the object exists. i.e.:

     public View getView(int position, View convertView, ViewGroup parent) {
        View v;
        if (convertView == null) {
            LayoutInflater li = getLayoutInflater();
            v = li.inflate(R.layout.list_nav_icon, null);
        } else {
            v = convertView;
        }
        TextView tv = (TextView) v.findViewById(R.id.list_nav_text);
        tv.setText(((TemplateInstanceDto) getItem(position))
                        .getName());
    
        ImageView icon = (ImageView) v
                        .findViewById(R.id.list_nav_icon);
        byte[] binary = ((TemplateInstanceDto) getItem(position))
                        .getIcon();
        Bitmap bm = BitmapFactory.decodeByteArray(binary, 0,
                        binary.length);
        icon.setImageBitmap(bm);
    
        ImageView arrow = (ImageView) v
                        .findViewById(R.id.list_nav_arrow);
        arrow.setImageResource(R.drawable.arrow);
    
        return v;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am making for my Graduation Project a low price Navigation device, using Android
I'm writing a toy car-navigation app for Android, mostly to learn the Android SDK.
How do I fully close a PhoneGap Android app? I've tried using device.exitApp() as
I am using phonegap and sqlite to develop cross-platform mobile app for android,ios,blackberry.For reference
In android you could set a navigation list in action bar by passing spinner
I was trying to figure out how to create navigation bar like pulse android
I'm trying to implement tabs for navigation in an Android app. Since TabActivity and
I have developed an app in android 4.0.3(Ice-cream Sandwich), i am using two activities
So for Android's LinkedIn app, there is a navigation bar and once you click
During navigation of the java.lang.reflect.Method class I came across the method isBridge . Its

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.