android.widget.ListView.addHeaderView()方法的使用及代码示例

x33g5p2x  于2022-01-23 转载在 其他  
字(7.3k)|赞(0)|评价(0)|浏览(293)

本文整理了Java中android.widget.ListView.addHeaderView()方法的一些代码示例,展示了ListView.addHeaderView()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ListView.addHeaderView()方法的具体详情如下:
包路径:android.widget.ListView
类名称:ListView
方法名:addHeaderView

ListView.addHeaderView介绍

暂无

代码示例

代码示例来源:origin: stackoverflow.com

ListView lv = getListView();
LayoutInflater inflater = getLayoutInflater();
View header = inflater.inflate(R.layout.header, lv, false);
lv.addHeaderView(header, null, false);

代码示例来源:origin: sunfusheng/StickyHeaderListView

@Override
protected void getView(String s, ListView listView) {
  View view = mInflate.inflate(R.layout.header_divider_layout, listView, false);
  listView.addHeaderView(view);
}

代码示例来源:origin: orhanobut/dialogplus

@Override public void addHeader(@NonNull View view, boolean fixed) {
 if (fixed) {
  headerContainer.addView(view);
 } else {
  listView.addHeaderView(view);
 }
 headerView = view;
}

代码示例来源:origin: sunfusheng/StickyHeaderListView

@Override
protected void getView(Object obj, ListView listView) {
  View view = mInflate.inflate(R.layout.header_filter_layout, listView, false);
  ButterKnife.bind(this, view);
  listView.addHeaderView(view);
}

代码示例来源:origin: stackoverflow.com

View header = getLayoutInflater().inflate(R.layout.header, null); 
View footer = getLayoutInflater().inflate(R.layout.footer, null); 

ListView listView = getListView();  

listView.addHeaderView(header); 
listView.addFooterView(footer);     

setListAdapter(new ArrayAdapter<String(this,android.R.layout.simple_list_item_single_choice,android.R.id.text1, names));

代码示例来源:origin: sunfusheng/StickyHeaderListView

@Override
protected void getView(List<String> list, ListView listView) {
  View view = mInflate.inflate(R.layout.header_banner_layout, listView, false);
  ButterKnife.bind(this, view);
  dealWithTheView(list);
  listView.addHeaderView(view);
}

代码示例来源:origin: sunfusheng/StickyHeaderListView

@Override
protected void getView(List<ChannelEntity> list, ListView listView) {
  View view = mInflate.inflate(R.layout.header_channel_layout, listView, false);
  ButterKnife.bind(this, view);
  dealWithTheView(list);
  listView.addHeaderView(view);
}

代码示例来源:origin: sunfusheng/StickyHeaderListView

@Override
protected void getView(List<OperationEntity> list, ListView listView) {
  View view = mInflate.inflate(R.layout.header_operation_layout, listView, false);
  ButterKnife.bind(this, view);
  dealWithTheView(list);
  listView.addHeaderView(view);
}

代码示例来源:origin: joyoyao/superCleanMaster

protected void createFakeHeader() {
  mFakeHeader = new View(mContext);
  mFakeHeader.setVisibility(View.INVISIBLE);
  AbsListView.LayoutParams lp = new AbsListView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 0);
  mFakeHeader.setLayoutParams(lp);
  mListView.addHeaderView(mFakeHeader);
}

代码示例来源:origin: facebook/facebook-android-sdk

@Override
void setupViews(ViewGroup view) {
  if (showSearchBox) {
    ListView listView = (ListView) view.findViewById(R.id.com_facebook_picker_list_view);
    View searchHeaderView = getActivity().getLayoutInflater().inflate(
        R.layout.picker_search_box, listView, false);
    listView.addHeaderView(searchHeaderView, null, false);
    searchBox = (EditText) view.findViewById(R.id.com_facebook_picker_search_text);
    searchBox.addTextChangedListener(new SearchTextWatcher());
    if (!TextUtils.isEmpty(searchText)) {
      searchBox.setText(searchText);
    }
  }
}

代码示例来源:origin: stackoverflow.com

View padding = new View(this);
padding.setHeight(20); // Can only specify in pixels unfortunately. No DIP :-(

ListView myListView = (ListView) findViewById(R.id.my_list_view);

myListView.addHeaderView(padding);
myListView.addFooterView(padding);

myListView.setAdapter(myAdapter);

代码示例来源:origin: beworker/pinned-section-listview

