Jean-Philippe Jodoin
Jean-Philippe Jodoin

Reputation: 4736

How to add elements to an Android ListView programmatically?

I have a ListView with an adapter extending BaseAdapter. I create a view (from a LinearLayout and I put some items ont it depending on some parameters. I have a textview, with a drawable and sometime another textview next to the drawable in this horizontal linearlayout. For some reason, this command doesn't seems to work.

setLayoutParams(new
ListView.LayoutParams(ListView.LayoutParams.FILL_PARENT,
          ListView.LayoutParams.WRAP_CONTENT));

So when my textview doesn't fill the full width of the list, I can only click on the part of the elements with the widget on it. I have try playing a lot with the layout and I can't get this to work. The parameters seems to be ignore all together. Only hack that would work I found was to set a big minimum width on my linearlayout but I don't think that's the best solution.

Upvotes: 0

Views: 2619

Answers (1)

Sebastian Deutsch
Sebastian Deutsch

Reputation: 26

Change everything ListView, LayoutContainer and TextView to FILL_PARENT, that should do the job.

Upvotes: 1

Related Questions