【问题标题】:Add Section in listview在列表视图中添加部分
【发布时间】:2018-01-16 13:26:37
【问题描述】:

我被困在列表视图中添加部分。有人可以给我与在 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;

}

}

和来自片段

    @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);

有人可以帮我把部分放在我的列表视图中吗?

【问题讨论】:

    标签: android listview custom-lists


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-05-14
      • 2012-01-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多