Can someone offer me some insight to redraw the list view? On a delete, I want it to rebuild.
Chris.
public void onCreate(Bundle bundle)
{
super.onCreate(bundle);
//setContentView(R.layout.findlist);
//getListView().setEmptyView(findViewById(R.id.empty));
mDbHelper = new DBHelper(this);
mDbHelper.open();
cursor = mDbHelper.fetchAllLocations();
startManagingCursor(cursor);
mAdapter = new myListAdapter(this);
setListAdapter(mAdapter);
}
public class myListAdapter extends BaseAdapter {
public myListAdapter(Context c) { ...
public int getCount() { ...
public Object getItem(int position) { ...
public long getItemId(int position) { ...
@Override
public View getView(int position, View convertView, ViewGroup parent) {
cursor.moveToPosition(position);
RowView rv;
if (convertView == null) {
rv = new RowView(mContext,(cursor.getString(2)),
(cursor.getString(5)), position);
} else {
rv = (RowView) convertView;
rv.setTitle(cursor.getString(2));
rv.setDialogue(cursor.getString(5));
rv.setFocusable(true);
rv.setClickable(true);
}
return rv;
}
}
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
// TODO Auto-generated method stub
super.onListItemClick(l, v, position, id);
// Do what you will need to w/ a List Row Click
Intent h = new Intent(FindList.this,showmaplocation.class);
startActivityForResult(h,SAVE_TABS);
}
private class RowView extends LinearLayout {
public RowView(Context context, String title, String words, int position) {
super(context);
this.setOrientation(VERTICAL);
// Here we build the child views in code. They could also have
// been specified in an XML file.
mTitle = new TextView(context);
mTitle.setText(title);
addView(mTitle, new LinearLayout.LayoutParams(
LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
mDialogue = new TextView(context);
mDialogue.setText(words);
addView(mDialogue, new LinearLayout.LayoutParams(
LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
Button mButton = new Button(context);
mButton.setFocusable(false);
mButton.setId(position);
addView(mButton, new LinearLayout.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
currentPosition = position;
Button button = (Button)findViewById(position);
button.setOnClickListener(mDeleteListener);
}
private OnClickListener mDeleteListener = new OnClickListener()
{
public void onClick(View v)
{
// To send a result, simply call setResult() before your
// activity is finished, building an Intent with the data
// you wish to send.
Intent data = new Intent();
data.setAction("Corky!");
setResult(RESULT_OK, data);
// finish();
cursor.moveToPosition(v.getId());
mDbHelper.deleteLocation(cursor.getInt(0));
// mAdapter.remove()
mAdapter.notifyDataSetChanged();
setListAdapter(mAdapter);
Toast mToast;
mToast = Toast.makeText(FindList.this, "Deleted" ,
Toast.LENGTH_LONG);
mToast.show();
}
};
/**
* Convenience method to set the title of a SpeechView
*/
public void setTitle(String title) {
mTitle.setText(title);
}
/**
* Convenience method to set the dialogue of a SpeechView
*/
public void setDialogue(String words) {
mDialogue.setText(words);
}
private TextView mTitle;
private TextView mDialogue;
}
}