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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T17:27:20+00:00 2026-05-30T17:27:20+00:00

I have an app which uses a Listview to display Lectures. The Lectures are

  • 0

I have an app which uses a Listview to display Lectures. The Lectures are colour coded according to their type. I used a custom adapter to control the different colours of each lecture. I call the adapter using the code below –

    cursor = myDbHelper.getReadableDatabase().rawQuery(sql, null);       
    startManagingCursor(cursor);
    adapter = new Lectures_Adapter(this,R.layout.menu_item,cursor,FROM,TO);        
    menuList.setAdapter(adapter);

This all works ok until I re-order the Lectures, say by Location. The code I use is –

    Cursor newCursor = myDbHelper.getReadableDatabase().rawQuery(sqlStr, null);
    adapter.changeCursor(newCursor);

The code in my custom adapter (Lectures_Adapter) is below but is not called when the Lectures are re-ordered.

     public class Lectures_Adapter extends SimpleCursorAdapter {
         private Context appContext;
         private int layout;
         private Cursor mycursor;

         public Lectures_Adapter(Context context, int layout, Cursor c, String[] from,int[] to) {
              super(context, layout, c, from, to);
              this.appContext=context;
              this.layout=layout;
              this.mycursor=c;               
         }

         @Override
         public View getView(int position, View convertView, ViewGroup parent)     
         {   
              View view = super.getView(position, convertView, parent);   
              try {             
                 if (position > 0)
                 {               
                    RelativeLayout rowFill = (RelativeLayout) convertView.findViewById(R.id.rowFill);
                    String title = mycursor.getString(1);                
                    int myColor = 0;
                    int myPos = title.indexOf("Nursing");
                    int myPos2 = title.indexOf("Masterclass");
                    if (myPos >= 0)
                    {
                        myColor = Color.parseColor("#99FF66");
                    }
                    else if (myPos2  >= 0)
                    {
                        myColor = Color.parseColor("#FF99FF");
                    }
                    else
                    {
                        myColor = Color.parseColor("#FFFF66");
                    }
                    convertView.findViewById(R.id.rowFill).setBackgroundColor(myColor);                 
                  }         
               }catch(Exception e) {

               }

              if (convertView == null) {
                  LayoutInflater inflator = (LayoutInflater) this.appContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                  convertView = inflator.inflate(this.layout,null);
              } else {
                  convertView = (View) convertView;
              }
              return view;  
          }

       }

Can somebody please tell me how I can re-order my Listview dynamically and call me custom adapter each time.

  • 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-30T17:27:21+00:00Added an answer on May 30, 2026 at 5:27 pm

    The problem is that your code in getView() gets its data from the class variable mycursor, but when you call changeCursor, the mycursor variable is not getting updated, so you still see the original list. Rather than using mycursor, you should call getCursor() instead.

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

Sidebar

Related Questions

I have developed an app which uses my own custom keyboard (well, a view
I have an app which uses two sliders to generate a product used elsewhere
I have an app which uses a keyboard hook procedure in a library. The
I have a C# app which uses a System.Diagnostics.Process to run another exe. I
I have a Silverlight web app which uses ASP.net Website administration tool for user
We have a a VB6 app (in a COM component) which uses CDate() to
I have an ASP.NET MVC server app and client code which uses jquery. I'd
I have created an app that uses NSTimer, which gets triggered each second. My
I have a App which uses the camera to take a picture. The camera
I have a iPhone app which uses TabBar in Navigation controller. I have a

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.