1. Enter Android XML Layout:
Paste in your Android XML Layout code
2. Pick your Views:
Select the views that you need to interact with
3. Get your Java code:
Click on the code to select the entire text
public class MyCursorAdapter extends CursorAdapter {
private static class ViewHolder {
public final RelativeLayout rootView;
public final RelativeLayout RLayout;
public final TextView lblComments;
public final EditText txtComments;
public final Button btnSave;
public final Button btnCancel;
private ViewHolder(RelativeLayout rootView, RelativeLayout RLayout, TextView lblComments, EditText txtComments, Button btnSave, Button btnCancel) {
this.rootView = rootView;
this.RLayout = RLayout;
this.lblComments = lblComments;
this.txtComments = txtComments;
this.btnSave = btnSave;
this.btnCancel = btnCancel;
}
public static ViewHolder create(RelativeLayout rootView) {
RelativeLayout RLayout = (RelativeLayout)rootView.findViewById( R.id.RLayout );
TextView lblComments = (TextView)rootView.findViewById( R.id.lblComments );
EditText txtComments = (EditText)rootView.findViewById( R.id.txtComments );
Button btnSave = (Button)rootView.findViewById( R.id.btnSave );
Button btnCancel = (Button)rootView.findViewById( R.id.btnCancel );
return new ViewHolder( rootView, RLayout, lblComments, txtComments, btnSave, btnCancel );
}
}
@Override
public void bindView(View view, Context context, Cursor cursor) {
ViewHolder vh = (ViewHolder)view.getTag();
// Bind your data to the views here
}
@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
View view = inflater.inflate( R.layout.listitem, parent, false );
view.setTag( ViewHolder.create( (RelativeLayout)view ) );
return view;
}
private LayoutInflater inflater;
// Constructors
public MyCursorAdapter(Context context, Cursor c, boolean autoRequery) {
super(context, c, autoRequery);
this.inflater = LayoutInflater.from( context );
}
public MyCursorAdapter(Context context, Cursor c, int flags) {
super(context, c, flags);
this.inflater = LayoutInflater.from( context );
}
}
