.
TwoLineListItem .
, :
public class ProfileItem {
public String host, name, tag;
public ProfileItem(String host, String name, String tag) {
this.host = host;
this.name = name;
this.tag = tag;
}
@Override
public String toString() {
return name+"#"+tag;
}
}
:
public class ProfileItemAdapter extends ArrayAdapter<ProfileItem> {
private Context context;
private int layoutResourceId;
private List<ProfileItem> objects = null;
public ProfileItemAdapter(Context context, int layoutResourceId, List<ProfileItem> objects) {
super(context, layoutResourceId, objects);
this.context = context;
this.layoutResourceId = layoutResourceId;
this.objects = objects;
}
public View getView(int position, View convertView, ViewGroup parent) {
View v = convertView;
if(v == null)
{
LayoutInflater inflater = ((Activity)context).getLayoutInflater();
v = inflater.inflate(layoutResourceId, parent, false);
}
ProfileItem item = objects.get(position);
TextView titletext = (TextView)v.findViewById(android.R.id.text1);
titletext.setText(item.toString());
TextView mainsmalltext = (TextView)v.findViewById(android.R.id.text2);
mainsmalltext.setText(item.host);
return v;
}
}
, ( ), onCreate:
setListAdapter(new ProfileItemAdapter(getActivity(),
android.R.layout.two_line_list_item, // or my own custom layout
ProfileListContent.ITEMS));