public class RecorderAdapter extends ArrayAdapter<Recorder>
{
private int mminItemwitdth;
private int mmaxItemwitdth;
private LayoutInflater minflater;
public RecorderAdapter(Context context, List<Recorder>datas) {
super(context, -1,datas);
minflater = LayoutInflater.from(context);
WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
DisplayMetrics outMetrics = new DisplayMetrics();
assert wm != null;
wm.getDefaultDisplay().getMetrics(outMetrics);
mmaxItemwitdth = (int)(outMetrics.widthPixels*0.7f);
mminItemwitdth = (int)(outMetrics.widthPixels*0.15f);
}
@Override
public View getView(int position, View convertView, ViewGroup parent)
{
Viewholder holder ;
if(convertView == null)
{
convertView = minflater.inflate(R.layout.item_recorder, parent,false);
holder = new Viewholder();
holder.seconds = (TextView)convertView.findViewById(R.id.id_recorder_time);
holder.length = convertView.findViewById(R.id.id_recorder_length);
convertView.setTag(holder);
}
else {
holder = (Viewholder) convertView.getTag();
}
holder.seconds.setText(Math.round(getItem(position).time)+"\"");
ViewGroup.LayoutParams lp = holder.length.getLayoutParams();
lp.width = (int)(mminItemwitdth + (mmaxItemwitdth / 60f * (getItem(position)).time));
return convertView;
}
private class Viewholder
{
TextView seconds;
View length;
}
}