我有一个ListView,它有2个项目 每一个都是ListView 我只想在单击某个项目时移动到另一个Activity。
我有这段代码
public void onBindViewHolder(HomeHolder holder, int position) {
holder.recyclerView.setAdapter(new InHomeAdapter(inflater));
holder.recyclerView.setLayoutManager(new LinearLayoutManager(context,
LinearLayoutManager.HORIZONTAL, false));
holder.recyclerView.addOnItemTouchListener(new
InHomeAdapter.InHomeListener(context, new InHomeAdapter.ClickListener() {
@Override
public void onClick(InHomeAdapter.InHomeHolder holder, View view, int position) {
Intent i = new Intent(this,movie_Detailes.class);
}
});
}
我在“movie_detailes.class”下面有一个红线 我怎样才能做到这一点?
答案 0 :(得分:1)
试试这个
//in adapter constructer
Context context;
public CustomAdapter(Context context){
this.context = context;
}
public void onBindViewHolder(HomeHolder holder, int position) {
holder.recyclerView.setAdapter(new InHomeAdapter(inflater));
holder.recyclerView.setLayoutManager(new LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false));
holder.recyclerView.addOnItemTouchListener(new InHomeAdapter.InHomeListener(context, new InHomeAdapter.ClickListener() {
@Override
public void onClick(InHomeAdapter.InHomeHolder holder, View view, int position) {
Intent i = new Intent(context, movie_Detailes.class);
}
}));
}
答案 1 :(得分:0)
试试这些代码
//Create constructor of your Adapter class
Context context;
public YourAdapterClass(Context context){
this.context = context;
}
然后
public void onBindViewHolder(HomeHolder holder, int position) {
holder.recyclerView.setAdapter(new InHomeAdapter(inflater));
holder.recyclerView.setLayoutManager(new LinearLayoutManager(context,
LinearLayoutManager.HORIZONTAL, false));
holder.recyclerView.addOnItemTouchListener(new
InHomeAdapter.InHomeListener(context, new InHomeAdapter.ClickListener() {
@Override
public void onClick(InHomeAdapter.InHomeHolder holder, View view, int position) {
Intent intent = new Intent(context,movie_Detailes.class);
startActivity(intent)
}
});
}