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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T20:08:22+00:00 2026-05-22T20:08:22+00:00

I got this ListView which is populated from a JSON data on the web.

  • 0

I got this ListView which is populated from a JSON data on the web. But when I updated the JSON entry, for example adding a new entry the ListView isn’t updated. It doesn’t show the new entry on the list even though I’ve already called the notifyDataSetChanged().

Here’s my code:

public class ProjectsList extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.projects_list);
        Intent serviceIntent = new Intent(this, LooserSync.class);
        startService(serviceIntent);
        ListView listView = (ListView) findViewById(R.id.lstText);
        MySimpleCursorAdapter projectAdapter = new MySimpleCursorAdapter(this, R.layout.listitems,
                managedQuery(Uri.withAppendedPath(LooserProvider.CONTENT_URI,
                        Database.Project.NAME), new String[] { BaseColumns._ID,
                        Database.Project.C_PROJECTTITLE, Database.Project.C_SMALLIMAGE }, null, null,
                        null), new String[] { Database.Project.C_PROJECTTITLE, Database.Project.C_SMALLIMAGE }, new int[] {
                        R.id.txt_title, R.id.image });
        listView.setAdapter(projectAdapter);
        projectAdapter.notifyDataSetChanged();


        listView.setOnItemClickListener(new OnItemClickListener() {
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {              

                Intent i = new Intent(ProjectsList.this, DetailsActivity.class);
                i.setData(Uri.withAppendedPath(Uri.withAppendedPath(
                        LooserProvider.CONTENT_URI, Database.Project.NAME), Long
                        .toString(id)));
                i.putExtra("spendino.de.ProjectDetail.position",position);
                startActivity(i);
            }
        });

    }

    class MySimpleCursorAdapter extends SimpleCursorAdapter {

        public MySimpleCursorAdapter(Context context, int layout, Cursor c,
                String[] from, int[] to) {
            super(context, layout, c, from, to);
            loader = new ImageLoaderCache(context);
            this.context = context;
        }
        Activity activity= ProjectsList.this;
        Context context=null;
        ImageLoaderCache loader = null;

        public void setViewImage(ImageView v, String value) {
            v.setTag(value);
            loader.displayImage(value, activity, v);
        }
    }


}

UPDATED here’s the LooserSync.java

public class LooserSync extends IntentService {

    public LooserSync() {
        super("LooserSyncService");
    }

    @Override
    protected void onHandleIntent(Intent intent) {
        Database.OpenHelper dbhelper = new Database.OpenHelper(getBaseContext());
        SQLiteDatabase db = dbhelper.getWritableDatabase();
        DefaultHttpClient httpClient = new DefaultHttpClient();
        db.beginTransaction();
        HttpGet request = new HttpGet(
                "http://liebenwald.spendino.net/admanager/dev/android/projects.json");
        try {
            HttpResponse response = httpClient.execute(request);
            if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
                InputStream instream = response.getEntity().getContent();
                BufferedReader r = new BufferedReader(new InputStreamReader(
                        instream), 8000);
                StringBuilder total = new StringBuilder();
                String line;
                while ((line = r.readLine()) != null) {
                    total.append(line);
                }
                instream.close();
                String bufstring = total.toString();
                JSONArray arr = new JSONArray(bufstring);
                Database.Tables tab = Database.Tables.AllTables.get(Database.Project.NAME);
                tab.DeleteAll(db);
                for (int i = 0; i < arr.length(); i++) {
                    tab.InsertJSON(db, (JSONObject) arr.get(i));
                }
                db.setTransactionSuccessful();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        db.endTransaction();
        db.close();

    }

}
  • 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-22T20:08:22+00:00Added an answer on May 22, 2026 at 8:08 pm

    As you’re using a cursor to populate the list you have to get a new one or requery the old one after you changed (add, edit or remove) something on your model.

    When you got a new cursor you can pass it to the adapter by calling changeCursor().

    UPDATE

    Following code will get a new cursor each time onResume() called. So your list should be up to date. Of course changes on the model which are made while the list is shown are not updated to the list. If you want a live update of the list you have to implement some kind of observer pattern. So your activity would get notified when the model changed.

    public class ProjectsList extends Activity {
        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.projects_list);
            Intent serviceIntent = new Intent(this, LooserSync.class);
            startService(serviceIntent);
            ListView listView = (ListView) findViewById(R.id.lstText);
    
            final String[] from = new String[] { Database.Project.C_PROJECTTITLE, Database.Project.C_SMALLIMAGE };
            final int[] to = new int[] {R.id.txt_title, R.id.image};
    
            MySimpleCursorAdapter projectAdapter = new MySimpleCursorAdapter(this, R.layout.listitems, null, from, to);
    
            listView.setAdapter(projectAdapter);
    
            listView.setOnItemClickListener(new OnItemClickListener() {
                public void onItemClick(AdapterView<?> parent, View view, int position, long id) {              
    
                    Intent i = new Intent(ProjectsList.this, DetailsActivity.class);
                    i.setData(Uri.withAppendedPath(Uri.withAppendedPath(
                            LooserProvider.CONTENT_URI, Database.Project.NAME), Long
                            .toString(id)));
                    i.putExtra("spendino.de.ProjectDetail.position",position);
                    startActivity(i);
                }
            });
    
        }
    
        public void onResume(){
            Cursor cursor = managedQuery(Uri.withAppendedPath(LooserProvider.CONTENT_URI,
                            Database.Project.NAME), new String[] { BaseColumns._ID,
                            Database.Project.C_PROJECTTITLE, Database.Project.C_SMALLIMAGE }, null, null, null);
    
            ListView listView = (ListView) findViewById(R.id.lstText);                         
            ((CursorAdapter)listView.getAdapter()).changeCursor(cursor);
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

It seems like this should be straightforward but I'm boggling. I've got my listview
I've got a listbox from which I'm dragging into the ListView. Now I have
I got this síngleton cache object and it exposes an IEnumerable property which just
I´ve got a ListView which is bound to the ObservableCollection mPersonList. The Class Person
I've an aspx page which has got a textbox and a submit button.Entering data
I've got a ListView that works just great, except for this minor annoyance. I
This is the situation: I've got a listview with some item. Each of these
Got this table in SQL Server 2005, which is used to maintain a history
I got this exception in time of running a web application in java. What
I got this error today when trying to open a Visual Studio 2008 project

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.