TBridges42
TBridges42

Reputation: 1879

ListView with mixed sources

Is it possible to have a ListView that draws from multiple sources? I want to have some hard-coded items and items from a ContentProvider in the same list, and I just want to know if that's possible.

Upvotes: 0

Views: 36

Answers (3)

TBridges42
TBridges42

Reputation: 1879

So, I realized that

  • I don't care if ContentProvider data is updated after the fragment loads and
  • I want to do manipulations on the data in my list that I do not want reflected in the ContentProvider.

So I'm going to dump my cursor results into an ArrayList along with my hardcoded items, and I think that should work fine.

Upvotes: 0

Jacob Phillips
Jacob Phillips

Reputation: 9274

You could have both types of items implement an interface such as

public interface Item {
    int TYPE_1 = 1;
    int TYPE_2 = 2;
    int getViewType();
    View getView(LayoutInflater inflater, View convertView, ViewGroup parent);
}

Then your Adapter can be for a list of Items. Also, if you're unfamiliar with the View Holder pattern I'd recommend looking it up. A quick search revealed a pretty good looking example here

Upvotes: 1

xiejiuwei
xiejiuwei

Reputation: 311

You can let them extends a common parent class, and then use it to construct the adapter. I have done this before, I hope to help you.

Upvotes: 0

Related Questions