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 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
| public class MainListActivity extends ListActivity {
private static final int ITEM_VIEW_TYPE_VIDEO = 0;
private static final int ITEM_VIEW_TYPE_SEPARATOR = 1;
private static final int ITEM_VIEW_TYPE_COUNT = 2;
private static class Video {
public String title;
public String description;
public Video(String title) {
this(title, "ok");
}
public Video(String title, String description) {
this.title = title;
this.description = description;
}
}
private static final Object[] OBJECTS = { "Compte",
new Video("bloquer compte"), new Video("débloquer le compte "),
new Video("changer code de sécurité par sms "),
new Video("Virement par SMS "),
new Video("Annuler Virement par SMS "),
new Video("consulter votre solde "),
"opération fiançiére",
new Video("paipement par sms "), new Video("recharge fix et GSM"),
new Video("chargement"), new Video("Transfer Spécial par SMS"),
"suvie"
};
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.liste);
setListAdapter(new VideoAdapter());
}
private class VideoAdapter extends BaseAdapter {
@Override
public int getCount() {
return OBJECTS.length;
}
@Override
public Object getItem(int position) {
return OBJECTS[position];
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public int getViewTypeCount() {
return ITEM_VIEW_TYPE_COUNT;
}
@Override
public int getItemViewType(int position) {
return (OBJECTS[position] instanceof String) ? ITEM_VIEW_TYPE_SEPARATOR
: ITEM_VIEW_TYPE_VIDEO;
}
@Override
public boolean isEnabled(int position) {
// A separator cannot be clicked !
return getItemViewType(position) != ITEM_VIEW_TYPE_SEPARATOR;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
final int type = getItemViewType(position);
// First, let's create a new convertView if needed. You can also
// create a ViewHolder to speed up changes if you want ;)
if (convertView == null) {
final LayoutInflater inflater = LayoutInflater.from(MainListActivity.this);
final int layoutID = type == ITEM_VIEW_TYPE_SEPARATOR ? R.layout.separator_list_item : R.layout.video_list_item;
convertView = inflater.inflate(layoutID, parent, false);
}
// We can now fill the list item view with the appropriate data.
if (type == ITEM_VIEW_TYPE_SEPARATOR) {
((TextView) convertView).setText((String) getItem(position));
} else {
final Video video = (Video) getItem(position);
((TextView) convertView.findViewById(R.id.title))
.setText(video.title);
((TextView) convertView.findViewById(R.id.description))
.setText(video.description);
}
return convertView;
}
}
} |
Partager