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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T10:09:17+00:00 2026-06-03T10:09:17+00:00

When a user clicks on a list I need a way to update MyCustomAdapter

  • 0

When a user clicks on a list I need a way to update MyCustomAdapter such that a hash key,value pair is removed and the list is updated.

I’m really stuck down in onListItemClick can you help

thanks graham

protected void onListItemClick(ListView l, View v, int position, long id) { 
    //TODO Auto-generated method stub 

    Toast.makeText(getApplicationContext(),"SHORT click"  , Toast.LENGTH_LONG).show();
    Toast.makeText(getApplicationContext(),"DATA is" + map.entrySet() , Toast.LENGTH_LONG).show();  //NAME,VALUE
    //remove the key,value pair and update CustomAdapter 

    ????? 
    //end of remove entries from hashmap map   


} 


package telephone.org;



import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.Map.Entry;

import telephone.org.MyService.LocalBinder;
import android.app.ActivityManager;
import android.app.ListActivity;
import android.app.ActivityManager.RunningServiceInfo;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.os.IBinder;
import android.provider.ContactsContract;
import android.provider.ContactsContract.PhoneLookup;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemLongClickListener;


//class 1 
public class DynamicLists extends ListActivity { 


    MyService mService;
    boolean mBound = false;


//class 2 ///////////////////////////////////
public class MyCustomAdapter extends BaseAdapter { 


    public HashMap<String, Integer> mData = new HashMap<String,Integer>();
    private String[] mKeys;
    //constructor    
    public MyCustomAdapter(DynamicLists dynamicLists, int row, HashMap<String, Integer> map){ 
    mData = map;
    mKeys = mData.keySet().toArray(new String[map.size()]);
    Log.d(TAG, "INSIDE ADAPTER constructor HELLO WORLD " + map.entrySet()); 

}

public MyCustomAdapter(MyService mService, int row, Object map) {
        // TODO Auto-generated constructor stub
    }

@Override
public View getView(int position, View convertView, ViewGroup parent) {
//TODO Auto-generated method stub

    Log.d(TAG, "inside getview  ");
    View row=convertView;

if (row==null){
    LayoutInflater inflater=getLayoutInflater();
    row=inflater.inflate(R.layout.row, null);
}

TextView label =(TextView)row.findViewById(R.id.blocked);
label.setText(mKeys[position] +  "   " + getItem(position).toString()); //key + value 
return row;   


}



@Override
public int getCount() 
{
    // TODO Auto-generated method stub
    return mData.size();
}
@Override
public Object getItem(int position) 
{
    // TODO Auto-generated method stub
    Log.d(TAG, "inside getitem " + mData.get(mKeys[position])); 
    return mData.get(mKeys[position]);
}
@Override
public long getItemId(int position) 
{
    // TODO Auto-generated method stub
    return position;
}

}  //end of class 2 ////////////////////////



private static final String TAG = "DynamicList";

//class 1 

public static  HashMap<String, Integer> map = new HashMap<String, Integer>(); 





/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);


}


@Override
protected void onListItemClick(ListView l, View v, int position, long id) { 
    //TODO Auto-generated method stub 

    Toast.makeText(getApplicationContext(),"SHORT click"  , Toast.LENGTH_LONG).show();
    Toast.makeText(getApplicationContext(),"DATA is" + map.entrySet() , Toast.LENGTH_LONG).show();  //NAME,VALUE
    //remove the name,value pair 


    //end of remove entries from hashmap map   


    } 


@Override
public void onStart() {
    super.onStart();
     isMyServiceRunning();

}


public void onStop() {
    super.onStop();
    // Unbind from the service
    if (mBound) {
    unbindService(mConnection);
    mBound = false;
    }
}

private boolean isMyServiceRunning() { 
    ActivityManager manager = (ActivityManager) getSystemService(ACTIVITY_SERVICE); 
    for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) { 
        if ("telephone.org.MyService".equals(service.service.getClassName())) 
        { 
            //Toast.makeText(getApplicationContext(),"SERVICE IS RUNNING", Toast.LENGTH_LONG).show();
            Intent intent = new Intent(this, MyService.class);
            bindService(intent, mConnection, Context.BIND_AUTO_CREATE);  //SEE INTERACT WITH SERVICE BELOW


            return true; 
        } 
    } 
           Toast.makeText(getApplicationContext(),"SERVICE IS STOPPED AND IS NOT RUNNING", Toast.LENGTH_LONG).show();
    return false; 
} 

//INTERACT WITH SERVICE
/** Defines callbacks for service binding, passed to bindService() */
private ServiceConnection mConnection = new ServiceConnection() {
@Override
public void onServiceConnected(ComponentName className, IBinder service) {
// We've bound to LocalService, cast the IBinder and get LocalService instance
LocalBinder binder = (LocalBinder) service;
mService = binder.getService();
mBound = true;
Set<Entry<String, Integer>> whatsup = mService.getNumbers();
//Toast.makeText(getApplicationContext(),"NUMBER INTERACTION IS" + whatsup, Toast.LENGTH_LONG).show();
Log.d(TAG, "ELEMENTS from service are:" + whatsup);
//Toast.makeText(getApplicationContext(),"NUMBER OF ENTRIES IS" + whatsup.size(), Toast.LENGTH_LONG).show();


//convert SET BACK TO HASHMAP 
for (Entry<String,Integer> entry : whatsup) { 

    String name = null; 
    String[] projection = new String[] { 
            ContactsContract.PhoneLookup.DISPLAY_NAME};
    Uri uri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, Uri.encode(entry.getKey())); 
    Cursor cursor = getContentResolver().query(uri, projection, null, null, null);

    if (cursor.moveToFirst()) { 
        name = cursor.getString(cursor.getColumnIndex(ContactsContract.PhoneLookup.DISPLAY_NAME));
    }
    //Toast.makeText(getApplicationContext(),"RESOLVED NAME IS " + name, Toast.LENGTH_LONG).show();
    projection = null;
    map.put(name,entry.getValue()); 
    }

//NEW CODE 
MyCustomAdapter custom = (new MyCustomAdapter(DynamicLists.this, R.layout.row, map));
setListAdapter(custom);
custom.notifyDataSetChanged();
//END NEW CODE 
}

//end CONVERT SET BACK TO HASHMAP


@Override
public void onServiceDisconnected(ComponentName arg0) {
mBound = false;
}
};
//END INTERACTION WITH SERVICE 

} //end of class 1 
  • 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-03T10:09:18+00:00Added an answer on June 3, 2026 at 10:09 am

    You have to modify the adapter’s dataset (apparently your mData) and call the notifyDataSetChanged method of the adapter.

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

Sidebar

Related Questions

Every time a user clicks on a link in a list view unordered list,
A list of books is displayed on the page. When a user clicks a
I ran into the situation that I need a way to edit the data
I have a list of data that needs to be processed. The way it
When user clicks on select box , I want to hide the options menu
When a user clicks a submit button I want the form to be submitted.
Use case: user clicks the link on a webpage - boom! load of files
When the user clicks on a row in the datagrid (or uses the keyboard),
When the user clicks on a link to generate report I make an AJAX
When the user clicks a button, I want his browser to automatically scroll to

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.