Hi,
I created a ListView that contains a row which in turn contain text and a button. The idea is to have the button function as a delete button to remove the row from the list as well as the database.
I order to do this I created an adapter to handle the button click. This code is below. Deleting the database record works fine, but I have not yet succeeded in refreshing the ListView so the record will no longer be displayed.
public class FeedArrayAdapter extends ArrayAdapter {
private ARssEReaderDBAdapter dba;
private String TAG = "FeedArrayAdapter";
private View v;
private ListView feedList;
private OnClickListener btnDeleteFeedListener = new OnClickListener(){
public void onClick(View pView) {
dba = new ARssEReaderDBAdapter(getContext());
Integer objInt = (Integer) pView.getTag();
dba.open();
dba.deleteFeed(objInt);
dba.close();
Log.w(TAG, "Database row, " + pView.getTag() + " got clicked.");
}
};
public FeedArrayAdapter(Context context, int textViewResourceId, List<Feed> items) {
super(context, textViewResourceId, items);
}
@Override
public View getView(int position, View convertView, ViewGroup parent){
Log.w(TAG, "getView");
v = convertView;
if (v == null) {
LayoutInflater vi = (LayoutInflater)getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = vi.inflate(R.layout.feedlistrow, null);
}
Feed feed = getItem(position);
if (feed != null){
v.setTag(feed.getFeedId());
TextView title = (TextView)v.findViewById(R.id.TextView01);
if (title != null){
title.setText(feed.getTitle());
}
Button btnDelete = (Button)v.findViewById(R.id.btnDelete);
btnDelete.setTag(feed.getFeedId());
btnDelete.setOnClickListener(btnDeleteFeedListener); //
}
return v;
}
}
Any help is greatly appreciated.
Richard