我想在android的列表视图中添加节标题,如附加图像。有人可以帮我处理代码。我不想像在联系人中那样实现侧面索引器。image
这是我创建的custim列表适配器 -
public class CustomListAdapter extends BaseAdapter {
private Activity mContext;
private List<String> mList;
private LayoutInflater mLayoutInflater = null;
public CustomListAdapter(Activity context, List<String> list){
mContext = context;
mList = list;
mLayoutInflater = (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
@Override
public int getCount() {
return mList.size();
}
@Override
public Object getItem(int pos) {
return mList.get(pos);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getDropDownView(int position, View convertView, ViewGroup parent) {
return super.getDropDownView(position, convertView, parent);
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
final ListViewHolder viewHolder;
if (convertView == null) {
LayoutInflater layoutInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = layoutInflater.inflate(R.layout.players_name_with_options, parent, false);
viewHolder = new ListViewHolder(convertView);
convertView.setTag(viewHolder);
} else {
viewHolder = (ListViewHolder) convertView.getTag();
}
// Setting the name of the player on the text view
viewHolder.textView.setText(mList.get(position));
return convertView;
}
// Class that contains the views as the variables
private class ListViewHolder {
TextView textView;
// Constructor of the class
public ListViewHolder(View item) {
// Initialising the text view and the spinner
textView = (TextView) item.findViewById(R.id.list_textView);
}
}
}
我正在初始化此ArrayAdapter
,然后添加播放器的名称。我希望在添加名称时,然后创建节标题,并将播放器的名称设置在标题下方,就像我附加的图像一样。