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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T21:08:16+00:00 2026-06-08T21:08:16+00:00

I have a service that synchronize data every minute. When a data is modified/created,

  • 0

I have a service that synchronize data every minute. When a data is modified/created, I send a broadcast to my Activity in order to update my ListView.

To update the view, i want to delete it and recreate with right values but i don’t know its position, i only have the content of its textViews.

Activity :

public void onCreate{
...
this.registerReceiver(this.updateListReceiver, new IntentFilter(
            "com.android.updatelist"));
}

BroadcastReceiver updateListReceiver = new BroadcastReceiver() {

    @Override
    public void onReceive(Context context, Intent intent) {

        String id = intent.getExtras().getString("AccountId");
        String name = intent.getExtras().getString("AccountName");
        boolean isNew = intent.getExtras().getBoolean("isNew");

        if (isNew) {
            Account accountInList = new Account(id, name, null, null, null,
                    null);
            adapter.add(accountInList);
        } else {

        }
    }
};

Service :

Intent intent = new Intent();
                                intent.setAction("com.android.updatelist");
                                intent.putExtra("AccountId",
                                        updatedAccount.getAccountId());
                                intent.putExtra("AccountName",
                                        updatedAccount.getName());
                                intent.putExtra("isNew", true);
                                sendBroadcast(intent);

Adapter :

public class AccountNameListAdapter extends ArrayAdapter<Account> {

private final Context context;
private final int layoutResourceId;
private final ArrayList<Account> data;
private final TableLayout table;
private final TextView tableName;
private final TextView tableIndustry;
private final TextView tablePhone;
private final TextView tableWebsite;
final AccountBDD accountBdd;

public AccountNameListAdapter(Context context, int layoutResourceId,
        ArrayList<Account> data) {
    super(context, layoutResourceId, data);
    this.layoutResourceId = layoutResourceId;
    this.context = context;
    this.data = data;
    table = (TableLayout) ((Activity) context)
            .findViewById(R.id.tableLayout);
    tableName = (TextView) ((Activity) context).findViewById(R.id.NameText);
    tableIndustry = (TextView) ((Activity) context)
            .findViewById(R.id.IndustryText);
    tablePhone = (TextView) ((Activity) context)
            .findViewById(R.id.PhoneText);
    tableWebsite = (TextView) ((Activity) context)
            .findViewById(R.id.WebsiteText);

    accountBdd = SQLiteApplication.getAccountBdd();

}

@Override
public View getView(final int position, View convertView, ViewGroup parent) {

    AccountHolder holder = null;

    if (convertView == null) {
        LayoutInflater inflater = ((Activity) context).getLayoutInflater();
        convertView = inflater.inflate(layoutResourceId, parent, false);

        holder = new AccountHolder();

        convertView.setClickable(true);
        convertView.setFocusable(true);

        holder.txtName = (TextView) convertView.findViewById(R.id.nom);
        holder.txtId = (TextView) convertView.findViewById(R.id.id);

        convertView.setTag(holder);

    } else {
        holder = (AccountHolder) convertView.getTag();
    }

    convertView.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {

            table.setVisibility(0);

            String id = data.get(position).getAccountId();
            Account displayAccount = accountBdd.getAccountWithAccountID(id);

            tableName.setText(displayAccount.getName());
            tableIndustry.setText(displayAccount.getIndustry());
            tablePhone.setText(displayAccount.getPhone());
            tableWebsite.setText(displayAccount.getWebsite());
        }

    });

    holder.txtName.setText(data.get(position).getName());
    holder.txtId.setText(data.get(position).getAccountId());

    ImageButton img = (ImageButton) convertView.findViewById(R.id.check);
    img.setTag(position);

    return convertView;
}

static class AccountHolder {
    TextView txtName;
    TextView txtId;
}

}

How can i do please ?

  • 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-08T21:08:17+00:00Added an answer on June 8, 2026 at 9:08 pm

    Create a method in the adapter that takes the account_id as an input. It should look like this:

    private void deleteData(int account_id) {
       for(int i=0; i<data.size(); i++) {
          //search for the id and delete it from the data
       }
       notifyDatasetChanged();
    }
    

    and from the activity that you receive the BroadcastReceiver just call this method and you are ok. It is much quicker than you think.

    UPDATE: The Account is an object. The remove does not work that way, because the address memory always changes.

    Try to find the position of the exact object among the data and try data.remove(position). Something like this, instead of getAccountByID(int accountid) implement this:

    private int getPositionFromID(int accountid) {
       for(int i=0; i<data.size(); i++) {
           if(data.get(i).getAccountID() == accountID)
               return i; //if you have a match
       }
       return -1; //error code, that is not found
    }
    

    and then use the position to remove the exact spot:

    private void deleteData(int account_id) {
       int position = getPositionFromID(int accountid);
       if(position == -1) {
          //handle error
       } else {
          data.remove(position); 
          notifyDatasetChanged();
       }
    }
    

    Here you are! Now you have a full copy-paste example! I have done it many times, no need to mess up CursorAdapter or anything like that, pure hard-coded java. I am pretty sure this actually works, if it doesn’t work in your example I will advise you to debug and make sure everything is ok, because I guess there is something else wrong with your code, and not that the adapter is not populated.

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

Sidebar

Related Questions

I have a Service that sends an Intent to my Activity every 0.1 seconds.
I have a service that needs to update the registry every 5 minutes (counteract
I need to have ALWAYS a background service that will synchronize my Android application
I have a service that has a dependency on SQL server express (2005). Every
I have a service that will return 0 or more sets of data. The
Possible Duplicate: Android Service makes Activity not responding I use service to synchronize data
I have a service that use the tcp binding and this services allows to
I have a service that I would like it to become single instance, because
I have a service that is downloading a file. When the download is done,
I have .Net service that listens on single port over TCP protocol. Clients connect

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.