TimePickerDialogFragment with Adapter (Android Studio)

Hello All,

Salam Super untuk semuanya, saya ingin bertanya berhubung saya newbie dalam membuat aplikasi Android, dibawah adalah source yang saya gunakan, saya akan membuat TimePickerDialogFragment dengan library yang saya gunakan https://github.com/code-troopers/android-betterpickers , akan tetapi saya kesulitan untuk memunculkan TimePickernya, ada yang bisa membantu saya ?? solusi apa yang harus saya gunakan dan bagaimana?

 

Terima Kasih

 

package com.example.verry.preventivecleaning.adapter;

import android.app.Dialog;
import android.app.TimePickerDialog;
import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.nfc.Tag;
import android.support.v4.app.FragmentManager;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.codetroopers.betterpickers.timepicker.TimePickerBuilder;
import com.codetroopers.betterpickers.timepicker.TimePickerDialogFragment;
import com.example.verry.preventivecleaning.R;
import com.example.verry.preventivecleaning.db.SQLiteDB;
import com.example.verry.preventivecleaning.listener.RecyclerItemClickListener;
import com.example.verry.preventivecleaning.model.JobDeskDetailModel;
import com.example.verry.preventivecleaning.model.JobDeskModel;
import com.example.verry.preventivecleaning.view.InputJobdesk;
import com.example.verry.preventivecleaning.view.MainActivity;
import com.example.verry.preventivecleaning.widget.LetterTile;
import com.github.aakira.expandablelayout.ExpandableLinearLayout;

import org.w3c.dom.Text;

import java.util.ArrayList;
import java.util.List;

public class JobDeskDetailAdapter extends RecyclerView.Adapter<JobDeskDetailAdapter.JobDeskDetailHolder>{

    private SQLiteDB sqLiteDB;
    private List<JobDeskDetailModel> jobDeskDetailModelList;
    private Context context;
    private RecyclerItemClickListener recyclerItemClickListener;
    //JobDeskDetailModel jobDeskDetailModel;

    public JobDeskDetailAdapter (Context context){
        this.context = context;
        this.jobDeskDetailModelList = new ArrayList<>();
    }

    private void add(JobDeskDetailModel jobDeskDetailModel){
        jobDeskDetailModelList.add(jobDeskDetailModel);
        notifyItemInserted(jobDeskDetailModelList.size() - 1);
    }

    public void addAll(List<JobDeskDetailModel> jobDeskDetailModelList){
        for (JobDeskDetailModel contactModel : jobDeskDetailModelList){
            add(contactModel);
        }
    }

    public void remove(JobDeskDetailModel jobDeskDetailModel){
        int position = jobDeskDetailModelList.indexOf(jobDeskDetailModel);
        if (position > -1){
            jobDeskDetailModelList.remove(position);
            notifyItemRemoved(position);
        }
    }

    public void clear(){
        while (getItemCount() > 0){
            remove(getItem(0));
        }
    }

    public JobDeskDetailModel getItem(int position){

        return jobDeskDetailModelList.get(position);
    }

    @Override
    public JobDeskDetailHolder onCreateViewHolder(ViewGroup viewGroup, int viewType){
        View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.list_detail_jobdesk, viewGroup, false);
        sqLiteDB = new SQLiteDB(this.context);
        final JobDeskDetailHolder jobDeskDetailHolder = new JobDeskDetailHolder(view);

        jobDeskDetailHolder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                int adapterPos = jobDeskDetailHolder.getAdapterPosition();
                if (adapterPos != RecyclerView.NO_POSITION){
                    if (recyclerItemClickListener != null){
                        recyclerItemClickListener.onItemClick(adapterPos, jobDeskDetailHolder.itemView);
                    }
                }
            }
        });
        return jobDeskDetailHolder;
    }

    @Override
    public void onBindViewHolder(JobDeskDetailHolder jobDeskDetailHolder, int position){
        final JobDeskDetailModel jobDeskDetailModel = jobDeskDetailModelList.get(position);
        jobDeskDetailHolder.setIsRecyclable(false);
        final Resources resources = context.getResources();
        int titleSize = resources.getDimensionPixelSize(R.dimen.letter_tile_size);

        jobDeskDetailHolder.namaJobdesk.setText(jobDeskDetailModel.getNameJobDesk());
        jobDeskDetailHolder.jamMulai.setText(jobDeskDetailModel.getJammulai());
        jobDeskDetailHolder.jamSelesai.setText(jobDeskDetailModel.getJamselesai());

    }

    @Override
    public int getItemCount() {

        return jobDeskDetailModelList.size();
    }

    public void setOnItemClickListener(RecyclerItemClickListener recyclerItemClickListener) {
        this.recyclerItemClickListener = recyclerItemClickListener;
    }

    public static class JobDeskDetailHolder extends RecyclerView.ViewHolder{

        TextView namaJobdesk;
        TextView jamMulai;
        TextView jamSelesai;


        public JobDeskDetailHolder(View itemView) {
            super(itemView);

            namaJobdesk = (TextView) itemView.findViewById(R.id.namaJobdesk);
            jamMulai = (TextView) itemView.findViewById(R.id.jamMulai);
            jamSelesai = (TextView) itemView.findViewById(R.id.jamSelesai);
        }
    }

    public static class InputWaktu extends BaseAdapter implements TimePickerDialogFragment.TimePickerDialogHandler {

        private TimePickerBuilder mTimePickerBuilder;
        private LayoutInflater mInflater;
        private ViewHolder holder;

        public InputWaktu(Context context, FragmentManager fm) {
            super();
            mInflater = LayoutInflater.from(context);
            mTimePickerBuilder = new TimePickerBuilder()
                    .setFragmentManager(fm)
                    .setStyleResId(R.style.BetterPickersDialogFragment_Light);
        }

        private class ViewHolder {
            ImageView inputJm;
            ImageView inputJs;
        }

        @Override
        public void onDialogTimeSet(int reference, int hourOfDay, int minute) {

        }

        @Override
        public int getCount() {
            return 0;
        }

        @Override
        public Object getItem(int i) {
            return null;
        }

        @Override
        public long getItemId(int i) {
            return 0;
        }

        @Override
        public View getView(final int position, View Convertview, ViewGroup parent) {
            View view = Convertview;
            if (view == null){
                view = mInflater.inflate(R.layout.list_detail_jobdesk, parent, false);
                ViewHolder holder = new ViewHolder();
                holder.inputJm = (ImageView)view.findViewById(R.id.waktuJm);
                holder.inputJs = (ImageView)view.findViewById(R.id.waktuJs);
                view.setTag(holder);
            } else {
                holder = (ViewHolder) view.getTag();
            }
            holder.inputJm.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    mTimePickerBuilder.setReference(position);
                    mTimePickerBuilder.addTimePickerDialogHandler(InputWaktu.this);
                    mTimePickerBuilder.show();
                }
            });
            holder.inputJs.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    mTimePickerBuilder.setReference(position);
                    mTimePickerBuilder.addTimePickerDialogHandler(InputWaktu.this);
                    mTimePickerBuilder.show();
                }
            });
            return view;
        }
    }
}
TK Ditanyakan on 8 May 2018 pada Android.
Tambah Komentar
0 Jawaban
  • Jawaban Anda

    Dengan memposting jawaban, anda setuju dengan Kebijakan Privasi dan ketentuan layanan.