ahmed salah
- Forum posts: 3
Apr 30, 2016, 2:56:53 AM via Website
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;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ListView listView=(ListView)findViewById(R.id.listv);
String[] items={"apple","banana","grape"};
arrayList=new ArrayList<>(Arrays.asList(items));
adapter=new ArrayAdapter<String>(this,R.layout.list_item,R.id.textView2,arrayList);
listView.setAdapter(adapter);
txtInput=(EditText)findViewById(R.id.txtinput);
Button btadd=(Button)findViewById(R.id.btadd);
btadd.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v)
{
String newitem=txtInput.getText().toString();
arrayList.add(newitem);
adapter.notifyDataSetChanged();
}
});
}
}
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
Recommended editorial content
With your consent, external content is loaded here.
By clicking on the button above, you agree that external content may be displayed to you. Personal data may be transmitted to third-party providers in the process. You can find more information about this in our Privacy Policy.