0
剛烤麪包作品上onClick()
的onclick上工作(),沒有別的,我已在AndroidManifest
太意圖和startactivity不recyclerview適配器
Intent
和startActivity
中所有條目RecyclerView
適配器上onClick()
不工作而Toast
工作正常
這裏是我的代碼
public class ForecastAdapter extends RecyclerView.Adapter<ForecastAdapter.MyForecastViewHolder> {
public Context context;
private LayoutInflater inflator;
List<Information> data = Collections.emptyList();
public ForecastAdapter(Context context, List<Information> data) {
inflator = LayoutInflater.from(context);
this.data = data;
this.context = context;
}
@Override
public MyForecastViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = inflator.inflate(R.layout.custom_row_forecast, parent, false);
MyForecastViewHolder holder = new MyForecastViewHolder(view);
return holder;
}
@Override
public void onBindViewHolder(MyForecastViewHolder holder, final int position) {
Information current = data.get(position);
holder.title.setText(current.title);
holder.icon.setImageResource(current.iconId);
}
@Override
public int getItemCount() {
return data.size();
}
class MyForecastViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
TextView title;
ImageView icon;
public MyForecastViewHolder(View itemView) {
super(itemView);
itemView.setOnClickListener(this);
title = (TextView) itemView.findViewById(R.id.temp);
icon = (ImageView) itemView.findViewById(R.id.listIcon3);
}
@Override
public void onClick(View v) {
context.startActivity(new Intent(context,SubActivity.class));
}
}
}
當你說「不工作,」該應用是否會崩潰?如果是這樣,請從Logcat發佈錯誤 –
您應該閱讀[問];) – mithrop