Advertisement
Guest User

Untitled

a guest
Mar 28th, 2017
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.46 KB | None | 0 0
  1. public class ProfListFragment extends Fragment{
  2. public static final String LC = "LIFECYCLE";
  3. private Context mContext;
  4. public static Context c;
  5. public static ProfListAdapter adapter;
  6. private SQLiteDatabase mDatabase;
  7. HashMap<Integer, String> mData = new HashMap<Integer, String>();
  8. private int[] profIds;
  9. private OnProfSelected mListener;
  10. public static ProfListFragment newInstance(){
  11. return new ProfListFragment();
  12. }
  13. @Override
  14. public void onAttach(Context context){
  15. System.out.println("do I ever get called");
  16. super.onAttach(context);
  17. mListener = (OnProfSelected) context;
  18. updateList();
  19. }
  20.  
  21. @Override
  22. public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){
  23. final View view = inflater.inflate(R.layout.prof_list, container, false);
  24. final Activity activity = getActivity();
  25. final RecyclerView recyclerView = (RecyclerView) view.findViewById(R.id.list_view);
  26. recyclerView.setLayoutManager(new LinearLayoutManager(activity));
  27. adapter = new ProfListAdapter(activity);
  28. recyclerView.setAdapter(adapter);
  29. return view;
  30. }
  31.  
  32. class ProfListAdapter extends RecyclerView.Adapter<ViewHolder>{
  33. private LayoutInflater mLayoutInflater;
  34. public ProfListAdapter(Context context) {
  35. mLayoutInflater = LayoutInflater.from(context);
  36. }
  37. @Override
  38. public ViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType){
  39. return new ViewHolder(mLayoutInflater
  40. .inflate(R.layout.recycler_view, viewGroup, false));
  41. }
  42.  
  43.  
  44. @Override
  45. public void onBindViewHolder(ViewHolder viewHolder, final int position){
  46. System.out.println(position);
  47. final String profName;
  48. Integer k = 0;
  49. for (Integer key : mData.keySet()) {
  50. viewHolder.setData(mData.get(key));
  51. }
  52.  
  53.  
  54. viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
  55. @Override
  56. public void onClick(View v){
  57. Intent intent = ProfPager.newIntent(getActivity(), position);
  58. startActivity(intent);
  59. }
  60. });
  61. }
  62. @Override
  63. public int getItemCount() {
  64. return mData.size();
  65. }
  66. }
  67.  
  68. class ViewHolder extends RecyclerView.ViewHolder {
  69. private TextView mTextView;
  70. private ViewHolder(View itemView){
  71. super(itemView);
  72. mTextView = (TextView) itemView.findViewById(R.id._prof); // galleryimage
  73. }
  74. private void setData(String profName){
  75. mTextView.setText(profName);
  76. System.out.println("setData" + profName);
  77. }
  78. }
  79.  
  80.  
  81. private ProfCursorWrapper query (String whereClause, String[] whereArgs) {
  82. Cursor cursor = mDatabase.query (Schema.ProfessorTable.NAME,null,whereClause,whereArgs,null,null,null);
  83. return new ProfCursorWrapper (cursor);
  84. }
  85.  
  86.  
  87.  
  88. public interface OnProfSelected {
  89. void OnProfSelected(int profId);
  90. }
  91.  
  92. public void updateList(){
  93. mDatabase = new DBHelper (getActivity()).getWritableDatabase();
  94. //DBHelper.remove(mContext);
  95. ProfCursorWrapper cursor = query(/*StudTable.Cols.ID+"=\"99999999\""*/null, null); //cursor= where I am in the database
  96. cursor.moveToFirst();
  97. while (!cursor.isAfterLast()) {
  98. Accessors accr = cursor.getStuff();
  99. System.out.println(accr.getDBID() + " " + accr.getName() + " " + accr.getDept() + " " + accr.getOffice() + " " + accr.getEmail());
  100. //data.add(accr.getDBID());
  101. mData.put(accr.getDBID(), accr.getName());
  102. cursor.moveToNext();
  103. }
  104. cursor.close();
  105. }
  106. @Override
  107. public void onStart() {
  108. Log.d (LC,"onStart");
  109. super.onStart();
  110. }
  111. @Override
  112. public void onPause() {
  113. Log.d (LC,"onPause");
  114. super.onPause();
  115. }
  116. @Override
  117. public void onResume() {
  118. Log.d (LC,"onResume");
  119. super.onResume();
  120. mData.clear();
  121. updateList();
  122. adapter.notifyDataSetChanged();
  123. }
  124. @Override
  125. public void onDestroy() {
  126. Log.d (LC,"onDestroy");
  127. super.onDestroy();
  128. }
  129. @Override
  130. public void onStop() {
  131. Log.d (LC,"onStop");
  132. super.onStop();
  133. }
  134. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement