title: add button to only one row in android listView
body: <p>I am trying to add a button in the middle of my listView. Ideally The button will split the listView and it will continue afterward, but if this is not possible I will be ok with a button inside a row in the listView.
  For example. My list view will have line one (image + text) , line two ( image + text) , button, and go on with the list view.</p>
  
  <p>I have wrote the following code. This adds a button to a row in listView, but on the way it also adds an empty button (a button with now text) to every row in my listView. In addition the gravity setting for center is not working.</p>
  
  <p>My xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      android:orientation="horizontal" &gt;
  
       &lt;ImageView android:id="@+id/imgUserIcon"
          android:layout_width="wrap_content"
          android:layout_height="fill_parent"
          android:layout_marginRight="10dp"
          android:layout_marginTop="5dp"
          android:gravity="center_vertical"
          android:scaleType="fitStart" /&gt;
  
       &lt;Button
           android:id="@+id/buttonShowHide"
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:gravity="center"
           android:text="@string/showHide" /&gt;
  
       &lt;TextView android:id="@+id/txtTitle"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_marginLeft="10dp" 
                      android:layout_marginTop="5dp"
              /&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>my adapter</p>
  
  <pre><code>public class UserAdapter extends ArrayAdapter&lt;UserAccountData&gt; {
      Context context;
      int layoutResourceId;
      User data[] = null;
  
      public UserAdapter(Context context, int layoutResourceId,
              UserAccountData[] data) {
          super(context, layoutResourceId, data);
          this.layoutResourceId = layoutResourceId;
          this.context = context;
          this.data = data;
      }
  
      @Override
      public View getView(int position, View convertView, ViewGroup parent) {
          View row = convertView;
          UserAccountDataHolder holder = null;
  
          if (row == null) {
              LayoutInflater inflater = ((Activity) context).getLayoutInflater();
              row = inflater.inflate(layoutResourceId, parent, false);
  
              holder = new UserAccountDataHolder();
              holder.imgIcon = (ImageView) row.findViewById(R.id.imgUserIcon);
              holder.txtTitle = (TextView) row.findViewById(R.id.txtTitle);
              holder.showHide = (Button) row.findViewById(R.id.buttonShowHide);
  
  
              row.setTag(holder);
          } else {
              holder = (UserHolder) row.getTag();
          }
  
          User user = data[position];
          holder.txtTitle.setText(user.title);    
          holder.imgIcon.setImageResource(user.icon);
          holder.showHide.setText(user.buttonName);
          return row;
      }
  
      static class UserHolder {
          ImageView imgIcon;
          TextView txtTitle;
          Button showHide;    
      }
  }
  </code></pre>
  
  <p>My Java object for the row. I have created two constructors one for the button and one for the image and text.</p>
  
  <pre><code>public class UserAccountData {
      public int icon;
      public String type;
      public String title;
      public CharSequence buttonName;
      public UserAccountData(){
          super();
      }
      // for image and text
      public UserAccountData(int icon, String title, String type) {
          super();
          this.icon = icon;
          this.title = title;
          this.type = type;
      }
      // for button
      public UserData(CharSequence buttonName, String type) {
          super();
          this.buttonName = buttonName;
          this.type = type;
      }
  
      public void setType(String type){
          this.type = type;
      }
  }
  </code></pre>
  
  <p>In my activity I am adding the following two rows to the array , that later my adapter will use to create the listView ( I am passing it an ArrayList that being changed into an Array)</p>
  
  <pre><code>user_data.add(new UserAccountData(icon, "title,"type"));
  user_data.add(new UserAccountData("show Password","button"));
  </code></pre>
  
  <p>a) is there a way to split the listView and the middle and just add a button? and continue the same listView? Because my current solution tries to add a button to a row.</p>
  
  <p>b) any ideas why I am actually also adding an empty button to the icon, title type row?
  I am getting icon, title, empty button on my actual listView</p>
  
  <p>Thank you very much</p>
  
  <p>UPDATE:
  Found two blogs
  <a href="http://logc.at/2011/10/10/handling-listviews-with-multiple-row-types/" rel="nofollow">http://logc.at/2011/10/10/handling-listviews-with-multiple-row-types/</a>
  and
  <a href="http://android.amberfog.com/?p=296" rel="nofollow">http://android.amberfog.com/?p=296</a>
  , but still don't have any luck. Would appreciate some more in depth help</p>