0
我有一個RecyclerView這是加載我的字符串數組的工作正常的內容,但我想開一個新的活動這取決於視圖他們已經按下了。應用崩潰
我做了什麼:
public class WinnersListAdapter extends RecyclerView.Adapter<WinnersListAdapter.WinnersCardViewHolder>
{
Context context;
LayoutInflater inflater;
List<ListLottery> lotteryList;
public WinnersListAdapter(List<ListLottery> loteries,Context context){
this.context = context;
this.lotteryList = loteries;
inflater = LayoutInflater.from(context);
}
@Override
public WinnersListAdapter.WinnersCardViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View v = inflater.inflate(R.layout.prevlotterycards_layout,parent,false);
// Toast.makeText(context,"Hi",Toast.LENGTH_SHORT).show();
WinnersListAdapter.WinnersCardViewHolder viewHolder = new WinnersListAdapter.WinnersCardViewHolder(v);
return viewHolder;
}
@Override
public void onBindViewHolder(WinnersListAdapter.WinnersCardViewHolder holder, int position) {
final ListLottery lottery = lotteryList.get(position);
holder.lottery_date.setText(lottery.getLotteryDate());
holder.lottery_date.setTag(holder);
holder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(context,"clicked--"+lottery.getLotteryId(),Toast.LENGTH_SHORT).show();
Intent intent = new Intent(context,WinnerActivity.class);
intent.putExtra("lotteryId",lottery.getLotteryId());
context.startActivity(intent);
}
});
}
@Override
public int getItemCount() {
return lotteryList.size();
}
class WinnersCardViewHolder extends RecyclerView.ViewHolder {
TextView lottery_date;
CardView card_lotteryList;
public WinnersCardViewHolder(View itemView) {
super(itemView);
lottery_date = (TextView) itemView.findViewById(R.id.l_lottery_date);
card_lotteryList = (CardView) itemView.findViewById(R.id.card_lotteryList);
}
}
}
我已經看了很多文章來解決它,並根據該做的東西,但無法找到任何解決方案。
安置自己的logcat的?你是在清單文件註冊WinnerActivity? – Rahul
如果您甚至不告訴我們錯誤是什麼,您如何期待我們提供幫助?從logcat發佈堆棧跟蹤。 –
後堆棧跟蹤 – Eswar