title: how to set update and delete button for every item in listview
body: <p>activity_main.xml</p>
  
  <pre><code> &lt;?xml version="1.0" encoding="utf-8"?&gt;
   &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
       xmlns:app="http://schemas.android.com/apk/res-auto"
       xmlns:tools="http://schemas.android.com/tools"
       android:layout_width="match_parent"
       android:layout_height="match_parent"
       tools:context=".MainActivity"&gt;
  
       &lt;ScrollView
           android:id="@+id/scroll_view"
           android:layout_width="match_parent"
           android:layout_height="match_parent"&gt;
  
           &lt;LinearLayout
               android:id="@+id/linearlayout1"
               android:layout_width="match_parent"
          android:layout_height="match_parent"
               android:orientation="vertical"&gt;
  
               &lt;TextView
                   android:id="@+id/tv_name1"
                   android:layout_width="match_parent"
                   android:layout_height="wrap_content"
                   android:layout_marginLeft="30dp"
                   android:layout_marginTop="15dp"
                   android:layout_marginRight="30dp"
                   android:padding="15dp"
                   android:text="Name:"
                   android:textSize="15sp" /&gt;
  
               &lt;EditText
                   android:id="@+id/et_name1"
                   android:layout_width="match_parent"
                   android:layout_height="wrap_content"
                   android:layout_marginLeft="30dp"
                   android:layout_marginRight="30dp"
                   android:hint="Enter Your Name"
                   android:padding="15dp"
                   android:textSize="15sp" /&gt;
  
               &lt;TextView
                   android:id="@+id/tv_email"
                   android:layout_width="match_parent"
                   android:layout_height="wrap_content"
                   android:layout_marginLeft="30dp"
                   android:layout_marginRight="30dp"
                   android:padding="15dp"
                   android:text="Email:"
                   android:textSize="15dp" /&gt;
  
               &lt;EditText
                   android:id="@+id/et_email"
                   android:layout_width="match_parent"
                   android:layout_height="wrap_content"
                   android:layout_marginLeft="30dp"
                   android:layout_marginRight="30dp"
                   android:hint="Enter Your Mail"
                   android:textSize="15dp" /&gt;
  
               &lt;TextView
                   android:id="@+id/tv_phoneno"
                   android:layout_width="match_parent"
                   android:layout_height="wrap_content"
                   android:layout_marginLeft="30dp"
                   android:layout_marginRight="30dp"
                  android:padding="15dp"
                   android:text="Phone No:"
                   android:textSize="15dp" /&gt;
  
               &lt;EditText
                   android:id="@+id/et_phoneno"
                   android:layout_width="match_parent"
                   android:layout_height="wrap_content"
                   android:layout_marginLeft="30dp"
                   android:layout_marginRight="30dp"
                   android:hint="Enter your Contact No"
                   android:padding="15dp"
                   android:textSize="15dp" /&gt;
  
               &lt;LinearLayout
                   android:layout_width="match_parent"
                   android:layout_height="match_parent"
                   android:orientation="horizontal"
                   android:padding="15dp"
                   android:weightSum="2"&gt;
  
                   &lt;TextView
                       android:id="@+id/tv_dob"
                       android:layout_width="0dp"
                       android:layout_height="wrap_content"
                      android:layout_marginLeft="30dp"
                       android:layout_marginRight="30dp"
                       android:layout_weight="1"
                       android:text="DOB:"
                       android:textSize="15dp"
  
                       /&gt;
  
                   &lt;Button
                       android:id="@+id/datepicker1"
                       android:layout_width="0dp"
                       android:layout_height="30dp"
                       android:layout_marginLeft="30dp"
                      android:layout_marginRight="70dp"
                       android:layout_weight="1"
                       android:textSize="15dp"&gt;
  
                   &lt;/Button&gt;
  
              &lt;/LinearLayout&gt;
  
               &lt;TextView
                   android:id="@+id/tv_qualification"
                   android:layout_width="match_parent"
                   android:layout_height="match_parent"
                   android:layout_marginLeft="30dp"
                   android:layout_marginRight="30dp"
                   android:padding="15dp"
                   android:text="Qualification"
                   android:textSize="15dp" /&gt;
  
               &lt;EditText
                   android:id="@+id/et_qualification"
                   android:layout_width="match_parent"
                   android:layout_height="wrap_content"
                   android:layout_marginLeft="30dp"
                  android:layout_marginRight="30dp"
                   android:hint="Enter Your Qualification"
                   android:padding="15dp"
                   android:textSize="15dp" /&gt;
  
               &lt;LinearLayout
                  android:id="@+id/linearlayout2"
                  android:layout_width="match_parent"
                   android:layout_height="match_parent"
                   android:orientation="horizontal"
                   android:padding="15dp"
                   android:weightSum="2"&gt;
  
                   &lt;TextView
                       android:id="@+id/tv_time"
                       android:layout_width="0dp"
                    android:layout_height="wrap_content"
                       android:layout_marginLeft="30dp"
                       android:layout_marginRight="30dp"
                       android:layout_weight="1"
                       android:text="Time:"
                       android:textSize="15dp"
  
                       /&gt;
  
                   &lt;Button
                       android:id="@+id/timepicker1"
                       android:layout_width="0dp"
                     android:layout_height="30dp"
                      android:layout_marginLeft="30dp"
                       android:layout_marginRight="70dp"
                       android:layout_weight="1"
                      android:textSize="15dp"&gt;
  
                   &lt;/Button&gt;
  
               &lt;/LinearLayout&gt;
  
               &lt;Button
                   android:id="@+id/button_save"
                   android:layout_width="wrap_content"
                   android:layout_height="wrap_content"
                   android:text="Save"
                   android:layout_gravity="center"
                   android:textSize="15dp"&gt;
  
               &lt;/Button&gt;
           &lt;/LinearLayout&gt;
      &lt;/ScrollView&gt;
  
  
   &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>MainActivity</p>
  
  <pre><code>import android.app.DatePickerDialog;
  import android.app.TimePickerDialog;
  import android.content.Intent;
  import android.icu.text.SimpleDateFormat;
  import android.os.Build;
  import android.support.annotation.RequiresApi;
  import android.support.v7.app.AppCompatActivity;
  import android.os.Bundle;
  import android.view.View;
  import android.widget.Button;
  import android.widget.DatePicker;
  import android.widget.EditText;
  import android.widget.TextView;
  import android.widget.TimePicker;
  
  import java.text.ParseException;
  import java.util.Calendar;
  import java.util.Date;
  
  import static android.content.Intent.EXTRA_EMAIL;
  import static android.content.Intent.EXTRA_PHONE_NUMBER;
  import static android.os.DropBoxManager.EXTRA_TIME;
  import static android.security.KeyChain.EXTRA_NAME;
  
  public class MainActivity extends AppCompatActivity implements View.OnClickListener {
      public static final String EXTRA_NAME = "com.example.android.persondetails.EXTRA_NAME";
      public static final String EXTRA_EMAIL = "com.example.android.persondetails.EXTRA_EMAIL";
      public static final String EXTRA_PHONE_NUMBER = "com.example.android.persondetails.EXTRA_PHONE_NUMBER";
      public static final String EXTRA_DOB = "com.example.android.persondetails.EXTRA_DOB";
      public static final String EXTRA_QUALIFICATION = "com.example.android.persondetails.EXTRA_QUALIFICATION";
      public static final String EXTRA_TIME = "com.example.android.persondetails.EXTRA_TIME";
      Button button1, button2, button3;
      TextView textView1, textView2, textView3, textView4, textView5, textView6;
      EditText editText1, editText2, editText3, editText4;
      private int mYear, mMonth, mDay, mHour, mMinute, format;
  
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          button3 = (Button) findViewById(R.id.button_save);
          textView1 = (TextView) findViewById(R.id.tv_name1);
          textView2 = (TextView) findViewById(R.id.tv_email);
          textView3 = (TextView) findViewById(R.id.tv_phoneno);
          textView4 = (TextView) findViewById(R.id.tv_dob);
          textView5 = (TextView) findViewById(R.id.tv_qualification);
          textView6 = (TextView) findViewById(R.id.tv_time);
          button1 = (Button) findViewById(R.id.datepicker1);
          button2 = (Button) findViewById(R.id.timepicker1);
  
  
          button1.setOnClickListener(this);
          button2.setOnClickListener(this);
          button3.setOnClickListener(this);
  
      }
  
      @Override
      public void onClick(View v) {
  
          if (v == button1) {
  
              final Calendar c = Calendar.getInstance();
              mYear = c.get(Calendar.YEAR);
              mMonth = c.get(Calendar.MONTH);
              mDay = c.get(Calendar.DAY_OF_MONTH);
              format = c.get(Calendar.AM_PM);
  
  
              DatePickerDialog datePickerDialog = new DatePickerDialog(this,
                      new DatePickerDialog.OnDateSetListener() {
  
                          @Override
                          public void onDateSet(DatePicker view, int year,
                                                int monthOfYear, int dayOfMonth) {
  
                              textView4.setText(dayOfMonth + "-" + (monthOfYear + 1) + "-" + year);
  
                          }
                      }, mYear, mMonth, mDay);
              datePickerDialog.show();
          }
          if (v == button2) {
  
              final Calendar c = Calendar.getInstance();
              mHour = c.get(Calendar.HOUR_OF_DAY);
              mMinute = c.get(Calendar.MINUTE);
              format = c.get(Calendar.AM_PM);
              final TimePickerDialog timePickerDialog;
              timePickerDialog = new TimePickerDialog(this,
                      new TimePickerDialog.OnTimeSetListener() {
  
                          @RequiresApi(api = Build.VERSION_CODES.N)
                          @Override
                          public void onTimeSet(TimePicker timePicker, int selectedHour, int selectedMinute) {
  
  
                              String time = selectedHour + ":" + selectedMinute;
  
                              SimpleDateFormat fmt = new SimpleDateFormat("HH:mm");
                              Date date = null;
                              try {
                                  date = fmt.parse(time);
                              } catch (ParseException e) {
  
                                  e.printStackTrace();
                              }
  
                              SimpleDateFormat fmtOut = new SimpleDateFormat("hh:mm aa");
  
                              String formattedTime = fmtOut.format(date);
  
                              textView6.setText(formattedTime);
                          }
                      }, mHour, mMinute, false);
              timePickerDialog.setTitle("Select Time");
              timePickerDialog.show();
          } 
  
  
              if (v == button3) {
                  EditText editText1 = (EditText) findViewById(R.id.et_name1);
                  String text = editText1.getText().toString();
                  EditText editText2 = (EditText) findViewById(R.id.et_email);
                  String text1 = editText2.getText().toString();
                  EditText editText3 = (EditText) findViewById(R.id.et_phoneno);
                  String text2 = editText3.getText().toString();
                  TextView textView6 = (TextView) findViewById(R.id.datepicker1); 
                  String text3 = textView6.getText().toString();
                  EditText editText4 = (EditText) findViewById(R.id.et_qualification); 
                  String text4 = editText4.getText().toString();
                  TextView textView4 = (TextView)  findViewById(R.id.timepicker1);
                  String text5 = textView4.getText().toString();
                  button3=(Button)findViewById(R.id.button_save);
                  Intent intent = new Intent(MainActivity.this, SecondActivity.class);
                  intent.putExtra(EXTRA_NAME, text);
                  intent.putExtra(EXTRA_EMAIL, text1);
                  intent.putExtra(EXTRA_PHONE_NUMBER, text2);
                  intent.putExtra(EXTRA_DOB, text3);
                  intent.putExtra(EXTRA_QUALIFICATION, text4);
                  intent.putExtra(EXTRA_TIME, text5);
                  startActivity(intent);
  
              }
  
  
          }
      }
  </code></pre>
  
  <p>second_layout.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;RelativeLayout
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:orientation="vertical"
      &gt;
  
      &lt;TextView
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:id="@+id/tv_name1"
          android:text="Name"
          android:textSize="15dp"
          /&gt;
  
      &lt;TextView
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:id="@+id/tv_phoneno"
          android:layout_below="@+id/tv_name1"
          android:text="contactno"
          android:textSize="15dp"
          /&gt;
      &lt;TextView
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_below="@+id/tv_phoneno"
          android:id="@+id/tv_email"
          android:text="Email"
          android:textSize="15dp"
          /&gt;
      &lt;TextView
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:id="@+id/tv_dob"
          android:layout_below="@+id/tv_email"
          android:text="DOB"
          android:textSize="15dp"
          /&gt;
      &lt;TextView
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:id="@+id/tv_qualification"
          android:layout_below="@+id/tv_dob"
          android:text="Qualification"
          android:textSize="15dp"
          /&gt;
      &lt;TextView
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:id="@+id/tv_time"
          android:layout_below="@+id/tv_qualification"
          android:text="Time"
          android:textSize="15dp"
          /&gt;
  
      &lt;LinearLayout
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:orientation="horizontal"
          android:layout_marginTop="120dp"
          android:weightSum="2"
          &gt;
  
          &lt;Button
              android:layout_width="0dp"
              android:layout_height="wrap_content"
              android:layout_below="@+id/tv_time"
              android:layout_weight="1"
              android:textSize="15dp"
              android:text="Delete"
              android:padding="10dp"
              android:id="@+id/delete"
              /&gt;
  
  
          &lt;Button
              android:layout_width="0dp"
              android:layout_height="wrap_content"
              android:layout_weight="1"
              android:textSize="15dp"
              android:text="Update"
              android:id="@+id/update"
              android:padding="10dp"
              /&gt;
  
      &lt;/LinearLayout&gt;
  
  
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>SecondActivity.java</p>
  
  <pre><code>package com.example.android.persondetails;
  
  import android.content.Intent;
  import android.os.Bundle;
  import android.support.v7.app.AppCompatActivity;
  import android.util.Log;
  import android.widget.ArrayAdapter;
  import android.widget.Button;
  import android.widget.ListView;
  import android.widget.TextView;
  
  import java.util.ArrayList;
  import java.util.List;
  
  import static java.util.Calendar.AM;
  
  public class SecondActivity extends AppCompatActivity {
      private ListView lvPerson;
      private Button addBtn,dleBtn;
      private PersonListAdapter adapter;
      private List&lt;Person&gt; mPersonList;
  
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.list_view);
  
          mPersonList = new ArrayList&lt;Person&gt;();
  
          addBtn = (Button) findViewById(R.id.update);
          dleBtn = (Button) findViewById(R.id.delete);
          lvPerson = (ListView) findViewById(R.id.listView);
  
  
  
          Intent intent = getIntent();
          String text = (String) intent.getStringExtra(MainActivity.EXTRA_NAME);
          String text1 = (String) intent.getStringExtra(MainActivity.EXTRA_PHONE_NUMBER);
          String text2 = (String) intent.getStringExtra(MainActivity.EXTRA_EMAIL);
          String text3 = (String) intent.getStringExtra(MainActivity.EXTRA_QUALIFICATION);
          String text4 = (String) intent.getStringExtra(MainActivity.EXTRA_DOB);
          String text5 = (String) intent.getStringExtra(MainActivity.EXTRA_TIME);
  
  
          Log.d("PersonDetails", text + " " + text1 + "" + text2 + "" + text3 + "" + text4 + "" + text5);
          mPersonList.add(0,new Person(text,text1,text2,text3,text4,text5));
          addMethod();
          setAdapter();
  
      }
  
      private void addMethod() {
  
          mPersonList.add(1,new Person("Narendra", "83330072", "narendraprasad616@gmail.com", "btech", "14 / 06 / 1996", "5-30 AM"));
          mPersonList.add(2,new Person("Banu", "715452", "naredra@gmail.com", "btech", "14 / 06 / 1996", "5-45 AM"));
          mPersonList.add(3,new Person("Kalyan", "83330072", "narendraprad616@gmail.com", "btech", "14 / 06 / 1998", "5-30 AM"));
          mPersonList.add(4,new Person("Teja", "8775564", "narendraprasa16@gmail.com", "btech", "14 / 06 / 1990", "5-30 AM"));
          mPersonList.add(5,new Person("Manu", "86423", "narendraprad616@gmail.com", "btech", "14 / 06 / 1996", "5-30 AM"));
  
      }
  
  
      private void setAdapter() {
          adapter = new PersonListAdapter(SecondActivity.this, mPersonList);
          lvPerson.setAdapter(adapter);
      }
  }
  </code></pre>
  
  <p>how to set dailog to update button and one dailog should need to open it should be in editing what we had like in main activityxml after clicking delete it should be deleted,update means open dailog and reedit and update</p>
  
  <blockquote>
    <p>PersonListAdapter.java</p>
  </blockquote>
  
  <pre><code>package com.example.android.persondetails;
  
  
  import android.content.Context;
  import android.os.Build;
  import android.support.annotation.RequiresApi;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
  import android.widget.BaseAdapter;
  import android.widget.TextView;
  
  import java.util.List;
  
  public class PersonListAdapter extends BaseAdapter {
  
      private Context mContext;
      private List&lt;Person&gt; mPersonList;
  
      PersonListAdapter(Context mContext, List&lt;Person&gt; mPersonList) {
          this.mContext = mContext;
          this.mPersonList = mPersonList;
      }
  
  
  
      @Override
      public int getCount() {
          return mPersonList.size();
      }
  
      @Override
      public Object getItem(int position) {
          return mPersonList.get(position);
      }
  
  
      @RequiresApi(api = Build.VERSION_CODES.P)
      @Override
      public View getView(int position, View convertView, ViewGroup parent) {
          ViewHolder holder;
          if (convertView == null) {
              holder = new ViewHolder();
              convertView = LayoutInflater.from(mContext).inflate(R.layout.second_layout, parent, false);
              holder.tv_name = (TextView) convertView.findViewById(R.id.tv_name1);
              holder.tv_contact = (TextView) convertView.findViewById(R.id.tv_phoneno);
              holder.tv_email=(TextView)convertView.findViewById(R.id.tv_email);
              holder.tv_dob=(TextView)convertView.findViewById(R.id.tv_dob);
              holder.tv_qualification=(TextView)convertView.findViewById(R.id.tv_qualification);
              holder.tv_time=(TextView)convertView.findViewById(R.id.tv_time);
  
              convertView.setTag(holder);
          } else {
              holder = (ViewHolder) convertView.getTag();
          }
  
          holder.tv_name.setText(mPersonList.get(position).getName());
          holder.tv_contact.setText(mPersonList.get(position).getContactno());
          holder.tv_email.setText(mPersonList.get(position).getEmail());
          holder.tv_dob.setText(mPersonList.get(position).getDatepicker());
          holder.tv_qualification.setText(mPersonList.get(position).getQualification());
          holder.tv_time.setText(mPersonList.get(position).getTimepicker());
          return convertView;
  
      }
  
      @Override
      public long getItemId(int position) {
          return position;
      }
  
  
      class ViewHolder {
          TextView tv_name;
          TextView tv_email;
          TextView tv_contact;
          TextView tv_dob;
          TextView tv_qualification;
          TextView tv_time;
  
      }
  
  }
  </code></pre>
  
  <p>Person.java</p>
  
  <pre><code>package com.example.android.persondetails;
  
  public class Person {
      private String name;
      private String contactno;
      private String email;
      private String qualification;
      private String datepicker;
      private String timepicker;
  
  
  
      public Person(String name, String contactno, String email, String qualification, String datepicker, String timepicker) {
          this.name = name;
          this.contactno = contactno;
          this.qualification=qualification;
          this.datepicker=datepicker;
          this.email=email;
          this.timepicker=timepicker;
  
  
      }
  
      public String getName() {
          return name == null ? "" : name;
      }
  
      public void setName(String name) {
          this.name = name;
      }
  
  
      public String  getContactno() {
          return contactno;
      }
  
      public void  setContactno(String contactno){
          this.contactno=contactno;
      }
      public String getEmail() {
          return email;
      }
  
      public String getQualification() {
          return qualification;
      }
  
      public String getDatepicker() {
          return datepicker;
      }
  
      public String getTimepicker() {
          return timepicker;
      }
  }
  </code></pre>
  
  <p>list_view.xml</p>
  
  <pre><code> &lt;?xml version="1.0" encoding="utf-8"?&gt;
      &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:app="http://schemas.android.com/apk/res-auto"
      xmlns:tools="http://schemas.android.com/tools"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      tools:context=".Person"&gt;
  
      &lt;ListView
          android:id="@+id/listView"
          android:layout_width="match_parent"
          android:layout_height="match_parent"&gt;
      &lt;/ListView&gt;
  
      &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>AndroidManifest.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.example.android.persondetails"&gt;
  
      &lt;application
          android:allowBackup="true"
          android:icon="@mipmap/ic_launcher"
          android:label="@string/app_name"
          android:roundIcon="@mipmap/ic_launcher_round"
          android:supportsRtl="true"
          android:theme="@style/AppTheme"
          &gt;
          &lt;activity android:name=".SecondActivity"&gt;
      &lt;/activity&gt;
          &lt;activity android:name=".MainActivity"
              android:parentActivityName=".MainActivity"&gt;
              &lt;intent-filter&gt;
                  &lt;action android:name="android.intent.action.MAIN" /&gt;
  
                  &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
              &lt;/intent-filter&gt;
          &lt;/activity&gt;
      &lt;/application&gt;
  
  &lt;/manifest&gt;
  </code></pre>