Код: Выделить всё
public class MarkersListActivity extends ListActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
String[] titles = new String[] {"Titre 1", "Titre 2", "Titre 3", "Titre 4"};
String[] des = new String[] {"des 1", "des 2", "des 3", "des 4"};
setListAdapter( new MarkerListArrayAdapter(this, titles, des));
}
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
//get selected items
String selectedValue = (String) getListAdapter().getItem(position);
Toast.makeText(this, selectedValue, Toast.LENGTH_SHORT).show();
}
}
Код: Выделить всё
public class MarkerListArrayAdapter extends ArrayAdapter {
private final Context context;
private final String[] titleText;
private final String[] descriptionText;
public MarkerListArrayAdapter(Context context, String[] titles, String[] description) {
super(context, R.layout.marker_list_layout, titles);
this.context = context;
this.titleText = titles;
this.descriptionText = description;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View rowView = inflater.inflate(R.layout.marker_list_layout, parent, false);
TextView title = (TextView) rowView.findViewById(R.id.title);
TextView description = (TextView) rowView.findViewById(R.id.description);
ImageView imageView = (ImageView) rowView.findViewById(R.id.image);
title.setText(titleText[position]);
description.setText(descriptionText[position]);
imageView.setBackgroundColor(Color.argb(255,255,0,0));
return rowView;
}
}
Код: Выделить всё
Подробнее здесь: https://stackoverflow.com/questions/154 ... stactivity