Я хочу проанализировать данные RecyclerView для другого действия, щелкнув элемент RecyclerView и используя метод putExtra.Где показать тост сообщение и намерение другой деятельности, но не анализировать данные.
Я не понимаю проблему!плз !!!помогите мне ....
здесь класс DataAdapter,
DataAdapter.java
public class DataAdapter extends android.support.v7.widget.RecyclerView.Adapter<DataAdapter.DataViewHolder>{
Context ctx;
List<DataModel> dataModelList;
public DataAdapter(Context ctx, List<DataModel> dataModelList) {
this.ctx = ctx;
this.dataModelList = dataModelList;
}
@Override
public DataViewHolder onCreateViewHolder( ViewGroup parent, int viewType) {
LayoutInflater inflater = LayoutInflater.from(ctx);
View view = inflater.inflate(R.layout.row_township_union,null);
return new DataViewHolder(view,dataModelList);
}
@Override
public void onBindViewHolder(DataViewHolder holder, final int position) {
final DataModel dataModel = dataModelList.get(position);
holder.textViewUnion.setText(dataModel.getTownship_union());
}
@Override
public int getItemCount() {
return dataModelList.size();
}
class DataViewHolder extends android.support.v7.widget.RecyclerView.ViewHolder{
TextView textViewUnion;
List<DataModel> dataModelList;
CardView cardView;
public DataViewHolder(View itemView, List<DataModel> data) {
super(itemView);
dataModelList = data;
textViewUnion = itemView.findViewById(R.id.tvUnion);
cardView = itemView.findViewById(R.id.card);
cardView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int position = getAdapterPosition();
Toast.makeText(ctx, "clicked !", Toast.LENGTH_LONG).show();
Intent i= new Intent(ctx, AreaSelect.class);
i.putExtra("key",dataModelList.get(position));
ctx.startActivity(i);
}
});
}
}
}
здесьКласс DataModel,
DataModel.java
public class DataModel implements Parcelable {
String township_union;
public DataModel(String township_union) {
this.township_union = township_union;
}
public String getTownship_union() {
return township_union;
}
public void setTownship_union(String township_union) {
this.township_union = township_union;
}
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(this.township_union);
}
protected DataModel(Parcel in) {
this.township_union = in.readString();
}
public static final Parcelable.Creator<DataModel> CREATOR = new Parcelable.Creator<DataModel>() {
@Override
public DataModel createFromParcel(Parcel source) {
return new DataModel(source);
}
@Override
public DataModel[] newArray(int size) {
return new DataModel[size];
}
};
}
AreaSelect.java
public class AreaSelect extends AppCompatActivity {
TextView textView;
String union;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_area_select);
textView = findViewById(R.id.tvUnion);
Bundle extras = getIntent().getExtras();
union = extras.getString("key");
textView.setText(union);
}
}