The getChildCount() method returns only the total number of children currently visible in the listview. You will have to get the data to be synced from the data-source (provided to the listview adapter). That is the correct way of doing it.
However, if you have to sync an item in the listview and update that particular view after syncing it, you can leverage the adapter's notifyDataSetChanged. You can have a flag that is checked to see if that particular record of the listview is to be updated or not.
// An array of flags, as many as the number of records in the listview
// such that, flag[0] is set to true to indicate that the first item in the
// listview needs to call startUpload()
private SparseBooleanArray flags = new SparseBooleanArray();
// At onClick, set all the flags to indicate that some data needs to be synced
ImageButton buttonSync = (ImageButton) findViewById(R.id.sync_btn);
buttonSync.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
for(int position=0; position<listView.getAdapter().getCount(); position++)
{
flags.put(position, true);
}
// Calling this would ensure a call to getView() on every
// visible child of the listview. That is where we will check if
// the data is to be synced and displayed or not
((BaseAdapter) listView.getAdapter()).notifyDataSetChanged();
}
});
@Override
// In getView of the listview's adapter
public View getView(int position, View convertView, ViewGroup parent) {
// If this item is to be synced
if(flags.get(position)) {
startUpload();
// Mark as synced
flags.put(position, false);
}
// Rest of the method that draws the view....
}