You can supply your own XML including a ListView. From the
documentation of ListFragment:

"ListFragment has a default layout that consists of a single list
view. However, if you desire, you can customize the fragment layout by
returning your own view hierarchy from onCreateView(LayoutInflater,
ViewGroup, Bundle). To do this, your view hierarchy must contain a
ListView object with the id "@android:id/list" (or list if it's in
code)"

This is quite similar to how you do for a ListActivity.

Another option is to skip the ListFragment and use a ListView directly
instead. You only need to use ListFragment if the same list (and
related logic) should be displayed in two different activities.

On 24 Juli, 14:33, vovs <[email protected]> wrote:
> I have some fragment(see below code).
> In this fragment i populate ListView.
> I have Categories and feeds.
> I want to create header to my ListView which will be always on top and
> don't hide when scrolling. This header will show Category name.
> Or how can I add staticview(TextView) and below it add list?
> Can anybody help me?
>
> public class FeedsListForViewFragment extends ListFragment {
>
>     private Context mContext;
>     List<FeedItem> items;
>     private int layoutForList = R.layout.list_feeds_simple;
>     private ActiveRecordBase _db;
>     private Activity mActivity;
>
>     @Override
>     public void onCreate(Bundle savedInstanceState) {
>         super.onCreate(savedInstanceState);
>         mActivity = getActivity();
>         _db =
> ((JtjApplication)getActivity().getApplication()).getDatabase();
>         try {
>             _db.open();
>         } catch (ActiveRecordException e) {
>             e.printStackTrace();
>         }
>
>     }
>
>     public void setItemsToList(List<FeedItem> items, int curPosition)
> {
>         mContext = getActivity().getApplicationContext();
>         this.items = items;
>         ListView lv = getListView();
>         setListAdapter(new ListOfFeedsAdapter(mContext, layoutForList,
> items, mActivity));
>         lv.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
>         lv.setCacheColorHint(Color.WHITE);
>
>         setPosition(curPosition);
>     }
>
>     @Override
>     public void onListItemClick(ListView l, View v, int position, long
> id) {
>         super.onListItemClick(l, v, position, id);
>         if (!(((FeedsActivity) getActivity()).getCurrentPosition() ==
> position)) {
>             updateUnreadItemsInDb(position);
>
>             updateLinksList(position, items.get(position));
>             ((FeedsActivity)
> getActivity()).setCurrentPosition(position);
>         }
>     }
>
>     @SuppressWarnings("unchecked")
>     private void updateUnreadItemsInDb(int position) {
>         FeedItem feed = items.get(position);
>         if (feed.isRead != true) {
>             List<FeedItem> feedsForUpdate = null;
>             List<FeedType> lft = null;
>             try {
>                 feedsForUpdate = _db.find(FeedItem.class, false,
> "GUID=?", new String[] { String.valueOf(feed.guid) }, null, null,
> "PUBLICATIONDATE DESC", null);
>                 lft = _db.findAll(FeedType.class);
>             } catch (ActiveRecordException e1) {
>                 e1.printStackTrace();
>             }
>             for (FeedItem curFeed:feedsForUpdate) {
>                 curFeed.isRead = true;
>                 try {
>                     curFeed.save();
>                     FeedType ft =
> lft.get(Integer.parseInt(curFeed.channel_id) - 1);
>                     ft.unread_count = ft.unread_count - 1;
>                     ft.update();
>                 } catch (ActiveRecordException e) {
>                     e.printStackTrace();
>                 }
>             }
>             items.get(position).isRead = true;
>             ((ArrayAdapter<FeedItem>)
> getListView().getAdapter()).notifyDataSetChanged();
>         }
>     }
>
>     private void setPosition(int position) {
>         ListView lv = getListView();
>         lv.setSelection(position);
>         lv.setItemChecked(position, true);
>         try{
>             updateLinksList(position, items.get(position));
>         } catch (IndexOutOfBoundsException e) {
>             e.printStackTrace();
>         }
>     }
>
>     private void updateLinksList(int position, FeedItem feedItem) {
>         FeedsViewFragment viewFragment = (FeedsViewFragment)
> getFragmentManager().findFragmentById(R.id.feed_view_fragment);
>         viewFragment.setViewItem(feedItem);
>     }
>
>
>
>
>
>
>
> }

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to