Shared Preferences Saving Listview Items Using Context Menu - android

I've got a context menu bar that has two icons...When I click the save icons I want to store all the the items I've checked in my list view in SharedPreferences and when I click the load icon, I want all those checked items to appear in the list as highlighted.
The icons are declared as menu items in the OnActionItemClicked.
Any ideas would be much appreciated.
My Class:
public class UserContacts extends ActionBarActivity {
SimpleCursorAdapter mAdapter;
MatrixCursor mMatrixCursor;
ListView listview;
int count = 0;
SharedPreferences prf;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_user_contacts);
// The contacts from the contacts content provider is stored in this cursor
mMatrixCursor = new MatrixCursor(new String[] { "_id","name","photo","details"} );
// Adapter to set data in the listview
mAdapter = new SimpleCursorAdapter(getBaseContext(),
R.layout.lv_layout,
null,
new String[] { "name","photo","details"},
new int[] { R.id.tv_name,R.id.iv_photo,R.id.tv_details}, 0);
// Getting reference to listview
final ListView lstContacts = (ListView) findViewById(R.id.lst_contacts);
// Setting the adapter to listview
lstContacts.setAdapter(mAdapter);
// Creating an AsyncTask object to retrieve and load listview with contacts
ListViewContactsLoader listViewContactsLoader = new ListViewContactsLoader();
// Starting the AsyncTask process to retrieve and load listview with contacts
listViewContactsLoader.execute();
//Selecting and highlighting the elements in the listview
//Creating the context menu and the options for it
listview = (ListView) findViewById(R.id.lst_contacts);
listview.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL);
listview.setMultiChoiceModeListener(new AbsListView.MultiChoiceModeListener() {
#Override
public void onItemCheckedStateChanged(ActionMode mode, int position, long id, boolean checked) {
try
{
final int checkedCount = listview.getCheckedItemCount();
mode.setTitle("Contacts: " + checkedCount);
if (checked)
{
count = count+1;
listview.getChildAt(position).setBackgroundColor(Color.parseColor("#6DCAEC"));
}
else
{
count = checkedCount;
listview.getChildAt(position).setBackgroundColor(Color.parseColor("#E7E8E9"));
}
}
catch (Exception e) {
e.printStackTrace();
}
}
#Override
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
MenuInflater inflater = mode.getMenuInflater();
inflater.inflate(R.menu.contact_context_menu, menu);
return true;
}
#Override
public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
return false;
}
#Override
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
switch (item.getItemId()) {
case R.id.delete_id:
Toast.makeText(getBaseContext(), count + " Contacts Deselected", Toast.LENGTH_SHORT).show();
count = 0;
mode.finish();
case R.id.save_id:
Toast.makeText(getBaseContext(), count + " Contacts Saved", Toast.LENGTH_SHORT).show();
count = 0;
mode.finish();
case R.id.load_id:
Toast.makeText(getBaseContext(), count + " Contacts Loaded", Toast.LENGTH_SHORT).show();
count = 0;
mode.finish();
}
return false;
}
#Override
public void onDestroyActionMode(ActionMode mode) {
}
});
}

Related

how to create menu in android on click of list view?

