title: How to get values from dynamically created LinearLayout in android
body: <p>I'm new to android. Started learning recently.</p>
  
  <p>I have created a LinearLayout dynamically. I have the following fields in LinearLayout:
  1. Customer name
  2. Edit Button
  3. Delete Button.</p>
  
  <p>Orientation is horizontal.</p>
  
  <p>Now I want to delete a single record when I click on delete button. How can I get row id in this case and later I can pass to database to delete the record. Here is the code.</p>
  
  <pre><code>user_list_view_item_row.xml
  
  &lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:orientation="horizontal"
     android:layout_width="fill_parent"
     android:layout_height="fill_parent"
     android:background="@drawable/bg_main"
     &gt;
  
  
      &lt;TextView android:id="@+id/txtTitle"
          android:layout_width="wrap_content"
          android:layout_height="fill_parent"
          android:gravity="center_vertical"
          android:textStyle="bold"
          android:textSize="50dp"
          android:textColor="#FFFFFF"
          android:layout_marginTop="5dp"
          android:layout_marginBottom="5dp" /&gt;
  
  
          &lt;Button
              android:id="@+id/userListEditButton"
              style="@style/SpecialText"
              android:layout_width="50dp"
              android:layout_height="50dp"  
              android:typeface="monospace"          
              android:text="@string/save" 
              android:layout_marginTop="5dp"
              android:layout_marginBottom="5dp" /&gt;
  
          &lt;Button
              android:id="@+id/userListDeleteButton"
              style="@style/SpecialText"
              android:layout_width="50dp"
              android:layout_height="50dp"  
              android:typeface="monospace"          
              android:text="@string/reset" 
              android:layout_marginTop="5dp"
              android:layout_marginBottom="5dp" /&gt;
      &lt;/LinearLayout&gt;
  
  
  UserAdapter.java
  
  package com.rad.mobileshop.activities;
  
  import java.sql.SQLException;
  
  import android.app.Activity;
  import android.content.Context;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.View.OnClickListener;
  import android.view.ViewGroup;
  import android.widget.ArrayAdapter;
  import android.widget.Button;
  import android.widget.TextView;
  
  import com.rad.mobileshop.common.entities.User;
  import com.rad.mobileshop.db.DBAdapter;
  
  public class UserAdapter extends ArrayAdapter&lt;User&gt; {
  
      Context context;
      int layoutResourceId;
      User data[] = null;
      private DBAdapter mdb;
  
      public UserAdapter(Context context, int layoutResourceId, User[] data) {
          super(context, layoutResourceId, data);
          this.layoutResourceId = layoutResourceId;
          this.context = context;
          this.data = data;
          mdb = new DBAdapter(context);
      }
  
      @Override
      public View getView(int position, View convertView, ViewGroup parent) {
          View row = convertView;
          UserHolder holder = null;
  
          if (row == null) {
              LayoutInflater inflater = ((Activity) context).getLayoutInflater();
              row = inflater.inflate(layoutResourceId, parent, false);
  
              holder = new UserHolder();
              holder.txtTitle = (TextView) row.findViewById(R.id.txtTitle);
              holder.editButton = (Button) row
                      .findViewById(R.id.userListEditButton);
              holder.deleteButton = (Button) row
                      .findViewById(R.id.userListDeleteButton);
  
              row.setTag(holder);
          } else {
              holder = (UserHolder) row.getTag();
          }
  
          User user = data[position];     
          holder.txtTitle.setText(user.getName());
          holder.editButton.setText("Edit");
          holder.deleteButton.setText("Delete");
  
          holder.editButton.setOnClickListener(new OnClickListener() {
              public void onClick(View view) {
                  System.out.println("hello Edit");
              }
          });
  
          holder.deleteButton.setOnClickListener(new OnClickListener() {
              public void onClick(View view) {
                  System.out.println("hello delete ");
              }
          });     
  
          return row;
      }
  
      private void deleteUserDetails(int userId) {
          try {
  
              mdb.open();
              mdb.deleteUserDetails(userId);
  
          } catch (SQLException e1) {
              e1.printStackTrace();
          }
      }
  
      static class UserHolder {
          TextView txtTitle;
          Button editButton;
          Button deleteButton;
      }
  }
  
  User.java
  
  package com.rad.mobileshop.common.entities;
  
  public class User {
      private int id;
      private String name;
      private String type;
  
      public User() {
          super();
      }
  
      public User(int id, String name, String type) {
          super();
          this.id = id;
          this.name = name;
          this.type = type;
      }
  
      public int getId() {
          return id;
      }
  
      public void setId(int id) {
          this.id = id;
      }
  
      public String getName() {
          return name;
      }
  
      public void setName(String name) {
          this.name = name;
      }
  
      public String getType() {
          return type;
      }
  
      public void setType(String type) {
          this.type = type;
      }
  
      @Override
      public String toString() {
          return this.name ;
      }
  }
  </code></pre>