android invoking activity from a multi-column listview
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. This editing
needs to startActivityForResult (as a custom dialog). However I get an
error as an activity can only be invoked from another activity. I have
tried moving the startActivityForResult to a procedure in the parent
activity, but this has then to be a static procedure to be called from the
listener and I get an error as startActivityForResult can't be in a static
process. Te error is "The method startActivityForResult(Intent, int) is
undefined for the type new View.OnClickListener(){}"
Has anyone a process for invoking an activity from a view listener where
the view in a row element of a ListView?
The code below is the process I'm using in my CursorAdapter.
public class CustomCursorAdapter extends CursorAdapter {
protected static class RowViewHolder {
public Button btnLap;
public TextView tvTime;
}
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.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();
Intent intentTimeEdit = new Intent(getBaseContext(),
TimeEditDialog.class);
intentTimeEdit.putExtra("Time", strTime);
startActivityForResult(intentTimeEdit, EDIT_TIME_REQUEST_CODE);
}
};
No comments:
Post a Comment