I am trying to create menu in android .Actually I want to show delete Icon when I long press in my list item .
I tried like this .I create one my_menu.xml
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#+id/id_delete"
android:title="Delete"
android:icon="#drawable/delete"></item>
</menu>
Then I create list view .My list view is display on view but it is not showing delete icon when i press long on row .Mean I want to show menu option when I press long on row .I am able to display list..but menu is not display.
here is my java code .
public class MainActivity extends AppCompatActivity {
ListView listView;
ArrayList arrayList = new ArrayList();
ArrayList selectionList = new ArrayList();
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
listView = (ListView) findViewById(R.id.list_view);
Log.d("==", loadJSONFromAsset());
try {
JSONArray js = new JSONArray(loadJSONFromAsset());
for (int i = 0; i < js.length(); i++) {
JSONObject obj = js.getJSONObject(i);
arrayList.add(obj.getString("name"));
}
//adp=new CustomAddapter(getApplicationContext(),R.layout.list_view);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, arrayList);
listView.setAdapter(adapter);
listView.setChoiceMode(AbsListView.CHOICE_MODE_MULTIPLE);
listView.setMultiChoiceModeListener(new AbsListView.MultiChoiceModeListener() {
#Override
public void onItemCheckedStateChanged(ActionMode mode, int position, long id, boolean checked) {
if (checked) {
selectionList.add(arrayList.get(position));
// arrayList.add(arr.)
}
}
#Override
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
MenuInflater menuInflater = getMenuInflater();
menuInflater.inflate(R.menu.my_menu, menu);
return true;
}
#Override
public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
return false;
}
#Override
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
return false;
}
#Override
public void onDestroyActionMode(ActionMode mode) {
}
});
} catch (JSONException e) {
e.printStackTrace();
}
}
public String loadJSONFromAsset() {
String json = null;
try {
InputStream is = getAssets().open("data.json");
int size = is.available();
byte[] buffer = new byte[size];
is.read(buffer);
is.close();
json = new String(buffer, "UTF-8");
} catch (IOException ex) {
ex.printStackTrace();
return null;
}
return json;
}
}
To create a context menu:
Register your listview for a context menu:
registerForContextMenu(listView);`
Then, to add menu items:
#Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo)
{
if(v.getId() == R.id.your_list_view)
{
menu.setHeaderTitle("My menu");
menu.add(Menu.NONE, 0, 0, "Delete");
menu.add(Menu.NONE, 1, 1, "Cancel");
// etc...
}
}
But as far as icons go...
Context menus: Do not support item shortcuts and item icons.
http://developer.android.com/reference/android/view/Menu.html
However, if you search SO you can find ways to do it (code examples, links to libraries).

Android custom listview with toggle button state reset after call another activity and back

Below is my activity class which retrieve data from sqllite db and generate the custom listview with 3textviews and 1 toggle button
Activity class:
public class PaymentReminderActivity extends ActionBarActivity {
ReminderDataSource datasource;
// Array of booleans to store toggle button status
public boolean[] status = {
false,
false,
false,
false,
false,
false,
false,
false,
false,
false
};
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_payment_reminder);
datasource = new ReminderDataSource(this);
/** Restore from the previous state if exists */
if(savedInstanceState!=null){
status = savedInstanceState.getBooleanArray("status");
}
//GET ALL DATA
datasource.open();
final List<ReminderClass> values = datasource.getAllUsers();
datasource.close();
ListView lvReminder = (ListView) findViewById(R.id.lv_countries);
registerForContextMenu(lvReminder);
OnItemClickListener itemClickListener = new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> lv, View item, int position, long id) {
ListView lView = (ListView) lv;
SimpleAdapter adapter = (SimpleAdapter) lView.getAdapter();
HashMap<String,Object> hm = (HashMap) adapter.getItem(position);
/** The clicked Item in the ListView */
RelativeLayout rLayout = (RelativeLayout) item;
/** Getting the toggle button corresponding to the clicked item */
ToggleButton tgl = (ToggleButton) rLayout.getChildAt(2);
String strStatus = "";
if(tgl.isChecked()){
tgl.setChecked(false);
strStatus = "Off";
status[position]=false;
}else{
tgl.setChecked(true);
strStatus = "On";
status[position]=true;
}
Toast.makeText(getBaseContext(), (String) hm.get("txt") + " : " + strStatus, Toast.LENGTH_SHORT).show();
}
};
lvReminder.setOnItemClickListener(itemClickListener);
// Each row in the list stores country name and its status
List<HashMap<String,Object>> aList = new ArrayList<HashMap<String,Object>>();
for (int i = 0; i<values.size(); i++) {
HashMap<String, Object> hm = new HashMap<String, Object>();
hm.put("txt", values.get(i).getType());
hm.put("txt2", values.get(i).getDesc());
hm.put("txt3", values.get(i).getDay() + " of every month");
hm.put("stat", status[i]);
aList.add(hm);
}
// Keys used in Hashmap
String[] from = {"txt","txt2","txt3","stat" };
// Ids of views in listview_layout
int[] to = { R.id.tv_item,R.id.tv_item2, R.id.tv_item3, R.id.tgl_status};
// Instantiating an adapter to store each items
// R.layout.listview_layout defines the layout of each item
SimpleAdapter adapter = new SimpleAdapter(getBaseContext(), aList, R.layout.lv_layout, from, to);
lvReminder.setAdapter(adapter);
}
/** Saving the current state of the activity
* for configuration changes [ Portrait <=> Landscape ]
*/
#Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putBooleanArray("status", status);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_payment_reminder, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_add) {
Intent intent = new Intent();
intent.setClass(this, NewReminderActivity.class);
startActivityForResult(intent, 0);
return true;
}
return super.onOptionsItemSelected(item);
}
#Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, v, menuInfo);
if (v.getId()==R.id.lv_countries) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu_list, menu);
}
}
#Override
public boolean onContextItemSelected(MenuItem item) {
AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
long selectid = info.id; //_id from database in this case
int selectpos = info.position;
switch(item.getItemId()) {
case R.id.add:
// add stuff here
return true;
case R.id.edit:
// edit stuff here
return true;
case R.id.delete:
return true;
default:
return super.onContextItemSelected(item);
}
}
}
Toggling toggle button on list view have no problem.
Once i leave that activity and came back the state is resetted.

How to delete items on the listview in Fragments?

I want to delete the items from the fragments. When long click on the items than a action bar is changed and a delete button appears. I click on the delete button The item seems to be deleted from the list view. But when I restart the app the item appears again.
public class ReadFragment extends Fragment {
ListView spinner;
TextView empty;
String selected;
List<String> list;
String[] filenames;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_read, container,
false);
spinner = (ListView) rootView.findViewById(R.id.spinner2);
this.spinner.setEmptyView(rootView.findViewById(R.id.emptyElement));
getFilenames();
getactionbar();
return rootView;
}
private void getFilenames() {
// TODO Auto-generated method stub
filenames = getActivity().fileList();
list = new ArrayList<String>();
for (int i = 0; i < filenames.length; i++) {
// Log.d("Filename", filenames[i]);
list.add(filenames[i]);
}
ArrayAdapter<String> filenameAdapter = new ArrayAdapter<String>(
getActivity(), android.R.layout.simple_list_item_1,
android.R.id.text1, list);
spinner.setAdapter(filenameAdapter);
spinner.setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
selected = ((TextView) view).getText().toString();
Intent intent = new Intent(getActivity(), ReadData.class);
intent.putExtra("key", selected);
startActivity(intent);
}
});
}
private void getactionbar() {
// TODO Auto-generated method stub
spinner.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL);
spinner.setMultiChoiceModeListener(new MultiChoiceModeListener() {
#Override
public void onItemCheckedStateChanged(ActionMode mode, int position,
long id, boolean checked) {
// Here you can do something when items are selected/de-selected,
// such as update the title in the CAB
}
#Override
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
// Respond to clicks on the actions in the CAB
switch (item.getItemId()) {
case R.id.ic_action_discard:
deletefiles();
Toast.makeText(getActivity(), "Deleted", Toast.LENGTH_LONG).show();
mode.finish(); // Action picked, so close the CAB
return true;
default:
return false;
}
}
private void deletefiles() {
// TODO Auto-generated method stub
SparseBooleanArray checkedItemPositions = spinner.getCheckedItemPositions();
int itemCount = spinner.getCount();
for(int i=itemCount-1; i >= 0; i--){
if(checkedItemPositions.get(i)){
filenameAdapter.remove(list.get(i));
}
}
checkedItemPositions.clear();
filenameAdapter.notifyDataSetChanged();
}
#Override
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
// Inflate the menu for the CAB
MenuInflater inflater = mode.getMenuInflater();
inflater.inflate(R.menu.context, menu);
return true;
}
#Override
public void onDestroyActionMode(ActionMode mode) {
// Here you can make any necessary updates to the activity when
// the CAB is removed. By default, selected items are deselected/unchecked.
}
#Override
public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
// Here you can perform updates to the CAB due to
// an invalidate() request
return false;
}
});
}
}
Can anyone help me deleting the item forever, I mean once it is deleted it should not appear in the listview again when the app is relaunched.
Try, tries it worked here
final Button btnRemove = (Button) findViewById(R.id.button1);
btnRemove.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
lst.remove(adapter.getItem(2));
adapter.notifyDataSetChanged();
}
});;
I don't know if it is intentionally, but you copy the items from the Activity into another array before passing it to the Adapter. So when you call adapter.remove() it only removes the item from the new one leaving the original List in the Activity untuched (guess you save that one to storage in the Activitys onPause or something).

Wrong item from the listview is selected

Initially it shows the correct item selected...but after re-populating the list it shows the wrong item being selected...please help me find the mistake
Intially the list is populated in onCreate()
and is re-populated in onOptionsItemSelected(MenuItem item)
public class MainActivity extends Activity {
MyListActivity adapter;
ListView list;
String[] web = {
"jerry",
"walters"
} ;
Integer[] imageId = {
R.drawable.ic_launcher,
R.drawable.ic_launcher
};
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
adapter = new MyListActivity(MainActivity.this, web, imageId);
list=(ListView)findViewById(R.id.listView1);
list.setAdapter(adapter);
list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view,int position, long id) {
Toast.makeText(MainActivity.this, "You Clicked at " +web[+ position], Toast.LENGTH_SHORT).show();
}
});
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.action_settings:
String[] web2 = {
"walters",
"jerry"
} ;
adapter = new MyListActivity(MainActivity.this, web2, imageId);
list.setAdapter(adapter);
return true;
}
return false;
}
}
You have this
web[position]
// get string from web string array not from web2 based on position
Position is the index.
web[0] = "jerry"
web[1] ="walters"
You are re-populating your listview with a different array.
web and web2 are two different arrays.
If you want to update , update the web array and call notifyDataSetChanged on your adapter to refresh listview
your are not updating your web array:
public class MainActivity extends Activity {
MyListActivity adapter;
ListView list;
String[] web = {
"jerry",
"walters"
} ;
Integer[] imageId = {
R.drawable.ic_launcher,
R.drawable.ic_launcher
};
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
adapter = new MyListActivity(MainActivity.this, web, imageId);
list=(ListView)findViewById(R.id.listView1);
list.setAdapter(adapter);
list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view,int position, long id) {
Toast.makeText(MainActivity.this, "You Clicked at " +web[position], Toast.LENGTH_SHORT).show();
}
});
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.action_settings:
web = {//<--------------just update we array as well
"walters",
"jerry"
} ;
adapter = new MyListActivity(MainActivity.this, web, imageId);
list.setAdapter(adapter);
return true;
}
return false;
}
}
I guess it might because web and web2 have different order which leads to different answer?
String[] web = { "jerry", "walters"} ;
String[] web2 = {"walters", "jerry" } ;

How to remove checked items from listview and in database

Hi i want to remove the checked items from the listview and in database.Iam using menus for that.If delete is selected from the menu then i want to remove the selected items from the listview and in the database.If select all is clicked in the menu i want to set all the checkbox of the listitems checked and then delete all the values from the listview and to delete all the records in the database.Iam using the following code to populate the data from the database in the listview with checkbox.Please help me if anybody knows.
Code:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.senthistory);
lvhistory = (ListView) findViewById(android.R.id.list);
PopulateSentList();
}
public void PopulateSentList() {
String strquery = "SELECT * FROM sent_history";
Cursor Cursor = (MainscreenActivity.JEEMAAndroSMSDB).rawQuery(
strquery, null);
MyAdapter adapter = new MyAdapter(SentHistoryActivity.this, Cursor);
setListAdapter(adapter);
lvhistory.setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> arg0, View arg1,
int position, long arg3) {
// TODO Auto-generated method stub
SQLiteCursor selectedValue = (SQLiteCursor) getListAdapter()
.getItem(position);
String id1 = selectedValue.getString(0);
System.out.println("DATA-->>>" + id1);
Intent intent = new Intent(getApplicationContext(),
Historydisplay.class);
intent.putExtra("Id", id1);
final int result = 1;
startActivityForResult(intent, result);
}
});
}
public void onBackPressed() {
super.onBackPressed();
Intent intent = new Intent(SentHistoryActivity.this,
MainscreenActivity.class);
startActivity(intent);
finish();
}
private void CreateMenu(Menu menu) {
menu.setQwertyMode(true);
MenuItem mnu1 = menu.add(0, 0, 0, "Delete");
{
mnu1.setAlphabeticShortcut('D');
}
MenuItem mnu2 = menu.add(0, 0, 0, "Select All");
{
mnu2.setAlphabeticShortcut('S');
}
}
private boolean MenuChoice(MenuItem item) throws Exception {
switch (item.getItemId()) {
case 0:
int count = (int) getListAdapter().getCount();
for (int i = 1; i <= count; i++) {
if (this.lvhistory.isItemChecked(i)) {
listItems.remove(i);
adapter.notifyDataSetChanged();
MainscreenActivity.JEEMAAndroSMSDB.delete(
MainscreenActivity.Table_SentHistory, "_id=" +i, null);
finish();
Intent intent = new Intent(getApplicationContext(),
SentHistoryActivity.class);
startActivity(intent);
}
}
return true;
}
return false;
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
CreateMenu(menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
try {
return MenuChoice(item);
} catch (Exception e) {
e.printStackTrace();
}
return false;
}
private class MyAdapter extends ResourceCursorAdapter {
public MyAdapter(Context context, Cursor cur) {
super(context, R.layout.dummy, cur);
}
#Override
public View newView(Context context, Cursor cur, ViewGroup parent) {
LayoutInflater li = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
return li.inflate(R.layout.dummy, parent, false);
}
#Override
public void bindView(View view, Context context, Cursor cur) {
TextView tvListText = (TextView)view.findViewById(R.id.Mobile);
final CheckBox chkBox = (CheckBox)view.findViewById(R.id.check);
tvListText.setText(cur.getString(cur.getColumnIndex(MainscreenActivity.COL_Mobile)));
chkBox.setTag(cur.getString(cur.getColumnIndex(MainscreenActivity.COL_Sent_id)));
chkBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
#Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
// TODO Auto-generated method stub
Log.v("Checked", chkBox.getTag().toString());
}
});
}
}
For removing checked items you can use isChecked() method for CheckBox. In your code you can use in following manner.
chkBox.setOnClickListener(new new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
CheckBox cb = (CheckBox)v;
if(cb.isChecked() == true)
{
String getStrinValue = cb.getTExt().toString(); // here you will get the value of selected CheckBox
// And now you have to perform your deletion operation as usual.
}
}
Ok, i'll give an overview of how to accomplish. This is what i did for my application.
First you need to have a model class for the list item which has a property to maintain the state(checked), then whenever you are getting the items from the database create list of items, such as arraylist.
Then whenever the check box get checked change the state property of the particular list item. Finally when you click the delete from the menu, there would be three steps
Get the checked items from the arraylist
Remove items from the adapter
Remove items from the database
I think this would make sense
EDIT
Have you tried this previous SO question? BTW this will help only to remove the items from the adapter. You have to find a way to remove the items from the database.
Here's how i did. I found this to be the easiest solution to always match the right ID. Because the adapter and the cursor will always have the same counting and position. Both have a starting index at 0.
This is what's inside my case for the menu item.
I also added an alert dialog as a safety step.
if (mListView.getCount() == 0 || mListView.getCheckedItemCount() == 0) {
Toast.makeText(this, "Select an item by holding", Toast.LENGTH_SHORT).show();
return false;
}
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
builder.setMessage("Are you sure you want to delete these items?");
builder.setCancelable(true);
builder.setPositiveButton(
"Yes",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
SparseBooleanArray selection = mListView.getCheckedItemPositions();
Cursor data = mDBHandler.getAllIDs(); // "SELECT " + COLUMN_ID + " FROM " + TABLE_NAME;
int itemID;
int itemCount = arrayAdapter.getCount();
for (int i=itemCount-1; i >= 0; i--) {
if (selection.get(i)) {
data.moveToPosition(i);
itemID = data.getInt(data.getColumnIndexOrThrow("id")); // COLUMN_ID = "id"
mDBHandler.deleteItem(itemID);
}
}
selection.clear();
updateListView();
dialog.cancel();
}
});
builder.setNegativeButton(
"No",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});
AlertDialog alertDelete = builder.create();
alertDelete.show();
return true;
public void updateListView() {
mListView.setAdapter(arrayAdapter);
Cursor data = mDBHandler.getItems();
arrayList.clear();
while (data.moveToNext()) {
arrayList.add(data.getString(1));
}
arrayAdapter.notifyDataSetChanged();
}

Categories

Resources