1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
| class IconicAdapter extends ArrayAdapter<String>
{
IconicAdapter() {
super(getActivity(), R.layout.custom, R.id.label, myList);
}
public View getView(final int position, View convertView,ViewGroup parent)
{
View row = super.getView(position, convertView, parent);
ImageView icon=(ImageView)row.findViewById(R.id.icon);
TextView text =(TextView)row.findViewById(R.id.label);
File tmpFichier = new File(myList.get(position));
tmpFichier.getName();
int posPoint = tmpFichier.getName().lastIndexOf('.');
String Extension = tmpFichier.getName().substring(posPoint + 1);
String Name = tmpFichier.getName().substring(0, tmpFichier.getName().length() - 4);
Matcher m = Pattern.compile("$").matcher(Name);
m.find();
if (Extension.toString().equals("sec") && Extension.toString() != "pdf")
{
LENGTH = m.end() + 3;
icon.setVisibility(View.GONE);
row.setOnClickListener(null);
//row.setOnLongClickListener(null);
//row.setLongClickable(false);
text.setTypeface(null, Typeface.BOLD);
text.setTextColor(Color.WHITE);
text.setText(Name);
text.setBackgroundResource(R.color.black);
text.setLayoutParams(new TableLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, 1f));
text.setGravity(Gravity.RIGHT | Gravity.CENTER);
text.setText(Name);
}
else
{
icon.setImageResource(getResources().getIdentifier(Extension, "drawable", getActivity().getPackageName()));
text.setText(Name.substring(LENGTH));
}
return(row);
}
}
setListAdapter(new IconicAdapter());
} |
Partager