2016-11-30 70 views
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); 
     } 
    } 
} 

我已經看了很多文章來解決它,並根據該做的東西,但無法找到任何解決方案。

+1

安置自己的logcat的?你是在清單文件註冊WinnerActivity? – Rahul

+1

如果您甚至不告訴我們錯誤是什麼,您如何期待我們提供幫助?從logcat發佈堆棧跟蹤。 –

+0

後堆棧跟蹤 – Eswar

回答

0

其實,我不能回答你的問題,因爲你不發表您的logcat的,但也有一些事情你可以檢查:

1 - 檢查你的活動在AndroidManifest.xml

2已經聲明 - 檢查你的上下文是Activity還是applicationContext的上下文? 如果不豈不等於活動的背景下,所以你需要添加標誌

Intent i = new Intent(this, WinnerActivity.class); 
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);