你能帮帮我吗,我怎么能在列表上的每个项目上打开一个不同的片段?我已经阅读并尝试了很多东西,但不能.我想要的是什么
案例:0,
案例1:等......
我必须说列表不会改变顺序或大小,总是相同的项目而不是四处走动.
谢谢您的回答.
import android.content.Context; import android.support.v7.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ImageView; import android.widget.TextView; import android.widget.Toast; import com.example.javier.MaterialDesignApp.R; import com.example.javier.MaterialDesignApp.RecyclerView.RecyclerViewClasses.Calendario; import com.squareup.picasso.Picasso; import java.util.ArrayList; public class Adapter_Calendario extends RecyclerView.Adapter{ private ArrayList calendario; Context context; private final View.OnClickListener onClickListener = new View.OnClickListener() { @Override public void onClick(View v) { Toast.makeText(context,"Clicked",Toast.LENGTH_SHORT).show(); } }; public Adapter_Calendario(Context context, ArrayList calendario) { this.calendario = calendario; this.context = context; } // Create new views. This is invoked by the layout manager. @Override public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_post, parent, false); v.setOnClickListener(onClickListener); return new ViewHolder(v); } @Override public void onBindViewHolder(final ViewHolder holder, final int position) { final TextView textViewJornada = (TextView) holder.view.findViewById(R.id.tv_jornada); final TextView textViewFecha = (TextView) holder.view.findViewById(R.id.tv_fecha); final TextView textViewHora = (TextView) holder.view.findViewById(R.id.tv_hora); final TextView textViewEquipo_local = (TextView) holder.view.findViewById(R.id.tv_equipo_local); final TextView textViewResultado_local = (TextView) holder.view.findViewById(R.id.tv_resultado_local); final TextView textViewResultado_visitante = (TextView) holder.view.findViewById(R.id.tv_resultado_visitante); final TextView textViewEquipo_visitante = (TextView) holder.view.findViewById(R.id.tv_equipo_visitante); final ImageView imageViewEscudo_local = (ImageView) holder.view.findViewById(R.id.tv_escudo_local); final ImageView imageViewEscudo_visitante = (ImageView) holder.view.findViewById(R.id.tv_escudo_visitante); textViewJornada.setText("Jornada: "+calendario.get(position).getJornada()); textViewFecha.setText(" El "+calendario.get(position).getFecha()+" "); textViewHora.setText("A las "+calendario.get(position).getHora()+" "); textViewEquipo_local.setText(calendario.get(position).getEquipo_local()); textViewResultado_local.setText(" "+calendario.get(position).getResultado_local()+" - "); textViewResultado_visitante.setText(calendario.get(position).getResultado_visitante()+" "); textViewEquipo_visitante.setText(calendario.get(position).getEquipo_visitante()); Picasso.with(context).load(calendario.get(position).getEscudo_local()) .placeholder(holder.view.getResources() .getDrawable(R.drawable.ic_contact_icon)).into(imageViewEscudo_local); Picasso.with(context).load(calendario.get(position).getEscudo_visitante()) .placeholder(holder.view.getResources() .getDrawable(R.drawable.ic_contact_icon)).into(imageViewEscudo_visitante); } @Override public int getItemCount() { return calendario.size(); } // you provide access to all the views for a data item in a view holder public static class ViewHolder extends RecyclerView.ViewHolder { // each data item is just a string in this case public View view; public ViewHolder(View v) { super(v); view = v; } } }
Piyush.. 6
有三种方法可以做到这一点.
1)您可以实现OnTouch
对事件的RecycleView
使用gesture
和使用position
的开关情况.
2)在适配器类中,为您的xml文件的父布局创建单击侦听器,并position
在switch case中使用相同的方法.
3)您可以在适配器类中创建一个接口,并在父布局的click事件上注册,并使用该接口实现您的活动.
有三种方法可以做到这一点.
1)您可以实现OnTouch
对事件的RecycleView
使用gesture
和使用position
的开关情况.
2)在适配器类中,为您的xml文件的父布局创建单击侦听器,并position
在switch case中使用相同的方法.
3)您可以在适配器类中创建一个接口,并在父布局的click事件上注册,并使用该接口实现您的活动.