List of usage examples for android.widget ListView addHeaderView
public void addHeaderView(View v)
From source file:at.bitfire.davdroid.syncadapter.SelectCollectionsFragment.java
@Override public void onViewCreated(View view, Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); final ListView listView = getListView(); listView.setPadding(20, 30, 20, 30); View header = getActivity().getLayoutInflater().inflate(R.layout.select_collections_header, null); listView.addHeaderView(header); final ServerInfo serverInfo = (ServerInfo) getArguments().getSerializable(KEY_SERVER_INFO); final SelectCollectionsAdapter adapter = new SelectCollectionsAdapter(serverInfo); setListAdapter(adapter);//from ww w . j a v a 2 s. c om listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE); listView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { int itemPosition = position - 1; // one list header view at pos. 0 if (adapter.getItemViewType(itemPosition) == SelectCollectionsAdapter.TYPE_ADDRESS_BOOKS_ROW) { // unselect all other address books for (int pos = 1; pos <= adapter.getNAddressBooks(); pos++) if (pos != itemPosition) listView.setItemChecked(pos + 1, false); } getActivity().supportInvalidateOptionsMenu(); } }); }
From source file:nl.basvanmarwijk.mylocations.viewcontroller.LocationItemListFragment.java
@SuppressLint("InflateParams") @Override//from w ww.ja va 2 s .com public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); //TODO other constructor flag adapter = new LocationItemCursorAdapter(App.getAppContext(), App.getDbManager().getAllColumnsCursor(), CursorAdapter.FLAG_AUTO_REQUERY); final View btn_add = getActivity().getLayoutInflater().inflate(R.layout.add_button, null); final ListView lv = getListView(); lv.addHeaderView(btn_add); btn_add.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { LocationBridge lb = new LocationBridge(getActivity().getApplicationContext()); final String TAG = ((Object) this).getClass().getName(); Log.i(TAG, "start locatie zoeken"); Location locatie = null; try { locatie = lb.getLastLocation(); } catch (LocationException e) { Log.w(TAG, e.getMessage()); } finally { lb.close(); } if (locatie != null) { Toast.makeText(getActivity(), R.string.location_found, Toast.LENGTH_SHORT).show(); toggleProgressBar(true); PlaceDownloaderTask downloader = new PlaceDownloaderTask(new PlaceDownloaderListener()); downloader.execute(locatie); } else { Toast.makeText(getActivity(), R.string.location_not_available, Toast.LENGTH_LONG).show(); } } }); setListAdapter(adapter); }
From source file:org.mercycorps.translationcards.activity.translations.TranslationsActivity.java
private void initList() { ListView list = (ListView) findViewById(R.id.translations_list); LayoutInflater layoutInflater = getLayoutInflater(); list.addHeaderView(layoutInflater.inflate(R.layout.translation_list_header, list, false)); findViewById(R.id.translation_list_header).setOnClickListener(null); inflateListFooter();// w ww.java2s. co m listAdapter = new CardListAdapter(this, this, R.layout.translation_item, R.id.origin_translation_text, new ArrayList<Translation>(), translationService, dictionaryService, deckService); list.setAdapter(listAdapter); }
From source file:com.money.manager.ex.budget.BudgetDetailFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout for this fragment // return inflater.inflate(R.layout.fragment_budget_detail, container, false); View view = super.onCreateView(inflater, container, savedInstanceState); ListView list = (ListView) view.findViewById(android.R.id.list); // Add the column header. View header = View.inflate(getActivity(), R.layout.item_budget_header, null); list.addHeaderView(header); // Header has to be added before the adapter is set on the list. setUpAdapter();/* w w w.jav a2 s. c o m*/ return view; }
From source file:pl.reticular.ttw.HighScoresActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //Log.i(getClass().getName(), "onCreate"); setContentView(R.layout.layout_high_scores); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar_high_scores); setSupportActionBar(toolbar);/*from ww w .ja v a 2 s . c o m*/ ActionBar actionBar = getSupportActionBar(); if (actionBar != null) { actionBar.setDisplayHomeAsUpEnabled(true); } ListView listView = (ListView) findViewById(R.id.list_high_scores); TextView noGames = (TextView) findViewById(R.id.text_no_games); listView.setEmptyView(noGames); listView.addHeaderView(createHeader(listView)); adapter = new HighScoresCursorAdapter(this, null, 0); listView.setAdapter(adapter); dbHelper = new DBHelper(this); }
From source file:com.ekuater.labelchat.ui.fragment.userInfo.HeaderFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { final Activity activity = getActivity(); assert activity != null; mFrameLayout = new FrameLayout(activity); mCover = onCoverView(inflater, mFrameLayout); mHeader = onCreateHeaderView(inflater, mFrameLayout); mHeaderHeader = mHeader.findViewById(android.R.id.title); mHeaderBackground = mHeader.findViewById(android.R.id.background); assert mHeader.getLayoutParams() != null; mHeaderHeight = mHeader.getLayoutParams().height; mFakeHeader = new Space(activity); mFakeHeader.setLayoutParams(new ListView.LayoutParams(0, mHeaderHeight)); View content = onCreateContentView(inflater, mFrameLayout); if (content instanceof RelativeLayout) { isListViewEmpty = true;/*from w ww . ja va 2 s . c o m*/ final ListView listView = (ListView) content.findViewById(R.id.list); listView.addHeaderView(mFakeHeader); listView.setOnScrollListener(new AbsListView.OnScrollListener() { @Override public void onScrollStateChanged(AbsListView absListView, int scrollState) { if (mOnScrollListener != null) { mOnScrollListener.onScrollStateChanged(absListView, scrollState); } } @Override public void onScroll(AbsListView absListView, int firstVisibleItem, int visibleItemCount, int totalItemCount) { if (mOnScrollListener != null) { mOnScrollListener.onScroll(absListView, firstVisibleItem, visibleItemCount, totalItemCount); } if (isListViewEmpty) { scrollHeaderTo(0); } else { final View child = absListView.getChildAt(0); assert child != null; scrollHeaderTo(child == mFakeHeader ? child.getTop() : -mHeaderHeight); } } }); } else { // Merge fake header view and content view. final LinearLayout view = new LinearLayout(activity); view.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); view.setOrientation(LinearLayout.VERTICAL); view.addView(mFakeHeader); view.addView(content); // Put merged content to ScrollView final NotifyingScrollView scrollView = new NotifyingScrollView(activity); scrollView.addView(view); scrollView.setOnScrollChangedListener(new NotifyingScrollView.OnScrollChangedListener() { @Override public void onScrollChanged(ScrollView who, int l, int t, int oldl, int oldt) { scrollHeaderTo(-t); } }); content = scrollView; } mFrameLayout.addView(content); mFrameLayout.addView(mHeader); if (mCover != null) { mFrameLayout.addView(mCover); } // Post initial scroll mFrameLayout.post(new Runnable() { @Override public void run() { scrollHeaderTo(0, true); } }); return mFrameLayout; }
From source file:org.eyeseetea.malariacare.fragments.PlannedPerOrgUnitFragment.java
/** * Initializes the listview component, adding a listener for swiping right *///from www . j a v a 2s.co m private void initListView() { LayoutInflater inflater = LayoutInflater .from(PreferencesState.getInstance().getContext().getApplicationContext()); View header = inflater.inflate(this.adapter.getHeaderLayout(), null, false); ListView listView = getListView(); listView.setBackgroundColor(getResources().getColor(R.color.feedbackDarkBlue)); if (listView.getHeaderViewsCount() == 0) listView.addHeaderView(header); setListAdapter((BaseAdapter) adapter); Session.listViewSent = listView; }
From source file:vit.collegecode.mediadb.fragments.HeaderFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { final Activity activity = getActivity(); assert activity != null; mFrameLayout = new FrameLayout(activity); mHeader = onCreateHeaderView(inflater, mFrameLayout); mHeaderHeader = mHeader.findViewById(android.R.id.title); mHeaderBackground = mHeader.findViewById(android.R.id.background); assert mHeader.getLayoutParams() != null; mHeaderHeight = mHeader.getLayoutParams().height; mFakeHeader = new Space(activity); mFakeHeader.setLayoutParams(new ListView.LayoutParams(0, mHeaderHeight)); View content = onCreateContentView(inflater, mFrameLayout); if (content instanceof ListView) { isListViewEmpty = true;//from www . j a v a2 s. co m final ListView listView = (ListView) content; listView.addHeaderView(mFakeHeader); listView.setOnScrollListener(new AbsListView.OnScrollListener() { @Override public void onScrollStateChanged(AbsListView absListView, int scrollState) { if (mOnScrollListener != null) { mOnScrollListener.onScrollStateChanged(absListView, scrollState); } } @Override public void onScroll(AbsListView absListView, int firstVisibleItem, int visibleItemCount, int totalItemCount) { if (isListViewEmpty) { scrollHeaderTo(0); } else { final View child = absListView.getChildAt(0); assert child != null; scrollHeaderTo(child == mFakeHeader ? child.getTop() : -mHeaderHeight); } } }); } else { // Merge fake header view and content view. final LinearLayout view = new LinearLayout(activity); view.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); view.setOrientation(LinearLayout.VERTICAL); view.addView(mFakeHeader); view.addView(content); // Put merged content to ScrollView final NotifyingScrollView scrollView = new NotifyingScrollView(activity); scrollView.addView(view); scrollView.setOnScrollChangedListener(new NotifyingScrollView.OnScrollChangedListener() { @Override public void onScrollChanged(ScrollView who, int l, int t, int oldl, int oldt) { scrollHeaderTo(-t); } }); content = scrollView; } mFrameLayout.addView(content); mFrameLayout.addView(mHeader); // Content overlay view always shows at the top of content. if ((mContentOverlay = onCreateContentOverlayView(inflater, mFrameLayout)) != null) { mFrameLayout.addView(mContentOverlay, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); } // Post initial scroll mFrameLayout.post(new Runnable() { @Override public void run() { scrollHeaderTo(0, true); } }); Animation anim = AnimationUtils.loadAnimation(getActivity(), R.anim.slide_in_bottom); mFrameLayout.startAnimation(anim); return mFrameLayout; }
From source file:com.maxleap.mall.fragments.MainFragment.java
private void initListView(View view) { mSwipeRefreshLayout = (SwipeRefreshLayout) view.findViewById(R.id.refresh_layout); mSwipeRefreshLayout.setColorSchemeResources(R.color.orange, R.color.green, R.color.blue); mSwipeRefreshLayout.setOnRefreshListener(this); ListView listview = (ListView) view.findViewById(R.id.frag_main_list_view); listview.addHeaderView(getHeadView()); listview.addFooterView(LayoutInflater.from(getActivity()).inflate(R.layout.view_footer, null)); if (mProducts == null) { mProducts = new ArrayList<>(); mComments = new ArrayList<>(); mHandler.postDelayed(mProgressRunnable, 100); }/* w w w . jav a 2 s .c o m*/ if (mProducts.isEmpty()) { fetchProductData(); } mProductAdapter = new ProductAdapter(mContext, mProducts, mComments); listview.setAdapter(mProductAdapter); listview.setOnItemClickListener(this); }
From source file:com.app4am.app4am.MainTopicListFragment.java
@Override public void onViewCreated(View view, Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); if (savedInstanceState != null) { mPosition = savedInstanceState.getInt(SwipeRefreshFragmentInterface.FRAGMENT_POSITION); }/*ww w . j a v a 2s. c o m*/ // Change the colors displayed by the SwipeRefreshLayout by providing it with 4 // color resource ids setColorSchemeResources(R.color.color_scheme_1_1, R.color.color_scheme_1_2, R.color.color_scheme_1_3, R.color.color_scheme_1_4); // Set list view background color. view.setBackgroundResource(R.color.color_common_list_background); // Attach topic banner. The banner is dynamically loaded from the server. // TODO: Real image source url. ListView listView = getListView(); listView.addHeaderView(mHeaderView); ImageView imageViewTopicBanner = (ImageView) mHeaderView.findViewById(R.id.iv_topic_banner); int cornerRadiusInPx = getResources() .getDimensionPixelSize(R.dimen.topic_list_item_background_corner_radius); DisplayImageOptions options = new DisplayImageOptions.Builder() .displayer(new RoundedBitmapDisplayer(cornerRadiusInPx)) //rounded corner bitmap .cacheInMemory(true).build(); ImageLoader imageLoader = ImageLoader.getInstance(); imageLoader.displayImage("assets://todo_topic_banner_1.png", imageViewTopicBanner, options); // List item divider and background color listView.setDivider(getResources().getDrawable(R.drawable.common_list_divider)); listView.setDividerHeight((int) getResources().getDimension(R.dimen.common_list_divider_height)); listView.setBackgroundResource(R.color.color_common_list_background); listView.setCacheColorHint(0); // List selector listView.setSelector(R.drawable.list_view_selector); listView.setDrawSelectorOnTop(true); // Event handler listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { // TODO: Open topic information page (B01). Log.d(LOG_TAG, "on click"); } }); listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) { // Open topic introduction page (B02). onOpenTopicIntroduction(); return true; } }); /** * Create an ArrayAdapter to contain the data for the ListView. Each item in the ListView * uses the system-defined simple_list_item_1 layout that contains one TextView. */ ListAdapter adapter = new ArrayAdapter<String>(getActivity(), R.layout.topic_list_item, R.id.textView, Cheeses.randomList(LIST_ITEM_COUNT)); // Set the adapter between the ListView and its backing data. setListAdapter(adapter); // BEGIN_INCLUDE (setup_refreshlistener) /** * Implement {@link android.support.v4.widget.SwipeRefreshLayout.OnRefreshListener}. When users do the "swipe to * refresh" gesture, SwipeRefreshLayout invokes * {@link android.support.v4.widget.SwipeRefreshLayout.OnRefreshListener#onRefresh onRefresh()}. In * {@link android.support.v4.widget.SwipeRefreshLayout.OnRefreshListener#onRefresh onRefresh()}, call a method that * refreshes the content. Call the same method in response to the Refresh action from the * action bar. */ setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { @Override public void onRefresh() { Log.i(LOG_TAG, "onRefresh called from SwipeRefreshLayout"); initiateRefresh(); } }); // END_INCLUDE (setup_refreshlistener) }