カスタム行レイアウト(custom_row.xmlなど)を作成し、アクティビティの通常のレイアウトと同じように、必要なビューを配置します(したがって、この場合、テキストのテキストビューと、おそらく左側のアイコンを提供します。それの)。
次に、既存のアダプターを拡張してカスタムアダプターを作成し、getViewメソッドをそのようにオーバーライドします。タイトルとサブタイトルの両方でレイアウトcustom_rowを使用する例を次に示します。
class CustomAdapter<T> extends ArrayAdapter<T> {
/** List item title */
protected TextView mTitle;
/** List item subtitle */
protected TextView mSubtitle;
/**
* @param context
* Current context
* @param items
* Items being added to the adapter
*/
public CustomAdapter(final Context context, final List<T> items) {
super(context, R.layout.custom_row, items);
}
/** Construct row */
@Override
public View getView(final int position, final View convertView, final ViewGroup parent) {
View view = convertView;
if (view == null) {
final LayoutInflater li = (LayoutInflater) getContext().getSystemService(
Context.LAYOUT_INFLATER_SERVICE);
view = li.inflate(R.layout.custom_row, null);
}
mTitle = (TextView) view.findViewById(R.id.custom_row_title);
mSubtitle = (TextView) view.findViewById(R.id.custom_row_subtitle);
return view;
}
}
示されているように、インフレータサービスを介して作成したcustom_rowレイアウトで指定されたアイテムを取得できます。次に、必要に応じてオブジェクトを操作できます。