I hava a ListView
and when you click on each row it starts downloading from a service in a new Intent
.
How can I update the progressBar
in the clicked row from the information that I get from service?
I hava a ListView
and when you click on each row it starts downloading from a service in a new Intent
.
How can I update the progressBar
in the clicked row from the information that I get from service?
In service send broadcast like below
Intent i = new Intent("Updated_Count");
i.putExtra("progress", <progress count>);
i.putExtra("row_index", <row_index>);
sendBroadcast(i);
On other side in activity receive it
public class newMessage extends BroadcastReceiver
{
@Override
public void onReceive(Context context, Intent intent)
{
String action = intent.getAction();
if(action.equalsIgnoreCase("Updated_Count")){
Bundle extra = intent.getExtras();
String progress= extra.getString("progress");
String index = extra.getString("row_index");
// now you can play with progress for any particular list row
}
}
You can place above class as sub class in to your list activity
Don't forget to register/unregister broadcast receiver
Happy Coding!
Use a broadcast receiver to notify the Progress bar in the activity. In your case the broadcast on receive you will update the progress bar and then notify the adapter of the data change.
You can use Broadcast Receiver from service to the activity or fragment.you have to register and unregistered broadcast on onResume()
and on onPause()
and created Broadcast instance in activity and sendBroadcast through service you can refer the following example:
http://www.truiton.com/2014/09/android-service-broadcastreceiver-example/