I've made a listview for some games, and when a game is deleted i'd like it to vanish in the listview. I'm trying to use adapter.notifyDataSetChanged(), but i can't get it to work, can you help me?
public static final String MY_SETTINGS = "MySettings";
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
DBHelpeR entry = new DBHelpeR(Loadmenu.this);
entry.open();
final ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,R.layout.list_item,entry.getGameNames());
setListAdapter(adapter);
entry.close();
ListView lv = getListView();
lv.setTextFilterEnabled(true);
lv.setBackgroundResource(R.drawable.background);
final AlertDialog.Builder builder = new AlertDialog.Builder(this);
lv.setOnItemLongClickListener(new OnItemLongClickListener(){
public boolean onItemLongClick(AdapterView<?> parent, final View view,
int position, long id) {
String gamename = ((TextView) view).getText().toString();
builder.setTitle("Slet " + gamename + "?");
builder.setItems(new CharSequence[]{"Slet"} , new DialogInterface.OnClickListener() {
// Click listener
public void onClick(DialogInterface dialog, int item) {
DBHelpeR entry = new DBHelpeR(Loadmenu.this);
entry.open();
int game_id = entry.getGameID(((TextView) view).getText().toString());
Log.d("load",Integer.toString(game_id));
entry.deleteGame(game_id);
entry.close();
adapter.notifyDataSetChanged();
}
});
builder.show();
return true;
}
});
}
final ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,R.layout.list_item,entry.getGameNames());
replace the above line with below :::
ArrayList<String> entries = entry.getGameNames();
final ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,R.layout.list_item,entries);
and when you delete just dcall the below two lines again::
entries = entry.getGameNames();
adapter.notifyDataSetChanged();
Updated::
Again before calling adapter.notifyDataSetChanged(); call the below lines::
final ArrayAdapter<String> adapter = new ArrayAdapter<String>(getApplicationContext(), R.layout.list_item, entry.getGameNames());
setListAdapter(adapter);
call
final ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,R.layout.list_item,entry.getGameNames());
setListAdapter(adapter);
Again before calling
adapter.notifyDataSetChanged();
Note: make sure you have changed the array for the change to be visible.
Related
my problem is the following. I have 2 Spinners in one activity. I want that both spinner items should be saved in the DB. But there is a slight difference between both spinners:
Spinner 1: Is populated by data from other db-table - when it is the only spinner in the mentioned activity, it works.
Spinner 2: Has default values. I am not sure if added it correctly to my activity. Anyway, after i added it to my saving the data is not working anymore.
Please help me what am I doing wrong??
My Activity Code:
public class activity_transport extends AppCompatActivity {
private BottomNavigationViewEx bottomNavigationViewEx;
DatabaseHelper myDb;
Button btn_save;
Spinner ChooseProject,ChooseTransport;
EditText Entfernung,Price,MWST;
String selectedspinner, selectedTransport;
ImageView imageView2;
private static int PICK_IMAGE = 100;
Uri imageUri;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_transport);
myDb = new DatabaseHelper(this);
ChooseProject = (Spinner) findViewById(R.id.ChooseProject);
ChooseTransport = (Spinner) findViewById(R.id.ChooseTransport);
Entfernung = (EditText) findViewById(R.id.Entfernung);
Price = (EditText) findViewById(R.id.Preis);
MWST = (EditText) findViewById(R.id.MwSt);
btn_save=(Button) findViewById(R.id.btn_save);
//bildanzeigebereich im layout
imageView2=(ImageView) findViewById(R.id.imageView2);
loadProjectSpinnerData();
//loadTransportSpinnerData();
SaveData();
//+++++++++++++++Function to load the spinner data from SQLite database++++++++++//
private void loadProjectSpinnerData() {
// database handler
DatabaseHelper db = new DatabaseHelper (getApplicationContext());
// Spinner Drop down elements
List<String> projects = db.getAllProjects();
// Creating adapter for spinner
ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, projects);
// Drop down layout style - list view with radio button
dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
ChooseProject.setPrompt("Projekt auswählen");
// attaching data adapter to spinner
ChooseProject.setAdapter(dataAdapter);
//Choose Transport Spinner
ArrayAdapter<String> spinnerArrayAdapter = new ArrayAdapter<String>(this,
android.R.layout.simple_spinner_item, new String[] {
new String("Auto"),
new String("Flugzeug"),
new String("Taxi"),
new String("Bahn")});
ChooseTransport.setAdapter(spinnerArrayAdapter);
// Drop down layout style - list view with radio button
spinnerArrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
ChooseTransport.setPrompt("Transport auswählen");
// attaching data adapter to spinner
ChooseTransport.setAdapter(spinnerArrayAdapter);
//Listener für den Projekt Spinner damit ich den Wert abspeichern kann
ChooseProject.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
Spinner spinner = (Spinner) parent;
if(spinner.getId() == R.id.ChooseProject)
{
selectedspinner = (String) ChooseProject.getSelectedItem();
}
else if(spinner.getId() == R.id.ChooseTransport)
{
selectedTransport = (String) ChooseTransport.getSelectedItem();
}
//selectedspinner =String.ValueOf(parent.getItemAtPosition(pos));
}
public void onNothingSelected(AdapterView<?> parent) {
}
});
}
/*private void loadTransportSpinnerData() {
// Spinner method to read the on selected value
ArrayAdapter<String> spinnerArrayAdapter = new ArrayAdapter<String>(this,
android.R.layout.simple_spinner_item, new String[] {
new String("Auto"),
new String("Flugzeug"),
new String("Taxi"),
new String("Bahn")});
ChooseTransport.setAdapter(spinnerArrayAdapter);
// Creating adapter for spinner
//ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, projects);
// Drop down layout style - list view with radio button
spinnerArrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
ChooseTransport.setPrompt("Transport auswählen");
// attaching data adapter to spinner
ChooseTransport.setAdapter(spinnerArrayAdapter);
//Listener für den Projekt Spinner damit ich den Wert abspeichern kann
ChooseTransport.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
//selectedspinner =String.ValueOf(parent.getItemAtPosition(pos));
selectedTransport = (String) ChooseTransport.getSelectedItem();
}
public void onNothingSelected(AdapterView<?> parent) {
}
});
}*/
//++++++++++++Save Data++++++//
public void SaveData(){
btn_save.setOnClickListener(
new View.OnClickListener() {
#Override
public void onClick(View v) {
boolean isInserted = myDb.createTransport(
selectedspinner,
selectedTransport,
Integer.valueOf(Price.getText().toString()),
Integer.valueOf(MWST.getText().toString()),
Integer.valueOf(Entfernung.getText().toString()),
imageViewToByte(imageView2)
);
if(isInserted=true)
Toast.makeText(activity_transport.this, "Daten gespeichert", Toast.LENGTH_LONG).show();
else
Toast.makeText(activity_transport.this, "Daten nicht gespeichert", Toast.LENGTH_LONG).show();
}
}
);
}
}
EDIT:
I tried to run the app by setting a few breakpoints.
When trying to run this line selectedTransport = (String) ChooseTransport.getSelectedItem(); the debugger posts Cannot find local variable 'ChooseTransport'
I solved the problem:
I implemented an own method for ChooseTransport- Spinner and now it works. I also figured out that the order how I add the data to the DB was not right. I changed this too.
See here my method for my second spinner:
private void loadTransportSpinnerData(){
ArrayAdapter<CharSequence> spinnerArrayAdapter = ArrayAdapter.createFromResource(this, R.array.transport, android.R.layout.simple_spinner_dropdown_item);
spinnerArrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
ChooseTransport.setPrompt("Transport auswählen");
ChooseTransport.setAdapter(spinnerArrayAdapter);
ChooseTransport.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
#Override
public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
selectedTransport = (String) ChooseTransport.getSelectedItem();
}
#Override
public void onNothingSelected(AdapterView<?> adapterView) {
}
});
}
I am trying to remove an item from the list when I click on the selected item but I get an error on logcat saying that the removeViewAt method is not supported on AddapterView. Any idea of what I could use here in order to achieve this ?
Many thanks.
Here is my code.
listView.setOnItemClickListener(new OnItemClickListener()
{
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id)
{
listView.removeViewAt(position);
listView.invalidateViews();
}
});
}
Try this:
ArrayList<String> arrlist=new ArrayList<String>();
arrlist.add("A");
arrlist.add("B");
arrlist.add("C");
arrlist.add("D");
ListView listView = (ListView) findViewById(R.id.mylist);
String[] items = { "Milk", "Butter", "Yogurt", "Toothpaste", "Ice Cream" };
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, items);
listView.setAdapter(adapter);
listView.setOnItemClickListener(new OnItemClickListener()
{
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id)
{
items.remove(position);
adapter.notifyDataSetChanged();
}
});
}
This fades away the clicked item using Animation, Requires API level 16
private List<String> myList;
File file;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ListView listView = (ListView) findViewById(R.id.listerX);
myList = new ArrayList<String>();
File directory = Environment.getExternalStorageDirectory();
file = new File( directory + "/myAppCache/" );
File list[] = file.listFiles();
for( int i=0; i< list.length; i++)
{
myList.add( list[i].getName() );
}
listView.setOnItemClickListener(new AdapterView.OnItemClickListener(){
#Override
public void onItemClick(AdapterView<?> parent, final View view,
int position, long id) {
final String item = (String) parent.getItemAtPosition(position);
view.animate().setDuration(2000).alpha(0)
.withEndAction(new Runnable() {
#Override
public void run()
{
Toast.makeText(getApplicationContext(), ""+item,
Toast.LENGTH_LONG).show();
}
});
}
});
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, android.R.id.text1, myList);
listView.setAdapter(adapter); //Set all the file in the list.
}
you are populate list with any array or collection item
Then remove item at position of clicked position.
And now notify adapter by calling adapter.notifydatasetchange();
Enjoy your code
I am creating spinners dynamically when i click add button.but i dont know how to get the values from created dynamic spinners.I need to get values how many shirt selected, saree selected and jeans selected when i click a submit button
this is my code
buttonAdd = (Button)findViewById(R.id.add);
container = (LinearLayout)findViewById(R.id.container);
final List<String> dressArray = new ArrayList<String>();
dressArray.add("Select Dress");
dressArray.add("Shirt");
dressArray.add("Saree");
dressArray.add("Jeans");
ArrayAdapter<String> adapter = new ArrayAdapter<String>(
this, android.R.layout.simple_spinner_item, dressArray);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
Spinner dress = (Spinner) findViewById(R.id.dress);
dress.setAdapter(adapter);
final List<String> dresscountArray = new ArrayList<String>();
dresscountArray.add("Count");
dresscountArray.add("1");
dresscountArray.add("2");
dresscountArray.add("3");
ArrayAdapter<String> adapter1 = new ArrayAdapter<String>(
this, android.R.layout.simple_spinner_item, dresscountArray);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
Spinner dresscount = (Spinner) findViewById(R.id.dresscount);
dresscount.setAdapter(adapter1);
buttonAdd.setOnClickListener(new OnClickListener(){
#Override
public void onClick(View arg0) {
LayoutInflater layoutInflater =
(LayoutInflater) getBaseContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
final View addView = layoutInflater.inflate(R.layout.row, null);
Spinner dresscount = (Spinner)addView.findViewById(R.id.dresscount);
Spinner dress = (Spinner)addView.findViewById(R.id.dress);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(
PickupOrder.this, android.R.layout.simple_spinner_item, dressArray);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
dress.setAdapter(adapter);
ArrayAdapter<String> adapter1 = new ArrayAdapter<String>(
PickupOrder.this, android.R.layout.simple_spinner_item, dresscountArray);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
dresscount.setAdapter(adapter1);
Button buttonRemove = (Button)addView.findViewById(R.id.remove);
buttonRemove.setOnClickListener(new OnClickListener(){
#Override
public void onClick(View v) {
((LinearLayout)addView.getParent()).removeView(addView);
}});
container.addView(addView);
}});
Firstly define globally
String value1;
int value_position1;
And then call these methods inside onCreate after setting value in each Spinner
spinner1.setOnItemSelectedListener(new OnItemSelectedListener() {
#Override
public void onItemSelected(AdapterView<?> parent,
View view, int position, long id) {
value_position1 = position;
value1 = parent.getSelectedItem().toString()
.trim();
}
#Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
And when you call your submit button, use values of each String.
showallPrompt = "";
int Count = new_container.getChildCount();
try {
for (int cc = 0; cc < Count; cc++) {
View child = new_container.getChildAt(cc);
Spinner value = (Spinner)(child.findViewById(R.id.sp_dynamic));
String spin_value = value.getSelectedItem().toString();
showallPrompt += spin_value;
}
} catch (Exception e) {
}
Toast.makeText(MainActivity.this,
showallPrompt,
Toast.LENGTH_LONG).show();
}
}
Do like this on your button click...
My MainActivity, which extends ActionBarActivity, has a ListView, which I want to reload using notifyDataSetChanged(), but I do not know how to do this.
My code so far:
public class MainActivity extends ActionBarActivity {
private JournalEntryDataSource datasource;
private ListView listView = null;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
datasource = new JournalEntryDataSource(this);
datasource.open();
listView = (ListView) findViewById(R.id.list);
List<JournalEntry> values = datasource.getAllJournalEntries();
listView.setAdapter(new ArrayAdapter<JournalEntry>(this, R.layout.list_item, R.id.lugares, values));
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> arg0, View v, int position, long id) {
Log.i("app", "Deleting item number " + position);
datasource.deleteJournalEntry((JournalEntry) listView.getAdapter().getItem(position));
//I would like to do this here:
//ArrayAdapter<JournalEntry> adapter = (ArrayAdapter<JournalEntry>) getListAdapter();
//adapter.notifyDataSetChanged();
}
});
}
But I get an error when calling adapter.notifyDatasetChanged()...
Any tips? I've been looking at similar questions and no luck so far...
--------EDITED CODE---------
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
datasource = new JournalEntryDataSource(this);
datasource.open();
listView = (ListView) findViewById(R.id.list);
values = datasource.getAllJournalEntries();
listView.setAdapter(new ArrayAdapter<JournalEntry>(this, R.layout.list_item, R.id.lugares, values));
ArrayAdapter<JournalEntry> adapter = (ArrayAdapter<JournalEntry>) getListAdapter();
// use the SimpleCursorAdapter to show the
// elements in a ListView
listView.setAdapter(new ArrayAdapter<JournalEntry>(this, R.layout.list_item, R.id.lugares, values));
listView.setLongClickable(true);
listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
public boolean onItemLongClick(AdapterView<?> parent, View v, int position, long id) {
Log.i("hola","borrando la posición "+position);
JournalEntry removeMe = (JournalEntry)listView.getAdapter().getItem(position);
values.remove(removeMe);
datasource.deleteJournalEntry(removeMe);
//adapter.notifyDataSetChanged();
reloadMe();
return true;
}
});
}
public void reloadMe(){
//need to do this better... but meh.
Intent intent = new Intent(this, MainActivity.class);
this.startActivity(intent);
}
protected ListView getListView() {
if (listView == null) {
listView = (ListView) findViewById(android.R.id.list);
}
return listView;
}
protected void setListAdapter(ListAdapter adapter) {
getListView().setAdapter(adapter);
}
protected ListAdapter getListAdapter() {
ListAdapter adapter = getListView().getAdapter();
if (adapter instanceof HeaderViewListAdapter) {
return ((HeaderViewListAdapter)adapter).getWrappedAdapter();
} else {
return adapter;
}
}
}
Updated Answer for updated code
instead of creating the same activity again, you should choose to set another new adapter object with the new values object.
public void reloadMe(){
//need to do this better... but meh.
//Intent intent = new Intent(this, MainActivity.class);
//this.startActivity(intent);
listView.setAdapter(new ArrayAdapter<JournalEntry>(this, R.layout.list_item, R.id.lugares, values));
}
Perhaps, you are deleting from
datasource.deleteJournalEntry((JournalEntry) listView.getAdapter().getItem(position));
But you did not set "datasource" as the data source of the adapter. If you look carefully you did set the "values" list object-
listView.setAdapter(new ArrayAdapter<JournalEntry>(this, R.layout.list_item, R.id.lugares, values));
Perhaps you may need to also remove from the values list also.
Can somebody please give me an example code of removing all ListView items and replacing with new items?
I tried replacing the adapter items without success. My code is
populateList(){
results //populated arraylist with strings
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, results);
listview.setAdapter(adapter);
adapter.notifyDataSetChanged();
listview.setOnItemClickListener(this);
}
// now populating list again
repopulateList(){
results1 //populated arraylist with strings
ArrayAdapter<String> adapter1 = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, results1);
listview.setAdapter(adapter1);
adapter1.notifyDataSetChanged();
listview.setOnItemClickListener(this);
}
Here repopulateList() method will add to ListView items, but it doesn't remove/replace all ListView items.
You will want to remove() the item from your adapter object and then just run the notifyDatasetChanged() on the Adapter, any ListViews will (should) recycle and update on it's own.
Here's a brief activity example with AlertDialogs:
adapter = new MyListAdapter(this);
lv = (ListView) findViewById(android.R.id.list);
lv.setAdapter(adapter);
lv.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> a, View v, int position, long id) {
AlertDialog.Builder adb=new AlertDialog.Builder(MyActivity.this);
adb.setTitle("Delete?");
adb.setMessage("Are you sure you want to delete " + position);
final int positionToRemove = position;
adb.setNegativeButton("Cancel", null);
adb.setPositiveButton("Ok", new AlertDialog.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
MyDataObject.remove(positionToRemove);
adapter.notifyDataSetChanged();
}});
adb.show();
}
});
I think if u add the following code, it will work
listview.invalidateViews();
To remove an item, Just remove that item from the arraylist that we passed to the adapter and do listview.invalidateViews();
This will refresh the listview
You can use
adapter.clear()
that will remove all item of your first adapter then you could either set another adapter or reuse the adapter and add the items to the old adapter. If you use
adapter.add()
to add data to your list you don't need to call notifyDataSetChanged
int count = adapter.getCount();
for (int i = 0; i < count; i++) {
adapter.remove(adapter.getItem(i));
}
then call notifyDataSetChanged();
Remove it from the adapter and then notify the arrayadapter that data set has changed.
m_adapter.remove(o);
m_adapter.notifyDataSetChanged();
names = db.getSites();
la = new ArrayAdapter<String>(EditSiteList.this,
android.R.layout.simple_list_item_1, names);
EditSiteList.this.setListAdapter(la);
listview.invalidateViews();
this code works fine for me.
You should use only one adapter binded with the list of data you need to list
When you need to remove and replace all items, you have to clear all items from data-list using "list.clear()" and then add new data using "list.addAll(List)"
here an example:
List<String> myList = new ArrayList<String>();
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, myList);
listview.setAdapter(adapter);
listview.setOnItemClickListener(this);
populateList(){
List<String> result = getDataMethods();
myList.addAll(result);
adapter.notifyDataSetChanged();
}
repopulateList(){
List<String> result = getDataMethods();
myList.clear();
myList.addAll(result);
adapter.notifyDataSetChanged();
}
Try this code, it works for me.
public class Third extends ListActivity {
private ArrayAdapter<String> adapter;
private List<String> liste;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_third);
String[] values = new String[] { "Android", "iPhone", "WindowsMobile",
"Blackberry", "WebOS", "Ubuntu", "Windows7", "Max OS X",
"Linux", "OS/2" };
liste = new ArrayList<String>();
Collections.addAll(liste, values);
adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, liste);
setListAdapter(adapter);
}
#Override
protected void onListItemClick(ListView l, View v, int position, long id) {
liste.remove(position);
adapter.notifyDataSetChanged();
}
}
At first you should remove the item from your list. Later you may empty your adapter and refill it with new list.
private void add(final List<Track> trackList) {
MyAdapter bindingData = new MyAdapter(MyActivity.this, trackList);
list = (ListView) findViewById(R.id.my_list); // TODO
list.setAdapter(bindingData);
// Click event for single list row
list.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
final int position, long id) {
// ShowPlacePref(places, position);
AlertDialog.Builder showPlace = new AlertDialog.Builder(
Favoriler.this);
showPlace.setMessage("Remove from list?");
showPlace.setPositiveButton("DELETE", new OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
trackList.remove(position); //FIRST OF ALL REMOVE ITEM FROM LIST
list.setAdapter(null); // THEN EMPTY YOUR ADAPTER
add(trackList); // AT LAST REFILL YOUR LISTVIEW (Recursively)
}
});
showPlace.setNegativeButton("CANCEL", new OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
}
});
showPlace.show();
}
});
}
It's simple .First you should clear your collection and after clear list like this code :
yourCollection.clear();
setListAdapter(null);
You can also use listView.setOnItemLongClickListener to delete selected item.
Below is the code.
// listView = name of your ListView
listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
#Override
public boolean onItemLongClick(AdapterView<?> parent, View view, int
position, long id) {
// it will get the position of selected item from the ListView
final int selected_item = position;
new AlertDialog.Builder(MainActivity.this).
setIcon(android.R.drawable.ic_delete)
.setTitle("Are you sure...")
.setMessage("Do you want to delete the selected item..?")
.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which)
{
list.remove(selected_item);
arrayAdapter.notifyDataSetChanged();
}
})
.setNegativeButton("No" , null).show();
return true;
}
});
//try this:
String text = ( (TextView) view).getText().toString();
adapter.remove(text);