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 47 48 49 50 51 52 53 54 55 56 57 58 59
| public class MyListAdapter extends ArrayAdapter<String[]>{
int groupid;
List<String[]> items;
Context context;
String test;
public MyListAdapter(Context context, int vg, int id, List<String[]> items){
super(context,vg, id, items);
this.context=context;
groupid=vg;
this.items=items;
}
static class ViewHolder {
public TextView textid;
//public TextView textname;
//public TextView txtadresse;
}
public View getView(final int position, View convertView, ViewGroup parent) {
View rowView = convertView;
if(rowView==null){
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
rowView= inflater.inflate(groupid, parent, false);
ViewHolder viewHolder = new ViewHolder();
viewHolder.textid = (TextView) rowView.findViewById(R.id.txtid);
rowView.setTag(viewHolder);
}
// Fill data
ViewHolder holder = (ViewHolder) rowView.getTag();
String[] row=items.get(position);
test = row[0].toString();
Spannable pouf = new SpannableString(test);
pouf.setSpan(new ForegroundColorSpan(Color.RED),0,5, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
holder.textid.setText(pouf+" - "+row[1]+"\n"+row[2]);
rowView.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v){
String[] record = items.get(position);
Intent intent=new Intent(context, Main3Activity.class);
intent.putExtra("numéro", record[0]);
intent.putExtra("localite", record[1]);
intent.putExtra("adresse", record[2]);
context.startActivity(intent);
}
});
return rowView;
}
} |
Partager