public class NewFriendsListFragment extends SherlockListFragment implements
LoaderManager.LoaderCallbacks<Cursor> {
int monthchange, daychange;
Dialog dialog;
int pos;
CheckedTextView ctv_name;
private SimpleCursorAdapter mAdapter=null;
private SQLiteCursorLoader loader=null;
String mCurFilter;
private static Handler responseHandler;
boolean loaded=false;
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
//some more stuff...
setHasOptionsMenu(true);
mAdapter = new FriendListSCA(getSherlockActivity().getApplicationContext(),
R.layout.friend_item, null,null, null, null, null, NAME),
new String[]{NAME,MONTH,UID}, new int[]{R.id.name,R.id.info,R.id.profile_pic});
setListAdapter(mAdapter);
setListShown(false);
registerForContextMenu(getListView());
getLoaderManager().initLoader(0, null, this);
responseHandler = new Handler()
{
//handler code
};
}
public Loader<Cursor> onCreateLoader(int loaderId, Bundle args) {
//loader code
return(loader);
}
public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) {
mAdapter.changeCursor(cursor);
// Showin List
if (isResumed()) {
setListShown(true);
} else {
setListShownNoAnimation(true);
}
}
public void onLoaderReset(Loader<Cursor> loader) {
mAdapter.changeCursor(null);
}
@Override
public boolean onContextItemSelected(android.view.MenuItem item) {
AdapterContextMenuInfo info;
try {
info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
} catch (ClassCastException e) {
return false;
}
pos=info.position;
switch (item.getItemId()) {
case R.id.edit_item:
show_dialog();
return true;
}
return(super.onOptionsItemSelected(item));
}
@Override
public void onListItemClick(ListView l, View v, final int position, long id) {
Log.e("onListItemClick","Inside onListItemClick");
ContentValues cv= new ContentValues();
//MORE CODE
loader.update(TABLE_NAME_INCLUDE, cv, _ID+" = ?", new String[]{Integer.toString(position)});
}
private class FriendListSCA extends SimpleCursorAdapter
{
public FriendListSCA(Context context, int layout, Cursor c,
String[] from, int[] to) {
super(context, layout, c, from, to,0);
setViewBinder(new FriendsListDataViewBinder());
}
}
public class FriendsListDataViewBinder implements SimpleCursorAdapter.ViewBinder
{
//_ID + "," + UID+","+NAME+","+MONTH+","+DAY+","+WISH
@Override
public boolean setViewValue(View view, Cursor c, int columnIndex)
{
switch (view.getId())
{
case R.id.name:
CheckedTextView ctv= (CheckedTextView)view;
ctv.setText(c.getString(2));
if(c.getInt(5)==0 || c.getInt(4)==-1)
{
ctv.setPaintFlags(ctv.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
ctv.setChecked(false);
}
else
{
ctv.setPaintFlags(ctv.getPaintFlags() & (~ Paint.STRIKE_THRU_TEXT_FLAG));
ctv.setChecked(true);
}
return true;
case R.id.info:
if(c.getInt(4)!=-1)
{
((TextView)view).setText(Utility.MONTH_NAME[c.getInt(3)-1] + " " + Integer.toString(c.getInt(4)));
}
else
{
((TextView)view).setText("Tap and hold to manually enter");
}
return true;
case R.id.profile_pic:
if(!loaded)
return true;
((ImageView)view).setImageBitmap(Utility.model.getImage(
Long.toString( c.getLong(1) ), getURL(c.getLong(1)) ));
return true;
}
return false;
}
}
private void show_dialog()
{
//DATE PICKER CODE
okay.setOnClickListener(new Button.OnClickListener() {
@Override
public void onClick(View v)
{
ContentValues cv=new ContentValues();
cv.put(MONTH, monthchange);
cv.put(DAY, daychange);
loader.update(TABLE_NAME_INCLUDE, cv, _ID+" = ?" , new String[]{Integer.toString(pos)});
//getLoaderManager().restartLoader(0, null, NewFriendsListFragment.this);
//I tried calling restart loader, but nothing, when I checked
//it turned out the sqlite database wasn't being updated
responseHandler.sendEmptyMessage(1); //just dismisses dialog
}
});
dialog.show();
}
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
// Place an action bar item for searching.
MenuItem item = menu.add("Search");
item.setIcon(android.R.drawable.ic_menu_search);
item.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
View searchView = SearchViewCompat.newSearchView(getActivity());
if (searchView != null) {
SearchViewCompat.setOnQueryTextListener(searchView,
new OnQueryTextListenerCompat() {
@Override
public boolean onQueryTextChange(String filtext) {
mCurFilter = !TextUtils.isEmpty(filtext) ? filtext : null;
getLoaderManager().restartLoader(0, null, NewFriendsListFragment.this);
return true;
}
});
item.setActionView(searchView);
}
}
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
// TODO Auto-generated method stub
}
}
私は ActionBarSherlock ライブラリの SherlockListFragment を使用して、CommonsWare Loaderex sqlite カーソル ローダーを使用してリストを表示しています。 loader.update(...) を使用してテーブル内のデータを更新するには、呼び出しても何も起こりません。どうしたの?