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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T05:07:40+00:00 2026-06-05T05:07:40+00:00

i want to refresh/update afeter i select the delete ContextItem, it deletes but dont

  • 0

i want to refresh/update afeter i select the “delete” ContextItem, it deletes but dont “refresh” the listview
see on code ListActivity:

public class ProjetoProTelefoneActivity extends ListActivity {
public final static String ID_EXTRA = "br.com.DaniloDeLuca.ProjetoProTelefone._ID";
Cursor modelo = null;
RestaurantAdapter adapter = null;
RestauranteHelper helper=null;
SharedPreferences prefs=null;

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.main);

    helper = new RestauranteHelper(this);
    prefs = PreferenceManager.getDefaultSharedPreferences(this);
    initList();
    prefs.registerOnSharedPreferenceChangeListener(prefListener);

    registerForContextMenu(getListView());
}

public void onDestroy(){
    super.onDestroy();

    helper.close();
}

//*********************************************************************************************************************************
// Long Press menu
//*********************************************************************************************************************************
public void onCreateContextMenu(ContextMenu menu,View v,ContextMenuInfo menuInfo){
    super.onCreateContextMenu(menu, v, menuInfo);
    AdapterView.AdapterContextMenuInfo info;
    try {
        info = (AdapterView.AdapterContextMenuInfo) menuInfo;
    } catch (ClassCastException e) {        
        return;
    }
    Cursor cursor = (Cursor) getListAdapter().getItem(info.position);
    if (cursor == null) {
        return;
    }
    new MenuInflater(this).inflate(R.menu.option_item,menu);
    super.onCreateContextMenu(menu,v,menuInfo);
}

public boolean onContextItemSelected(MenuItem item)
{
    AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
    int index = info.position;
    View view = info.targetView;
    long id = info.id;

    if(item.getItemId()==R.id.edit){
        Intent i=new Intent(ProjetoProTelefoneActivity.this, DetailForm.class);
        i.putExtra(ID_EXTRA, String.valueOf(id));
        startActivity(i);
        return(true);
    }
    else if(item.getItemId()==R.id.remove){

        Intent i=new Intent(ProjetoProTelefoneActivity.this, DeleteItemList.class);
        i.putExtra(ID_EXTRA, String.valueOf(id));
        startActivity(i);
        return(true);
    }
    return super.onContextItemSelected(item);
}
//*********************************************************************************************************************************
// Fim Long Press menu
//*********************************************************************************************************************************
public void onListItemClick(ListView list, View view,
        int position,long id){
    Intent i=new Intent(ProjetoProTelefoneActivity.this, DetailForm.class);
    i.putExtra(ID_EXTRA, String.valueOf(id));
    startActivity(i);
}
//hook into menu button for activity 
public boolean onCreateOptionsMenu(Menu menu){
    new MenuInflater(this).inflate(R.menu.option,menu);
    return(super.onCreateOptionsMenu(menu));
}
/// when menu button option selected 
public boolean onOptionsItemSelected(MenuItem item){
    if(item.getItemId()==R.id.add){
        startActivity(new Intent(ProjetoProTelefoneActivity.this, DetailForm.class));
        return(true);
    }
    else if(item.getItemId()==R.id.prefs){
        startActivity(new Intent(this, EditPreferences.class));
        return(true);
    }
    return(super.onOptionsItemSelected(item));
}

private SharedPreferences.OnSharedPreferenceChangeListener prefListener=
        new SharedPreferences.OnSharedPreferenceChangeListener() {

            public void onSharedPreferenceChanged(SharedPreferences sharedPreferences,
                    String key) {
                if(key.equals("sort_order")){
                    initList();
                }

            }
};
private void initList(){
    if(modelo!=null){
        stopManagingCursor(modelo);
        modelo.close();
    }

    modelo =helper.getAll(prefs.getString("sort_order","nome DESC"));
    startManagingCursor(modelo);

    adapter = new RestaurantAdapter(modelo);       
    setListAdapter(adapter);         

}

class RestaurantAdapter extends CursorAdapter {
    RestaurantAdapter(Cursor c) {
      super(ProjetoProTelefoneActivity.this, c);
    }

    public void bindView(View row, Context ctxt,
                         Cursor c) {
      RestaurantHolder holder=(RestaurantHolder)row.getTag();

      holder.populateFrom(c, helper);
    }


    public View newView(Context ctxt, Cursor c,
                         ViewGroup parent) {
      LayoutInflater inflater=getLayoutInflater();
      View row=inflater.inflate(R.layout.row, parent, false);
      RestaurantHolder holder=new RestaurantHolder(row);

      row.setTag(holder);

      return(row);
    }
  }

  static class RestaurantHolder {
    private TextView name=null;
    private TextView address=null;
    private ImageView icon=null;

    RestaurantHolder(View row) {
      name=(TextView)row.findViewById(R.id.title);
      address=(TextView)row.findViewById(R.id.address);
      icon=(ImageView)row.findViewById(R.id.icon);
    }

    void populateFrom(Cursor r,RestauranteHelper helper) {
      name.setText(helper.getNome(r));
      address.setText(helper.getEnd(r));


      if (helper.getTipo(r).equals("casa")) {
        icon.setImageResource(R.drawable.casa_icon);
      }
      else if (helper.getTipo(r).equals("apartamento")) {
        icon.setImageResource(R.drawable.apartamento_icon);
      }
      else {
        icon.setImageResource(R.drawable.comercio_ico);
      }
    }
  }

}

Now my DeleteItemList:

public class DeleteItemList extends Activity{
RestauranteHelper helper = null;
String restauranteId= null;
public void onCreate(Bundle savedInstaceState){
    super.onCreate(savedInstaceState);
    helper= new RestauranteHelper(this);


    restauranteId=getIntent().getStringExtra(ProjetoProTelefoneActivity.ID_EXTRA);

    helper.delete(restauranteId);
    finish();
}

public void onDestroy(){
    super.onDestroy();
    helper.close();

}

}

RestauranteHelper.delete:

    public void delete(String id){
    String[] args = {id};

    getWritableDatabase().delete("restaurantes", "_ID =?", args);

}

idk if its clear what i want to do… i want to refresh the list, afeter selecting “Remove” option.

=D

  • 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-05T05:07:42+00:00Added an answer on June 5, 2026 at 5:07 am

    After changing the items in the list call the notifyDatasetChanged on your list adapter. That will do it.

    Here is how the ListView will work.

    After you initialize the list, set the items in the list adapter.
    Now call listview.setAdapter method to set the adapter.

    Now when ever you make any changes in the items, change them on the list that you have passed to the adapter.

    Then call the notofyDatasetChanged on your adapter.

    That should work. If that is not working, then something else is wrong and try to debug each step of your code.

    ** In your case you are calling the delete on the database helper, but your cursor or adapter does not update when you change your stuff on the database. You need to remove that item from the cursor or query the database again and then pass it to the adapter.

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

Sidebar

Related Questions

I want to be able to refresh a view from another class, but nothing
I want to partially update page when i upload or delete the image. What
What am I doing wrong? I want the 'refreshB' button to call the 'update'
I want to refresh Google Map and send new geolocalization request without refreshing the
I have some problems using ajax with Spring MVC. I want to refresh only
I want to submit a form without page refresh using jQuery. I found some
i just want to find out the name of this grid to refresh it.
I want to create an event with YUI where every two seconds, refresh the
I have a Devexpress Gridview that is linked to a delete, fetch and update
I have an HTML page where I want to refresh a lot of images

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.