【问题标题】:I want to send the selected data through intent if there is one Activity between them如果它们之间有一个活动,我想通过意图发送选定的数据
【发布时间】:2019-05-08 04:21:32
【问题描述】:
@Override
public void onBindViewHolder(LiveMatchViewHolder holder, final int position) {


    liveMatchPOJO  currItem = liveMatches.get(position);


    holder.tvTeam1.setText(currItem.getTeam1());
    holder.tvTeam2.setText(currItem.getTeam2());

// holder.timedate.setText(Integer.toString(currItem.getUniqueid()));

    if (prevPos < position) {
        //downwards
        AnimUtil.animate(holder, true);
    }else{
        //upwards
        AnimUtil.animate(holder, false);
    }

    holder.itemView.setOnClickListener(v -> {

        final Intent i;
               i = new Intent(context, Cricket_Categorie.class);
               i.putExtra("unique_id", liveMatches.get(position).getUniqueid());
               i.putExtra("matchStarted", liveMatches.get(position).getMatchStarted());
               i.putExtra("team1",liveMatches.get(position).getTeam1());
               i.putExtra("team2",liveMatches.get(position).getTeam2());
               context.startActivity(i);




    });

    prevPos = position;
}

这是我发送意图的第一个代码,我如何在第二个适配器上接收它

如何在第二个适配器上接收它

@覆盖 public void onBindViewHolder(ViewHolder holder, int position) {

    final Categories_Data_holder listItem = listItems.get(position);
    listItem.getCategories_id();
    holder.biography.setText(listItem.getBio());
    Picasso.with(context)
            .load(listItem.getImageUrl())
            .into(holder.imageView);
    holder.biography.setText(listItem.getBio());

   // Intent i = ((Cricket_Categorie)context).getIntent();


    //Setting OnClickListner on Views:-
    holder.itemView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            Intent ii = null;
            switch (position){
                case 0:
           ii = new Intent(v.getContext(), Activity.class);

                    break;

                case 1:
                    ii = new Intent(v.getContext(), ActivityII.class);
                    break;
            }
            context.startActivity(ii);

        }
    });



}

我如何在这里接收文本,因为我需要通过这里向第三个活动发送文本

【问题讨论】:

  • 请附上您的代码和您的问题
  • 请在代码中添加更多信息。

标签: android


【解决方案1】:

您可以将文本发送到第二个活动,将其存储在某个变量中,并在需要时从第二个活动发送到第三个活动。

【讨论】:

    【解决方案2】:

    如果你想通过意图传递数据,你应该将数据传递给第二个活动,然后从第二个活动传递到第三个活动像这样:

    Intent intent = new Intent(Activity1.this, Activity2.class);
    intent.putExtra("EXTRA_DATA", data);
    startActivity(intent);
    

    然后在第二个活动中变成这样

    String data= getIntent().getStringExtra("EXTRA_DATA");
    

    然后像这样传递给第三个活动:

    Intent intent = new Intent(Activity2.this, Activity3.class);
    intent.putExtra("EXTRA_DATA", data);
    startActivity(intent);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-10-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-06
      相关资源
      最近更新 更多