Click here to Skip to main content
15,940,246 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I have created an layout which contains the listview. I have added a button'+', which on clicked gives an alert box with an edit text box and two options OK and CANCEL.
I want to add the item which the user enters in the edit text box into the listview. Can any one help me out how to add it?



this is the code which shows me the Alert dialogue box:

if(v.getId() == addbtn.getId())
{
AlertDialog.Builder alert = new AlertDialog.Builder(this);

alert.setTitle("Add new location");


// Set an EditText view to get user input
final EditText input = new EditText(this);
alert.setView(input);

alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
Editable value = input.getText();
// Do something with value!
}
});

alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
// Canceled.
}
});

alert.show();



}
Posted
Comments
Aashish J Kumar 22-Oct-12 6:26am    
alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
Editable value = input.getText();
// Do something with value! <--------this is where I need to add the activity which adds the entered text into the listview. Can any one suggest me the code for that?
Aashish J Kumar 22-Oct-12 6:32am    
Editable value = input.getText();

This value I need to enter as the items in the listview.

1 solution

Use "confirm" window instead of "alert" window.

Thanks,
Ambesha
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900