Last active
January 19, 2018 02:40
-
-
Save wightwulf1944/4a27d2ac16fde14378dfe6b81162119c to your computer and use it in GitHub Desktop.
adapter for listview
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class StorageIntroAdapter extends BaseAdapter { | |
private final LayoutInflater inflater; | |
private final List<StorageOption> data; | |
public StorageIntroAdapter(LayoutInflater inflater, List<StorageOption> data) { | |
this.inflater = inflater; | |
this.data = data; | |
} | |
@Override | |
public int getCount() { | |
return data.size(); | |
} | |
@Override | |
public StorageOption getItem(int position) { | |
return data.get(position); | |
} | |
@Override | |
public long getItemId(int position) { | |
return position; | |
} | |
@Override | |
public View getView(int position, View convertView, ViewGroup parent) { | |
View view = createView(convertView, parent); | |
StorageOption storageOption = getItem(position); | |
bindView(view, storageOption); | |
return view; | |
} | |
private View createView(View recycledView, ViewGroup parent) { | |
if (recycledView == null) { | |
return inflater.inflate(R.layout.item_storage_option, parent, false); | |
} | |
return recycledView; | |
} | |
private void bindView(View view, StorageOption storageOption) { | |
TextView titleText = view.findViewById(R.id.titleText); | |
titleText.setText(storageOption.getTitle()); | |
TextView pathText = view.findViewById(R.id.pathText); | |
pathText.setText(storageOption.getPath()); | |
TextView freeSpaceText = view.findViewById(R.id.freeSpaceText); | |
freeSpaceText.setText(storageOption.getFreeSpaceStr()); | |
ProgressBar gauge = view.findViewById(R.id.gauge); | |
gauge.setMax(storageOption.getTotalSpaceMb()); | |
gauge.setProgress(storageOption.getUsedSpaceMb()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment