こんにちは、クラスを使用して、Android PinnedHeaderListView
のようにヘッダー付きのリスト ビューを取得しようとしています。contacts app
ヘッダーは問題なく表示されますが、連絡先アプリのように、スクロールすると上部にピン留めされません。代わりに、通常の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);
}
}
誰でもこれを修正するのを手伝ってもらえますか? ありがとう!