在列表视图android中实现section indexer

时间:2016-04-25 06:23:50

标签: android android-arrayadapter

我想在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,然后添加播放器的名称。我希望在添加名称时,然后创建节标题,并将播放器的名称设置在标题下方,就像我附加的图像一样。

1 个答案:

答案 0 :(得分:0)

有很多图书馆可供选择。希望以下链接可以帮助您弄清楚您需要什么。

  1. pinned-section-listview
  2. Example 1
  3. Example 2