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