Android - Coding onActivityResult for embedded startActivityresult in
custom CursorAdapter
Within my project I have an activity with a multi-column ListView. This
ListView draws its data from a custom CursorAdapter that I've implemented
in a separate java module. I have listeners on a couple of the views
within the ListView's rows, and these are implemented within the
CursorAdapter. One of the listeners needs to edit the view content that
called it and save the data back to the underlying database.
Based on advice received here I've managed to code the
startActivityForResult. However, I can't find how or where to code the
onActivityResult routine in order to process the response from the dialog
activity. Has anyone any advice?
public class CustomCursorAdapter extends CursorAdapter {
private static final String TAG = CustomCursorAdapter.class.getSimpleName();
private static final int EDIT_TIME_REQUEST_CODE = 11;
protected static class RowViewHolder {
public Button btnLap;
public TextView tvTime;
public Context ctx;
}
public CustomCursorAdapter(Context context, Cursor c) {
super(context, c);
}
@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
LayoutInflater inflater = LayoutInflater.from(parent.getContext());
View retView = inflater.inflate(R.layout.single_row_item, parent, false);
RowViewHolder holder = new RowViewHolder();
holder.btnLap = (Button) retView.findViewById(R.id.btn_lap);
holder.tvTime = (TextView) retView.findViewById(R.id.tv_time);
holder.ctx = context;
holder.btnLap.setOnClickListener(btnLapOnClickListener);
holder.tvTime.setOnClickListener(tvTimeOnClickListener);
retView.setTag(holder);
return retView;
}
...
private OnClickListener tvTimeOnClickListener = new OnClickListener() {
@Override
public void onClick(View v) {
TextView tv = (TextView) v;
String strTime = tv.getText().toString();
// get the RowViewHolder
RowViewHolder holder = new RowViewHolder();
holder = (RowViewHolder) ((View) v.getParent()).getTag();
Intent intentTimeEdit = new Intent(holder.ctx,
TimeEditDialog.class);
intentTimeEdit.putExtra("Time", strTime);
// Set up intent to pass to dialog
((Activity)holder.ctx).startActivityForResult(intentTimeEdit,
EDIT_TIME_REQUEST_CODE);
}
}
};
}
No comments:
Post a Comment