在listview中添加部分

时间:2018-01-16 13:26:38

标签: android listview custom-lists

我坚持在列表视图中添加部分。有人可以给我提示或链接相关的添加部分在mylistview中。注意我已被搜索并找到模块 - here模块 - 但不知何故模块不兼容或与我现有的模块不匹配。看我的代码。

你可以看到我的类是扩展ArrayAdapter,而不是baseadapter。我该怎么做才能自定义代码?

public class CustomArrayAdapter extends ArrayAdapter<Item> {

ArrayList<Item> profileList = new ArrayList<>();

public CustomArrayAdapter(Context context, int textViewResourceId, ArrayList<Item> objects) {
    super(context, textViewResourceId, objects);
    profileList = objects;
}

@Override
public int getCount() {
    return super.getCount();
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {

    View v = convertView;
    LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    v = inflater.inflate(R.layout.list_view_items, null);
    TextView textView = (TextView) v.findViewById(R.id.textView);
    ImageView imageView = (ImageView) v.findViewById(R.id.imageView);
    System.out.println(position);
    textView.setText(profileList.get(position).getProfileItem());
    imageView.setImageResource(profileList.get(position).getProfileImage());
    return v;

}

}

和Fragment

    @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    View view = inflater.inflate(R.layout.fragment_profile, container, false);
    //List View for profile user
    ListView listView = (ListView) view.findViewById(R.id.listProfile);
    proflieList.add(new Item("Profile", R.drawable.ic_person_black_24dp));
    proflieList.add(new Item("Housing", R.drawable.ic_hotel_black_24dp));
    //proflieList.add(new Item("Bantuan", R.drawable.ic_action_tv));
    //proflieList.add(new Item("Versi aplikasi", R.drawable.ic_action_tv));
    sAdapter = new SectionAdapter(getActivity());
    sAdapter.addSectionHeaderItem("Section");

    CustomArrayAdapter myadapter = new CustomArrayAdapter(getActivity(), R.layout.list_view_items, proflieList);
    listView.setAdapter(myadapter);

有人可以提供帮助,以便我可以在我的列表视图中添加部分吗?

1 个答案:

答案 0 :(得分:0)

我不知道你要在这里拉什么,但你可以使用这个lib: https://github.com/beworker/pinned-section-listview