How to add alert dialog(code) when add item to dynamic list view by code

  • Replies:0
  • OpenNot stickiedUnanswered
  • Forum posts: 3

Apr 30, 2016 2:56:53 AM via Website

the following code to add dynamic list view by button
public class MainActivity extends AppCompatActivity {
private ArrayListarrayList;
private ArrayAdapteradapter;
private EditText txtInput;

protected void onCreate(Bundle savedInstanceState) {
    ListView listView=(ListView)findViewById(;
    String[] items={"apple","banana","grape"};
    arrayList=new ArrayList<>(Arrays.asList(items));
    adapter=new ArrayAdapter<String>(this,R.layout.list_item,,arrayList);
    Button btadd=(Button)findViewById(;
    btadd.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v)
            String newitem=txtInput.getText().toString();



what i need to add alert dialog code with yes and NO when yes add item
when NO not added
Actually i need to modify code to accept alert dialog box with yes and NO
when press yes add item
when press NO not added