Android : Download Manager Broadcast Receiver and loop through listview

on Tuesday, August 5, 2014


I have an app with list view of downloadable files. i used Download Manager for handling multiple downloads. Now my problem is i need to update list view row of completed download so in Broadcast Receiver i lop through list view rows to find appropriate row of data and update it but i receive Null pointer Exception in 6th item in list view.



BroadcastReceiver downloadReceiver = new BroadcastReceiver() {

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

long referenceId = intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, -1);

final ListView listView = getListView();
String[] a = null;

for (int i = 0; i < listView.getCount(); i++) {
View v = listView.getChildAt(i);
TextView et = (TextView) v.findViewById(R.id.dmrefrence);
Log.d( "position",et.getText().toString() );
Log.d( "i",Integer.toString(i) );
if(et.getText().toString() == Long.toString(referenceId) ){

ImageButton cancelButton = (ImageButton) v.findViewById(R.id.cancelButton);
cancelButton.setVisibility( View.GONE );
}

}

}
};//end of broadcast reciever

0 comments:

Post a Comment