Created
July 20, 2016 15:57
-
-
Save samtstern/e08eec46b363d536f5c3c61f8696862a to your computer and use it in GitHub Desktop.
FirebaseRecyclerAdapter - ViewHolder with Context
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class HomeActivity extends Activity implements TodoListener { | |
private MyRecyclerAdapter mAdapter; | |
// ... | |
@Override | |
public void onCreate(Bundle savedInstanceState) { | |
// ... | |
mAdapter.setListener(this); | |
} | |
@Override | |
public void onDoneClick(TodoMasterModel model, int action) { | |
// Do your click action here | |
// ... | |
} | |
@Override | |
public void showAddEditDialog(TodoMasterModel model, int action) { | |
// Do your edit action here | |
// ... | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MyRecyclerAdapter extends FirebaseRecyclerAdapter<TodoMasterModel, TodoViewHolder> { | |
private TodoListener mListener; | |
// ... | |
public setListener(TodoListener listener) { | |
this.mListener = listener; | |
} | |
@Override | |
protected void populateViewHolder(TodoViewHolder viewHolder, TodoMasterModel model, int position) { | |
// ... | |
viewHolder.setListener(mListener); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface TodoListener { | |
void onDoneClick(TodoMasterModel model, int action); | |
void showAddEditDialog(TodoMasterModel model, int action); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class TodoViewHolder extends RecyclerView.ViewHolder { | |
private TodoListener mListener; | |
// ... | |
public setListener(TodoListener listener) { | |
this.mListener = listener; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment