Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class ProfListFragment extends Fragment{
- public static final String LC = "LIFECYCLE";
- private Context mContext;
- public static Context c;
- public static ProfListAdapter adapter;
- private SQLiteDatabase mDatabase;
- HashMap<Integer, String> mData = new HashMap<Integer, String>();
- private int[] profIds;
- private OnProfSelected mListener;
- public static ProfListFragment newInstance(){
- return new ProfListFragment();
- }
- @Override
- public void onAttach(Context context){
- System.out.println("do I ever get called");
- super.onAttach(context);
- mListener = (OnProfSelected) context;
- updateList();
- }
- @Override
- public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){
- final View view = inflater.inflate(R.layout.prof_list, container, false);
- final Activity activity = getActivity();
- final RecyclerView recyclerView = (RecyclerView) view.findViewById(R.id.list_view);
- recyclerView.setLayoutManager(new LinearLayoutManager(activity));
- adapter = new ProfListAdapter(activity);
- recyclerView.setAdapter(adapter);
- return view;
- }
- class ProfListAdapter extends RecyclerView.Adapter<ViewHolder>{
- private LayoutInflater mLayoutInflater;
- public ProfListAdapter(Context context) {
- mLayoutInflater = LayoutInflater.from(context);
- }
- @Override
- public ViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType){
- return new ViewHolder(mLayoutInflater
- .inflate(R.layout.recycler_view, viewGroup, false));
- }
- @Override
- public void onBindViewHolder(ViewHolder viewHolder, final int position){
- System.out.println(position);
- final String profName;
- Integer k = 0;
- for (Integer key : mData.keySet()) {
- viewHolder.setData(mData.get(key));
- }
- viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v){
- Intent intent = ProfPager.newIntent(getActivity(), position);
- startActivity(intent);
- }
- });
- }
- @Override
- public int getItemCount() {
- return mData.size();
- }
- }
- class ViewHolder extends RecyclerView.ViewHolder {
- private TextView mTextView;
- private ViewHolder(View itemView){
- super(itemView);
- mTextView = (TextView) itemView.findViewById(R.id._prof); // galleryimage
- }
- private void setData(String profName){
- mTextView.setText(profName);
- System.out.println("setData" + profName);
- }
- }
- private ProfCursorWrapper query (String whereClause, String[] whereArgs) {
- Cursor cursor = mDatabase.query (Schema.ProfessorTable.NAME,null,whereClause,whereArgs,null,null,null);
- return new ProfCursorWrapper (cursor);
- }
- public interface OnProfSelected {
- void OnProfSelected(int profId);
- }
- public void updateList(){
- mDatabase = new DBHelper (getActivity()).getWritableDatabase();
- //DBHelper.remove(mContext);
- ProfCursorWrapper cursor = query(/*StudTable.Cols.ID+"=\"99999999\""*/null, null); //cursor= where I am in the database
- cursor.moveToFirst();
- while (!cursor.isAfterLast()) {
- Accessors accr = cursor.getStuff();
- System.out.println(accr.getDBID() + " " + accr.getName() + " " + accr.getDept() + " " + accr.getOffice() + " " + accr.getEmail());
- //data.add(accr.getDBID());
- mData.put(accr.getDBID(), accr.getName());
- cursor.moveToNext();
- }
- cursor.close();
- }
- @Override
- public void onStart() {
- Log.d (LC,"onStart");
- super.onStart();
- }
- @Override
- public void onPause() {
- Log.d (LC,"onPause");
- super.onPause();
- }
- @Override
- public void onResume() {
- Log.d (LC,"onResume");
- super.onResume();
- mData.clear();
- updateList();
- adapter.notifyDataSetChanged();
- }
- @Override
- public void onDestroy() {
- Log.d (LC,"onDestroy");
- super.onDestroy();
- }
- @Override
- public void onStop() {
- Log.d (LC,"onStop");
- super.onStop();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement