2016-05-25 7 views
1

Я раздуваю мой вид карты через свой пользовательский адаптер recyclerview. Теперь я хочу знать, как я могу настроить прослушиватель кликов из моего класса adpater на su, mo, tu, we, th, fr, sa position wise.Как установить onclicklistener на карте?

Я хочу, чтобы массив, как если бы пользователь нажал вс, пн, вт на 0 позиции cardview то массив должен быть следующим образом [1,2,3]

и на 1-й позиции пользователь нажал мы, е, fr, тогда я должен получить следующий массив следующим образом: [4,5,6]

В настоящее время из моего адаптера я взял ссылки на это текстовое представление и добавил прослушиватель, но я получаю такой же массив для обоих поведений, даже если выбор отличается.

Мой класс адаптера a следует.

public class Adapter1 extends RecyclerView.Adapter { 


private final int VIEW_ITEM = 1; 
private final int VIEW_PROG = 0; 


private List<String> myDataSet; 
private static String KEY1; 
// The minimum amount of items to have below your current scroll position 
// before loading more. 
private int visibleThreshold = 5; 
private int lastVisibleItem, totalItemCount; 
private boolean loading; 
private OnLoadMoreListener onLoadMoreListener; 
private static String TAG = "DATA_ADAPTER"; 
private static ArrayList<String> mSavedTime = new ArrayList<String>(); 
private static ArrayList<String> mTimeUnit = new ArrayList<>(); 
private static String mCurrentHour; 
private static String mCurrentMinute; 

private static Context context; 




public AlarmAdapter(Context context, RecyclerView recyclerView, ArrayList<String> mTime, ArrayList<String> mTimeUnit, String mCurrentHour, String mCurrentMinute) { 


    this.mSavedTime = mTime; 
    this.mTimeUnit = mTimeUnit; 
    this.mCurrentHour = mCurrentHour; 
    this.mCurrentMinute = mCurrentMinute; 

    this.context = context; 
    if (recyclerView.getLayoutManager() instanceof LinearLayoutManager) { 

     final LinearLayoutManager linearLayoutManager = (LinearLayoutManager) recyclerView 
       .getLayoutManager(); 


     recyclerView 
       .addOnScrollListener(new RecyclerView.OnScrollListener() { 
        @Override 
        public void onScrolled(RecyclerView recyclerView, 
              int dx, int dy) { 
         super.onScrolled(recyclerView, dx, dy); 

         totalItemCount = linearLayoutManager.getItemCount(); 
         lastVisibleItem = linearLayoutManager 
           .findLastVisibleItemPosition(); 
         if (!loading 
           && totalItemCount <= (lastVisibleItem + visibleThreshold)) { 
          // End has been reached 
          // Do something 
          if (onLoadMoreListener != null) { 
           onLoadMoreListener.onLoadMore(); 
          } 
          loading = true; 
         } 
        } 
       }); 
    } 
} 

@Override 
public int getItemViewType(int position) { 
    return mSavedTime.get(position) != null ? VIEW_ITEM : VIEW_PROG; 
} 

@Override 
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, 
                int viewType) { 
    RecyclerView.ViewHolder vh; 


    if (viewType == VIEW_ITEM) { 
     View v = LayoutInflater.from(parent.getContext()).inflate(
       R.layout.saved_alarm_card, parent, false); 

     vh = new StudentViewHolder(v); 

    } else { 
     View v = LayoutInflater.from(parent.getContext()).inflate(
       R.layout.more_progress_item, parent, false); 

     vh = new ProgressViewHolder(v); 
    } 

    return vh; 
} 

@Override 
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { 
    if (holder instanceof StudentViewHolder) { 


     ((StudentViewHolder) holder).mTimeDigitText.setText(mSavedTime.get(position)); 
     ((StudentViewHolder) holder).mTimeUnitText.setText(mTimeUnit.get(position)); 
     // ((StudentViewHolder) holder).dateField.setText(mFileDate.get(position)); 


    } else { 
     ((ProgressViewHolder) holder).progressBar.setIndeterminate(true); 
    } 
} 

public void setLoaded() { 
    loading = false; 
} 

@Override 
public int getItemCount() { 
    return mSavedTime.size(); 
} 

public void setOnLoadMoreListener(OnLoadMoreListener onLoadMoreListener) { 
    this.onLoadMoreListener = onLoadMoreListener; 
} 


// 
public class StudentViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener { 
    public TextView mTimeDigitText; 
    public TextView mTimeUnitText; 
    private SwitchCompat mAlarmButtonPower; 
    private ImageView mAlarmBellImage; 

    private TextView mSundayButton; 
    private TextView mMondayButton; 
    private TextView mTuesdayButton; 
    private TextView mWednesdayButton; 
    private TextView mThursdayButton; 
    private TextView mFridayButton; 
    private TextView mSaturdayButton; 

    public CardView cardView1; 

    public StudentViewHolder(View v) { 
     super(v); 
     mTimeDigitText = (TextView) v.findViewById(R.id.timeDigit); 
     mTimeUnitText = (TextView) v.findViewById(R.id.timeUnit); 
     mAlarmBellImage = (ImageView) v.findViewById(R.id.alarmBell); 
     mAlarmButtonPower = (SwitchCompat) v.findViewById(R.id.alarmPowerSwitch); 

     mSundayButton = (TextView) v.findViewById(R.id.sunday); 
     mMondayButton = (TextView) v.findViewById(R.id.monday); 
     mTuesdayButton = (TextView) v.findViewById(R.id.tuesday); 
     mWednesdayButton = (TextView) v.findViewById(R.id.wednesday); 
     mThursdayButton = (TextView) v.findViewById(R.id.thursday); 
     mFridayButton = (TextView) v.findViewById(R.id.friday); 
     mSaturdayButton = (TextView) v.findViewById(R.id.saturday); 


     v.findViewById(R.id.alarmBell).setOnClickListener(this); 
     v.findViewById(R.id.sunday).setOnClickListener(this); 
     v.findViewById(R.id.monday).setOnClickListener(this); 
     v.findViewById(R.id.tuesday).setOnClickListener(this); 
     v.findViewById(R.id.wednesday).setOnClickListener(this); 
     v.findViewById(R.id.thursday).setOnClickListener(this); 
     v.findViewById(R.id.friday).setOnClickListener(this); 
     v.findViewById(R.id.saturday).setOnClickListener(this); 





     mAlarmButtonPower.setChecked(true); 
     if (mAlarmButtonPower.isChecked()) { 
      mBellCount = 2; 
      mAlarmBellImage.setImageDrawable(ContextCompat.getDrawable(context, R.drawable.bell_touch)); 
      Toast.makeText(context, "Alarm Activated!!", Toast.LENGTH_SHORT).show(); 
     } else { 
      mAlarmBellImage.setImageDrawable(ContextCompat.getDrawable(context, R.drawable.bell)); 
      Toast.makeText(context, "First Activate Your Alarm", Toast.LENGTH_SHORT).show(); 
     } 
     mAlarmButtonPower.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { 
      @Override 
      public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { 
       switch (buttonView.getId()) { 

        case R.id.alarmPowerSwitch: 

         if (!isChecked) { 
          mAlarmBellImage.setImageDrawable(ContextCompat.getDrawable(context, R.drawable.bell)); 
          Toast.makeText(context, "Alarm is off!!", Toast.LENGTH_SHORT).show(); 

         } else { 
          // AlarmReceiver.stopRingtone(); 
          // alarmManager.cancel(pendingIntent); 
          Log.d("MyActivity", "Alarm Off"); 
          mAlarmBellImage.setImageDrawable(ContextCompat.getDrawable(context, R.drawable.bell_touch)); 
          Toast.makeText(context, "Alarm is on!!", Toast.LENGTH_SHORT).show(); 
         } 
         break; 

        default: 
         break; 
       } 
      } 
     }); 

    } 


    @Override 
    public void onClick(View v) { 

     switch (v.getId()) { 

      case R.id.alarmBell: 

       mBellCount = mBellCount + 1; 

       if (mBellCount % 2 == 0) { 
        mAlarmBellImage.setImageDrawable(ContextCompat.getDrawable(context, R.drawable.bell_touch)); 
       } else { 
        mAlarmBellImage.setImageDrawable(ContextCompat.getDrawable(context, R.drawable.bell)); 
       } 

       break; 

      case R.id.sunday: 
        mSunCount = mSunCount + 1; 
       // mDaysArrayList.add(1); 
       if (mSunCount % 2 == 0) { 
        mSundayButton.setTextColor(ContextCompat.getColor(context, R.color.colorProfilePrimary)); 

       } else { 
        mSundayButton.setTextColor(ContextCompat.getColor(context, R.color.colorSecondary)); 
        // mDaysArrayList.clear(); 
       } 
       break; 

      case R.id.monday: 
       mMonCount = mMonCount + 1; 
       // mDaysArrayList.add(2); 
       if (mMonCount % 2 == 0) { 
        mMondayButton.setTextColor(ContextCompat.getColor(context, R.color.colorProfilePrimary)); 
       } else { 
        mMondayButton.setTextColor(ContextCompat.getColor(context, R.color.colorSecondary)); 
        //mDaysArrayList.remove(1); 
        // mDaysArrayList.clear(); 
       } 
       break; 
      case R.id.tuesday: 

       mTueCount = mTueCount + 1; 
       // mDaysArrayList.add(3); 
       if (mTueCount % 2 == 0) { 
        mTuesdayButton.setTextColor(ContextCompat.getColor(context, R.color.colorProfilePrimary)); 
       } else { 
        mTuesdayButton.setTextColor(ContextCompat.getColor(context, R.color.colorSecondary)); 
        // mDaysArrayList.remove(2); 
        //mDaysArrayList.clear(); 
       } 
       break; 

      case R.id.wednesday: 

       mWedCount = mWedCount + 1; 
      // mDaysArrayList.add(4); 
       if (mWedCount % 2 == 0) { 
        mWednesdayButton.setTextColor(ContextCompat.getColor(context, R.color.colorProfilePrimary)); 
       } else { 
        mWednesdayButton.setTextColor(ContextCompat.getColor(context, R.color.colorSecondary)); 
        // mDaysArrayList.remove(3); 
        //mDaysArrayList.clear(); 
       } 
       break; 

      case R.id.thursday: 

       mThuCount = mThuCount + 1; 
      // mDaysArrayList.add(5); 
       if (mThuCount % 2 == 0) { 
        mThursdayButton.setTextColor(ContextCompat.getColor(context, R.color.colorProfilePrimary)); 
       } else { 

        mThursdayButton.setTextColor(ContextCompat.getColor(context, R.color.colorSecondary)); 
        // mDaysArrayList.remove(4); 
        //mDaysArrayList.clear(); 
       } 
       break; 

      case R.id.friday: 

       mFriCount = mFriCount + 1; 
      // mDaysArrayList.add(6); 
       if (mFriCount % 2 == 0) { 
        mFridayButton.setTextColor(ContextCompat.getColor(context, R.color.colorProfilePrimary)); 
       } else { 
        mFridayButton.setTextColor(ContextCompat.getColor(context, R.color.colorSecondary)); 
        //mDaysArrayList.remove(5); 
        // mDaysArrayList.clear(); 
       } 
       break; 

      case R.id.saturday: 

       mSatCount = mSatCount + 1; 
       // mDaysArrayList.add(7); 
       if (mSatCount % 2 == 0) { 
        mSaturdayButton.setTextColor(ContextCompat.getColor(context, R.color.colorProfilePrimary)); 
       } else { 
        mSaturdayButton.setTextColor(ContextCompat.getColor(context, R.color.colorSecondary)); 
        //mDaysArrayList.remove(6); 
       // mDaysArrayList.clear(); 
       } 
       break; 


     } 


    } 
} 

public static class ProgressViewHolder extends RecyclerView.ViewHolder { 
    public ProgressBar progressBar; 

    public ProgressViewHolder(View v) { 
     super(v); 
     progressBar = (ProgressBar) v.findViewById(R.id.progressBar1); 
    } 
} 
} 

Любая помощь большинство welcome.Thanks

+1

вы можете поместить свой код здесь? –

+0

Какой массив вы хотите, если пользователь нажимает на su, mo и tu в позиции 1? –

+0

@NavinGupta - да, я помещаю свой класс адаптера. – Arora

ответ

0

Вы можете получить позицию так:

@Override 
public void onClick(View view) { 
    int position = getAdapterPosition(); 
    //do something depending on the position 
    //... 
} 
0

Учитывая тот факт, что ваш viewholer уже держит View объекты отношение к дням недели вы может легко добавить пользовательский код с несколькими вариантами выбора для вашего рекламодателя. (Там может быть более простые способы сделать это, но я обеспечиваю возможный ответ на то, что вы просили)

//decalare this instance variables in your adapter 
//better to go for a hash map but I'm just writing an example 
int itemPosition=-1; 
List<Integer> selectedDays; 

//initiate the list in the adapter constructor 
selectedDays=new ArrayList<>(); 

//make this change in your onBindViewHolder() 
StudentViewHolder sHOlder=(StudentViewHolder)holder; 
List<TextView> dayViews=new ArrayList<>(); 
dayView.add(sHolder.mSundayButton); 
//continue this and fill the list with all the seven buttons 

//check the previously created selectedDays list and set the colors for selected text views 
if(postion==itemPosition){ 
    for(int i=1;i<8;i++){ 
     TextView tv=dayViews.get(i-1); 
     if(selectedList.contains(new Integer(i))){ 
      tv.setTextColor(/*your selected color*/); 
     }else{ 
      tv.setTextColor(/*your unselected color*/); 
     } 
    } 
}else{ 
    for(TextView tv:dayViews){ 
     tv.setTextColor(/* your unselectedColor */); 
    } 
} 

//now implement onclicks for the days; 
for(int i=0;i<dayViews.length;i++){ 
    TextView tv=dayViews.get(i); 
    tv.setOnClickListener(new View.OnCLickListener{ 
     @Override 
     public void onClick(View v){ 
      //clear the list if the item position has changed 
      if(position!=itemPosition){ 
      selectedDays.clear(); 
      } 
      itemPosition=position; 
      selectedDays.add(i+1); 
      //notify the adapter 
      notifyDataSetChanged(); 
     } 
    }); 
} 

//you can convert the list to an array when you want to take the data 
int[] returnArray=new Int[selectedDays.size()]; 
for(int i=0;i<selectedDays.size;i++){ 
    returnArray[i]=selectedDays.get(i); 
} 
0

Результат такой же, потому что вы настраиваете ваши данные в одном списке массива для каждого элемента (т.е.) mDaysArrayList.

Вы должны создать mDaysArrayList для каждого элемента отдельно. Лучше всего сделать класс для элемента. и поместите arrayList из выбранных дней в этом классе.

0
try this 

public class AlarmAdapter extends RecyclerView.Adapter { 


private final int VIEW_ITEM = 1; 
private final int VIEW_PROG = 0; 


private List<String> myDataSet; 
private static String KEY1; 
// The minimum amount of items to have below your current scroll position 
// before loading more. 
private int visibleThreshold = 5; 
private int lastVisibleItem, totalItemCount; 
private boolean loading; 
private OnLoadMoreListener onLoadMoreListener; 
private static String TAG = "DATA_ADAPTER"; 
private static ArrayList<String> mSavedTime = new ArrayList<String>(); 
private static ArrayList<String> mTimeUnit = new ArrayList<>(); 
private static String mCurrentHour; 
private static String mCurrentMinute; 

private static Context context; 

private int mBellCount = 1; 
private int mSunCount = 1; 
private int mMonCount = 1; 
private int mTueCount = 1; 
private int mWedCount = 1; 
private int mThuCount = 1; 
private int mFriCount = 1; 
private int mSatCount = 1; 
private static ArrayList<Integer> mDaysArrayList = new ArrayList<Integer>(); 
private HashMap<Integer,List<Integer>> mDaysHashMap = new HashMap<>(); 

/*public AlarmAdapter(Context context, RecyclerView recyclerView, ArrayList<String> mSavedTime, 
          String mUserSavedPin, ArrayList<Integer> mFileId, Integer mFamilyMemberId, 
          String mResponseToken, ArrayList<String> mFileDate, ArrayList<String> mFileUrl, 
          ArrayList<String> mFileDescription) {*/ 

public AlarmAdapter(Context context, RecyclerView recyclerView, ArrayList<String> mTime, ArrayList<String> mTimeUnit, String mCurrentHour, String mCurrentMinute) { 


    this.mSavedTime = mTime; 
    this.mTimeUnit = mTimeUnit; 
    this.mCurrentHour = mCurrentHour; 
    this.mCurrentMinute = mCurrentMinute; 

    this.context = context; 
    if (recyclerView.getLayoutManager() instanceof LinearLayoutManager) { 

     final LinearLayoutManager linearLayoutManager = (LinearLayoutManager) recyclerView 
       .getLayoutManager(); 


     recyclerView 
       .addOnScrollListener(new RecyclerView.OnScrollListener() { 
        @Override 
        public void onScrolled(RecyclerView recyclerView, 
              int dx, int dy) { 
         super.onScrolled(recyclerView, dx, dy); 

         totalItemCount = linearLayoutManager.getItemCount(); 
         lastVisibleItem = linearLayoutManager 
           .findLastVisibleItemPosition(); 
         if (!loading 
           && totalItemCount <= (lastVisibleItem + visibleThreshold)) { 
          // End has been reached 
          // Do something 
          if (onLoadMoreListener != null) { 
           onLoadMoreListener.onLoadMore(); 
          } 
          loading = true; 
         } 
        } 
       }); 
    } 
} 

@Override 
public int getItemViewType(int position) { 
    return mSavedTime.get(position) != null ? VIEW_ITEM : VIEW_PROG; 
} 

@Override 
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, 
                int viewType) { 
    RecyclerView.ViewHolder vh; 


    if (viewType == VIEW_ITEM) { 
     View v = LayoutInflater.from(parent.getContext()).inflate(
       R.layout.saved_alarm_card, parent, false); 

     vh = new StudentViewHolder(v); 

    } else { 
     View v = LayoutInflater.from(parent.getContext()).inflate(
       R.layout.more_progress_item, parent, false); 

     vh = new ProgressViewHolder(v); 
    } 

    return vh; 
} 

@Override 
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { 
    if (holder instanceof StudentViewHolder) { 


     ((StudentViewHolder) holder).mTimeDigitText.setText(mSavedTime.get(position)); 
     ((StudentViewHolder) holder).mTimeUnitText.setText(mTimeUnit.get(position)); 
     // ((StudentViewHolder) holder).dateField.setText(mFileDate.get(position)); 

holder.mAlarmBellImage.setOnClickListener(new Listener(holder.mSundayButton,holder.mAlarmBellImage)); 
     holder.mSundayButton.setOnClickListener(new Listener(holder.mSundayButton,holder.mAlarmBellImage)); 
     holder.mMondayButton.setOnClickListener(new Listener(holder.mMondayButton,holder.mAlarmBellImage)); 
     holder.mTuesdayButton.setOnClickListener(new Listener(holder.mTuesdayButton,holder.mAlarmBellImage)); 
     holder.mWednesdayButton.setOnClickListener(new Listener(holder.mWednesdayButton,holder.mAlarmBellImage)); 
     holder.mThursdayButton.setOnClickListener(new Listener(holder.mThursdayButton,holder.mAlarmBellImage)); 
     holder.mFridayButton.setOnClickListener(new Listener(holder.mFridayButton,holder.mAlarmBellImage)); 
     holder.mSaturdayButton.setOnClickListener(new Listener(holder.mSaturdayButton,holder.mAlarmBellImage)); 
    } else { 
     ((ProgressViewHolder) holder).progressBar.setIndeterminate(true); 
    } 
} 

public void setLoaded() { 
    loading = false; 
} 

@Override 
public int getItemCount() { 
    return mSavedTime.size(); 
} 

public void setOnLoadMoreListener(OnLoadMoreListener onLoadMoreListener) { 
    this.onLoadMoreListener = onLoadMoreListener; 
} 


class Listener implements View.OnClickListener 

{ 
TextView textview; 
ImageView alarmview; 
Listener(TextView textview,ImageView alarmview) 

{ 
this.alarmview = alarmview; 
this.textview = textview; 
} 
    @Override 
    public void onClick(View v) { 

     switch (v.getId()) { 

      case R.id.alarmBell: 

       mBellCount = mBellCount + 1; 

       if (mBellCount % 2 == 0) { 
        alarmview.setImageDrawable(ContextCompat.getDrawable(context, R.drawable.bell_touch)); 
       } else { 
        alarmview.setImageDrawable(ContextCompat.getDrawable(context, R.drawable.bell)); 
       } 

       break; 

      case R.id.sunday: 
        mSunCount = mSunCount + 1; 
       // mDaysArrayList.add(1); 
       if (mSunCount % 2 == 0) { 
        textview.setTextColor(ContextCompat.getColor(context, R.color.colorProfilePrimary)); 

       } else { 
        textview.setTextColor(ContextCompat.getColor(context, R.color.colorSecondary)); 
        // mDaysArrayList.clear(); 
       } 
       break; 

      case R.id.monday: 
       mMonCount = mMonCount + 1; 
       // mDaysArrayList.add(2); 
       if (mMonCount % 2 == 0) { 
        textview.setTextColor(ContextCompat.getColor(context, R.color.colorProfilePrimary)); 
       } else { 
        textview.setTextColor(ContextCompat.getColor(context, R.color.colorSecondary)); 
        //mDaysArrayList.remove(1); 
        // mDaysArrayList.clear(); 
       } 
       break; 
      case R.id.tuesday: 

       mTueCount = mTueCount + 1; 
       // mDaysArrayList.add(3); 
       if (mTueCount % 2 == 0) { 
        textview.setTextColor(ContextCompat.getColor(context, R.color.colorProfilePrimary)); 
       } else { 
        textview.setTextColor(ContextCompat.getColor(context, R.color.colorSecondary)); 
        // mDaysArrayList.remove(2); 
        //mDaysArrayList.clear(); 
       } 
       break; 

      case R.id.wednesday: 

       mWedCount = mWedCount + 1; 
      // mDaysArrayList.add(4); 
       if (mWedCount % 2 == 0) { 
        textview.setTextColor(ContextCompat.getColor(context, R.color.colorProfilePrimary)); 
       } else { 
        textview.setTextColor(ContextCompat.getColor(context, R.color.colorSecondary)); 
        // mDaysArrayList.remove(3); 
        //mDaysArrayList.clear(); 
       } 
       break; 

      case R.id.thursday: 

       mThuCount = mThuCount + 1; 
      // mDaysArrayList.add(5); 
       if (mThuCount % 2 == 0) { 
        textview.setTextColor(ContextCompat.getColor(context, R.color.colorProfilePrimary)); 
       } else { 

        textview.setTextColor(ContextCompat.getColor(context, R.color.colorSecondary)); 
        // mDaysArrayList.remove(4); 
        //mDaysArrayList.clear(); 
       } 
       break; 

      case R.id.friday: 

       mFriCount = mFriCount + 1; 
      // mDaysArrayList.add(6); 
       if (mFriCount % 2 == 0) { 
        textview.setTextColor(ContextCompat.getColor(context, R.color.colorProfilePrimary)); 
       } else { 
        textview.setTextColor(ContextCompat.getColor(context, R.color.colorSecondary)); 
        //mDaysArrayList.remove(5); 
        // mDaysArrayList.clear(); 
       } 
       break; 

      case R.id.saturday: 

       mSatCount = mSatCount + 1; 
       // mDaysArrayList.add(7); 
       if (mSatCount % 2 == 0) { 
        textview.setTextColor(ContextCompat.getColor(context, R.color.colorProfilePrimary)); 
       } else { 
        textview.setTextColor(ContextCompat.getColor(context, R.color.colorSecondary)); 
        //mDaysArrayList.remove(6); 
       // mDaysArrayList.clear(); 
       } 
       break; 


     } 


    } 
} 


// 
public class StudentViewHolder extends RecyclerView.ViewHolder { 
    public TextView mTimeDigitText; 
    public TextView mTimeUnitText; 
    private SwitchCompat mAlarmButtonPower; 
    private ImageView mAlarmBellImage; 

    private TextView mSundayButton; 
    private TextView mMondayButton; 
    private TextView mTuesdayButton; 
    private TextView mWednesdayButton; 
    private TextView mThursdayButton; 
    private TextView mFridayButton; 
    private TextView mSaturdayButton; 

    public CardView cardView1; 

    public StudentViewHolder(View v) { 
     super(v); 
     mTimeDigitText = (TextView) v.findViewById(R.id.timeDigit); 
     mTimeUnitText = (TextView) v.findViewById(R.id.timeUnit); 
     mAlarmBellImage = (ImageView) v.findViewById(R.id.alarmBell); 
     mAlarmButtonPower = (SwitchCompat) v.findViewById(R.id.alarmPowerSwitch); 

     mSundayButton = (TextView) v.findViewById(R.id.sunday); 
     mMondayButton = (TextView) v.findViewById(R.id.monday); 
     mTuesdayButton = (TextView) v.findViewById(R.id.tuesday); 
     mWednesdayButton = (TextView) v.findViewById(R.id.wednesday); 
     mThursdayButton = (TextView) v.findViewById(R.id.thursday); 
     mFridayButton = (TextView) v.findViewById(R.id.friday); 
     mSaturdayButton = (TextView) v.findViewById(R.id.saturday); 








     mAlarmButtonPower.setChecked(true); 
     if (mAlarmButtonPower.isChecked()) { 
      mBellCount = 2; 
      mAlarmBellImage.setImageDrawable(ContextCompat.getDrawable(context, R.drawable.bell_touch)); 
      Toast.makeText(context, "Alarm Activated!!", Toast.LENGTH_SHORT).show(); 
     } else { 
      mAlarmBellImage.setImageDrawable(ContextCompat.getDrawable(context, R.drawable.bell)); 
      Toast.makeText(context, "First Activate Your Alarm", Toast.LENGTH_SHORT).show(); 
     } 
     mAlarmButtonPower.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { 
      @Override 
      public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { 
       switch (buttonView.getId()) { 

        case R.id.alarmPowerSwitch: 

         if (!isChecked) { 
          mAlarmBellImage.setImageDrawable(ContextCompat.getDrawable(context, R.drawable.bell)); 
          Toast.makeText(context, "Alarm is off!!", Toast.LENGTH_SHORT).show(); 

         } else { 
          // AlarmReceiver.stopRingtone(); 
          // alarmManager.cancel(pendingIntent); 
          Log.d("MyActivity", "Alarm Off"); 
          mAlarmBellImage.setImageDrawable(ContextCompat.getDrawable(context, R.drawable.bell_touch)); 
          Toast.makeText(context, "Alarm is on!!", Toast.LENGTH_SHORT).show(); 
         } 
         break; 

        default: 
         break; 
       } 
      } 
     }); 

    } 



} 

public static class ProgressViewHolder extends RecyclerView.ViewHolder { 
    public ProgressBar progressBar; 

    public ProgressViewHolder(View v) { 
     super(v); 
     progressBar = (ProgressBar) v.findViewById(R.id.progressBar1); 
    } 
} 
} 
0

самый простой путь вызова viewHolder.itemView.setOnClickListener(listner) внутри вашей onBindViewHolder, как показано ниже:

@Override 
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {  
     holder.itemView.setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View v) { 
      } 
     }); 
} 
Смежные вопросы