private void initializeHeaderAndFooter() {
  setListAdapter(null);
  if (hasHeaderAndFooter) {
    ListView list = getListView();
    LayoutInflater inflater = LayoutInflater.from(this);
    TextView header1 = (TextView) inflater.inflate(android.R.layout.simple_list_item_1, list, false);
    header1.setText("First header");
    list.addHeaderView(header1);
    TextView header2 = (TextView) inflater.inflate(android.R.layout.simple_list_item_1, list, false);
    header2.setText("Second header");
    list.addHeaderView(header2);
    TextView footer = (TextView) inflater.inflate(android.R.layout.simple_list_item_1, list, false);
    footer.setText("Single footer");
    list.addFooterView(footer);
  }
  initializeAdapter();
}

代码示例来源:origin: bingoogolapple/BGABanner-Android

/**
 * 初始化ListView
 */
private void initListView() {
  // 初始化HeaderView
  View headerView = View.inflate(this, R.layout.layout_header, null);
  mBanner = headerView.findViewById(R.id.banner);
  mBanner.setAdapter(this);
  mBanner.setDelegate(this);
  // 初始化ListView
  mContentLv.addHeaderView(headerView);
  mContentAdapter = new ContentAdapter(this);
  mContentLv.setAdapter(mContentAdapter);
}

代码示例来源:origin: ksoichiro/Android-ObservableScrollView

public static void setDummyDataWithHeader(Context context, ListView listView, View headerView) {
  listView.addHeaderView(headerView);
  setDummyData(context, listView);
}

代码示例来源:origin: commonsguy/cw-omnibus

@Override
public void onCreate(Bundle state) {
 super.onCreate(state);
 setContentView(R.layout.main);
 getListView().addHeaderView(buildHeader());
 getListView().addFooterView(buildFooter());
 setListAdapter(new ArrayAdapter<String>(this,
           android.R.layout.simple_list_item_1,
           items));
}

代码示例来源:origin: stackoverflow.com

drawerList = (ListView) findViewById(R.id.left_drawer);
View header = getLayoutInflater().inflate(R.layout.drawer_list_header, null);
drawerList.addHeaderView(header, null, false);
drawerList.setAdapter(new ArrayAdapter<String>(this, R.layout.drawer_list_item, android.R.id.text1,
    layers));

代码示例来源:origin: robolectric/robolectric

@Test
public void addHeaderView_shouldAttachTheViewToTheList() throws Exception {
 View view = new View(context);
 view.setId(42);
 listView.addHeaderView(view);
 assertThat((View) listView.findViewById(42)).isSameAs(view);
}

代码示例来源:origin: robolectric/robolectric

@Test
public void testGetFooterViewsCount() throws Exception {
 listView.addHeaderView(new View(context));
 listView.addFooterView(new View(context));
 listView.addFooterView(new View(context));
 prepareListWithThreeItems();
 assertThat(listView.getFooterViewsCount()).isEqualTo(2);
}

代码示例来源:origin: robolectric/robolectric

@Test
public void setAdapter_shouldNotClearHeaderOrFooterViews() throws Exception {
 View header = new View(context);
 listView.addHeaderView(header);
 View footer = new View(context);
 listView.addFooterView(footer);
 prepareListWithThreeItems();
 assertThat(listView.getChildCount()).isEqualTo(5);
 assertThat(listView.getChildAt(0)).isSameAs(header);
 assertThat(listView.getChildAt(4)).isSameAs(footer);
}

代码示例来源:origin: robolectric/robolectric

@Test
public void addHeaderView_ShouldRecordHeaders() throws Exception {
 View view0 = new View(context);
 view0.setId(0);
 View view1 = new View(context);
 view1.setId(1);
 View view2 = new View(context);
 view2.setId(2);
 View view3 = new View(context);
 view3.setId(3);
 listView.addHeaderView(view0);
 listView.addHeaderView(view1);
 listView.addHeaderView(view2, null, false);
 listView.addHeaderView(view3, null, false);
 listView.setAdapter(new ShadowCountingAdapter(2));
 assertThat(listView.getHeaderViewsCount()).isEqualTo(4);
 assertThat(shadowOf(listView).getHeaderViews().get(0)).isSameAs(view0);
 assertThat(shadowOf(listView).getHeaderViews().get(1)).isSameAs(view1);
 assertThat(shadowOf(listView).getHeaderViews().get(2)).isSameAs(view2);
 assertThat(shadowOf(listView).getHeaderViews().get(3)).isSameAs(view3);
 assertThat((View) listView.findViewById(0)).isNotNull();
 assertThat((View) listView.findViewById(1)).isNotNull();
 assertThat((View) listView.findViewById(2)).isNotNull();
 assertThat((View) listView.findViewById(3)).isNotNull();
}

相关文章

ListView类方法