Created
August 21, 2013 15:17
-
-
Save lithid/6295819 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
##### | |
# OnClick | |
##### | |
mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() { | |
@Override | |
public void onItemClick(AdapterView<?> parent, View view, int position, long id) { | |
new MessageTable(mContext).deleteItem(mMessageArray.get(position)[MESSAGE_ID]); | |
new MessageLoader().execute(); | |
} | |
}); | |
##### | |
# Loader | |
##### | |
class MessageLoader extends AsyncTask<String, String, ArrayList<String[]>> { | |
@Override | |
protected void onPreExecute() { | |
mListView.invalidateViews(); | |
} | |
@Override | |
protected ArrayList<String[]> doInBackground(String... params) { | |
return new MessageTable(mContext).getAllCurrentThreads(); | |
} | |
@Override | |
protected void onPostExecute(ArrayList<String[]> list) { | |
messages.clear(); | |
messages.addAll(list); | |
mAdapter.notifyDataSetChanged(); | |
mListView.invalidateViews(); | |
if (messages.size() > 0) { | |
// Show List | |
} else { | |
// Hide list | |
} | |
} | |
} | |
##### | |
# Database object | |
##### | |
public ArrayList<String[]> getAllCurrentThreads() { | |
ArrayList<String[]> list = new ArrayList<String[]>(); | |
open(); | |
Cursor c; | |
c = database.query(TABLE, new String[]{"*"}, null, null, null, null, DBHelper.C_DATE + " DESC"); | |
if (c.moveToFirst()) { | |
int count = c.getCount(); | |
for (int i = 0; i < count; i++) { | |
int str_length = DBHelper.MESSAGE_TABLE_ENTRIES.length; | |
String[] items = new String[str_length]; | |
for (int x=0; x < str_length; x++) { | |
items[x] = c.getString( | |
c.getColumnIndex(DBHelper.MESSAGE_TABLE_ENTRIES[x]) | |
); | |
} | |
list.add(items); | |
c.moveToNext(); | |
} | |
} | |
close(); | |
return list; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment