Search code examples
androidlistviewlayoutandroid-arrayadapterinflate

How do I programmatically add a button into the inflated layout from an adapter?


Im using an inflater inside an adapter for my listview. I need to add in a different button depending in the state of the data for each row, so Im thinking I need to do this programmatically, but how do I make sure its inserted into the correct place inside the layout?


Solution

  • Have two view files for each scenario. You will overkill yourself with the problem to add views at the desired place by code.

    Or have one view that holds the button, and set visibility to GONE to dismiss when you don't needed.

    ((TextView) inflatedview.findViewById(R.id.custombut)).setVisibility(View.GONE);