嗨,我正在尝试使用PinnedHeaderListView
该类来获取带有标题的列表视图,就像contacts app
在 Android 中一样。
标题显示正常,但是,滚动时它们不会固定到顶部,就像在联系人应用程序中一样。listview
相反,它们只是像普通物品一样滚动过去。
我怎样才能解决这个问题?
这是我的片段和适配器类的片段:
public class StaffSectionFragment extends ListFragment implements
ActionBar.TabListener {
private ListFragment mFragment;
private StaffListAdapter adapter;
private ArrayList<Staff> staffList;
public StaffSectionFragment() {
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Get the view from fragment_courses.xml
getActivity().setContentView(R.layout.fragment_staff);
adapter = new StaffListAdapter();
LayoutInflater inflator = (LayoutInflater) getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
RelativeLayout layout = (RelativeLayout) inflator.inflate(R.layout.fragment_staff, null);
PinnedHeaderListView listview =(PinnedHeaderListView) layout.findViewById(R.id.pinnedListView);
setListAdapter(adapter);
listview.setAdapter(adapter);
}
private void setupListView()
{
}
public class StaffListAdapter extends SectionedBaseAdapter {
@Override
public Object getItem(int section, int position) {
// TODO Auto-generated method stub
return null;
}
@Override
public long getItemId(int section, int position) {
// TODO Auto-generated method stub
return 0;
}
@Override
public int getSectionCount() {
//*************DO THIS*****************
// TODO Auto-generated method stub
return 2;
}
@Override
public int getCountForSection(int section) {
//*************DO THIS*****************
// TODO Auto-generated method stub
return 20;
}
@Override
public View getItemView(int section, int position, View convertView,
ViewGroup parent) {
// TODO Auto-generated method stub
LinearLayout layout = null;
if(convertView == null)
{
LayoutInflater inflator = (LayoutInflater) parent.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
layout = (LinearLayout) inflator.inflate(R.layout.list_item, null);
}
else
{
layout = (LinearLayout)convertView;
}
//set item
((TextView) layout.findViewById(R.id.listtextItem)).setText("Section " + section + " item " + position);
return layout;
}
@Override
public View getSectionHeaderView(int section, View convertView,
ViewGroup parent) {
LinearLayout layout = null;
if(convertView == null)
{
LayoutInflater inflator = (LayoutInflater) parent.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
layout = (LinearLayout) inflator.inflate(R.layout.header_item, null);
}
else
{
layout = (LinearLayout)convertView;
}
//set item
((TextView) layout.findViewById(R.id.headertextItem)).setText("Header for section " + section);
return layout;
}
}
@Override
public void onListItemClick(ListView l, View v, int position, long id) {
// Do something with the data
}
@Override
public void onTabReselected(Tab arg0, FragmentTransaction arg1) {
// TODO Auto-generated method stub
}
@Override
public void onTabSelected(Tab arg0, FragmentTransaction ft) {
// TODO Auto-generated method stub
mFragment = new StaffSectionFragment();
// Attach fragment_courses.xml layout
ft.add(android.R.id.content, mFragment);
ft.attach(mFragment);
}
@Override
public void onTabUnselected(Tab arg0, FragmentTransaction ft) {
// TODO Auto-generated method stub
// Remove fragment_courses.xml layout
ft.remove(mFragment);
}
}
谁能帮我解决这个问题?谢谢!