如何将不同 api id 的数据显示到 recyclerview 的不同项目?

how to display data of different api ids to different items of recycle view?

我将简要地写下我真正想要的东西以及我的确切位置 stucked.I正在使用改造从 api 加载回收视图中的列表(我已成功加载)请参阅此图片- ->image description here.

此外,我有两个 api ID(例如:https//..id=1 和 https//..id=2 等等,具体取决于此列表 image description here。)

这是我的 2 apis:(第一个 https//..id=1)

{"id":"1","title":"Android Introduction","description":"
Android is a Linux based operating system it is designed primarily for touch screen mobile devices such as smart phones and tablet computers. The operating system have developed a lot in last 15 years starting from black and white phones to recent smart phones or mini computers. One of the most widely used mobile OS   these days is android.  The android is software that was founded in Palo Alto of California in 2003.<\/p>\r\n\r\n

 \"\"<\/p>\r\n\r\n

 The android is a powerful operating system and it supports large number of applications in Smartphones. These applications are more comfortable and advanced for the users. The hardware that supports android software is based on ARM architecture platform. The android is an open source operating system means that it’s free and any one can use it. The android has got millions of apps available that can help you managing your life one or other way and it is available low cost in market at that reasons android is very popular.<\/p>\r\n\r\n

 \"\"<\/p>\r\n\r\n

 The android development supports with the full java programming language. Even other packages that are API and JSE are not supported. The first version 1.0 of android development kit (SDK) was released in 2008 and latest updated version is jelly bean.<\/p>\r\n"}

第二个:(https//..id=2)

{"id":"2","title":"Android Studio","description":"
 Meet Android Studio<\/p>\r\n\r\n

 Android Studio is the official Integrated Development Environment (IDE) for Android app development, based onIntelliJ IDEA <\/a>. On top of IntelliJ's powerful code editor and developer tools, Android Studio offers even more features that enhance your productivity when building Android apps, such as:<\/p>\r\n\r\n

   \r\n\t
  A flexible Gradle-based build system<\/li>\r\n\t
  A fast and feature-rich emulator<\/li>\r\n\t
  A unified environment where you can develop for all Android devices<\/li>\r\n\t
  Apply Changes to push code and resource changes to your running app without restarting your    app<\/li>\r\n\t
  Code templates and GitHub integration to help you build common app features and import sample code<\/li>\r\n\t
   Extensive testing tools and frameworks<\/li>\r\n\t
   Lint tools to catch performance, usability, version compatibility, and other problems<\/li>\r\n\t
  C++ and NDK support<\/li>\r\n\t
   Built-in support for Google Cloud Platform<\/a>, making it easy to integrate Google Cloud    Messaging and App Engine<\/li>\r\n<\/ul>\r\n\r\n
   This page provides an introduction to basic Android Studio features. For a summary of the latest changes, seeAndroid Studio release notes<\/a>.<\/p>\r\n"}

正如您在 apis 中看到的那样,单击项目时应该将它们各自的描述从 apis 加载到下一个 activity像这样-->image description here

如果你想要我可以分享code.just告诉你你到底需要什么。我会编辑

这是我的下一个activity适配器代码:

public class NextAndroidAdapter  extends RecyclerView.Adapter<NextAndroidAdapter.CustomViewHolder> {
DescriptionModel WAmdel;
Context context;
public NextAndroidAdapter(Context context,DescriptionModel employees) {
    this.WAmdel = employees;
    this.context=context;
}



@Override
public CustomViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    View itemView = LayoutInflater.from(parent.getContext())
            .inflate(R.layout.nextwhatsandroid_item , parent, false);

    return new CustomViewHolder(itemView);
}

@Override
public void onBindViewHolder(CustomViewHolder holder, final int position) {

  // holder.textView.setText(String.valueOf(position+1)+". ");
   holder.textView.setText(WAmdel.getDescription());

}

@Override
public int getItemCount() {
    return 1;
}

public class CustomViewHolder extends RecyclerView.ViewHolder {
    TextView textView;

    public CustomViewHolder(View view) {
        super(view);
       // employeeName = (TextView) view.findViewById(R.id.WA2);
        textView=view.findViewById(R.id.detailswhatsandroid);
        
            }
        });

    }
}

}

这是我的回收视图项目适配器(image description here):

public class WhatsAndroidAdapter extends RecyclerView.Adapter<WhatsAndroidAdapter.CustomViewHolder> {
List<WhatsAndroid.WhatsAndroidModel> WAmdel;
Context context;
public WhatsAndroidAdapter(Context context,List<WhatsAndroid.WhatsAndroidModel> employees) {
    this.WAmdel = employees;
    this.context=context;
}



@Override
public CustomViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    View itemView = LayoutInflater.from(parent.getContext())
            .inflate(R.layout.whatsandroid_item , parent, false);

    return new CustomViewHolder(itemView);
}

@Override
public void onBindViewHolder(CustomViewHolder holder, final int position) {

    holder.textView.setText(String.valueOf(position+1)+". ");
    holder.employeeName.setText(WAmdel.get(position).getTitle());

}

@Override
public int getItemCount() {
    return WAmdel.size();
}

public class CustomViewHolder extends RecyclerView.ViewHolder {
    public TextView employeeName;
    TextView textView;

    public CustomViewHolder(View view) {
        super(view);
        employeeName = (TextView) view.findViewById(R.id.WA2);
        textView=view.findViewById(R.id.WA1);
      view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent =  new Intent(context, NextActivity.class);
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                intent.putExtra("title", WAmdel.get(getAdapterPosition()).getTitle());

                context.startActivity(intent);

            }
        });

    }
}

}

下一个activity:

public class NextActivity extends AppCompatActivity {
private RecyclerView recyclerView;
private NextAndroidAdapter adapter;
private DescriptionModel DescriptList;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.nextwhatsandroid_layout);
    Toolbar toolbar = (Toolbar) findViewById(R.id. toolbar );
    setSupportActionBar( toolbar );
    if (getSupportActionBar() != null) {
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        getSupportActionBar().setDisplayShowHomeEnabled(true);
    }
    Intent intent = getIntent();
    String title = intent.getStringExtra("title");
  String hello=intent.getStringExtra("hii");

    getSupportActionBar().setTitle(title);
    /*Create handle for the RetrofitInstance interface*/
    DescriptService service = DescriptClientInstance.getRetrofitInstance().create(DescriptService.class);
    Call<DescriptionModel> call = service.getAllPhotos();
    call.enqueue(new Callback<DescriptionModel>() {
        @Override
        public void onResponse(Call<DescriptionModel> call, Response<DescriptionModel> response) {
           // progressDialog.dismiss();
            DescriptList=response.body();
            generateDataList(DescriptList);
        }

        @Override
        public void onFailure(Call<DescriptionModel> call, Throwable t) {
           // progressDialog.dismiss();

            Toast.makeText(getApplicationContext(), "Something went wrong...Please try later!", Toast.LENGTH_SHORT).show();
        }
    });
}
private void generateDataList(DescriptionModel photoList) {
    recyclerView = findViewById(R.id.recyclenext);
    LinearLayoutManager manager = new LinearLayoutManager(getApplicationContext());
    recyclerView.setLayoutManager(manager);
    recyclerView.setHasFixedSize(true);
    adapter = new NextAndroidAdapter(getApplicationContext(),photoList);
    recyclerView.setAdapter(adapter);
}
@Override
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
    if (item.getItemId() ==android.R.id.home) {
        finish();
    }
    return super.onOptionsItemSelected(item);
}
@Override
public void onBackPressed() {
    super.onBackPressed();
}

}

但现在我是这样出来的: 当我点击 item0 它进入下一个屏幕并显示 item1 的描述但是当我点击 item1 它进入下一个屏幕显示与之前相同的描述..我应该在改造界面方法中做什么?

需要帮助...提前致谢

在 Adapter 中,在 Binding 方法上添加 item click listener 并在 position base 上发送描述,并在 intent 中或通过参数传递描述,如下所示:

holder.itemView.setonClickListener(new OnItemClickListner{

      override
      onClick(View view){
           intent i=new Intent(context,YOUR_ACTIVITY);
           i.putString("description",you_data_list.get(postion)
           .getString("description");
           context.startActivity(i);
     }
}

据我了解你想做什么,据此我假设你需要进行以下更改:

WhatsAndroidAdapter

view.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        Intent intent =  new Intent(context, NextActivity.class);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.putExtra("title", WAmdel.get(getAdapterPosition()).getTitle());
        intent.putExtra("id", WAmdel.get(getAdapterPosition()).getId());

        context.startActivity(intent);

    }
});

NextActivity

Intent intent = getIntent();
String title = intent.getStringExtra("title");
String id = intent.getStringExtra("id");
String hello=intent.getStringExtra("hii");

getSupportActionBar().setTitle(title);
/*Create handle for the RetrofitInstance interface*/
DescriptService service = DescriptClientInstance.getRetrofitInstance().create(DescriptService.class);
Call<DescriptionModel> call = service.getAllPhotos(id);
call.enqueue(new Callback<DescriptionModel>() {
    @Override
    public void onResponse(Call<DescriptionModel> call, Response<DescriptionModel> response) {
       // progressDialog.dismiss();
        DescriptList=response.body();
        generateDataList(DescriptList);
    }

    @Override
    public void onFailure(Call<DescriptionModel> call, Throwable t) {
       // progressDialog.dismiss();

        Toast.makeText(getApplicationContext(), "Something went wrong...Please try later!", Toast.LENGTH_SHORT).show();
    }
});

DescriptService

@GET("/v1/android_tutorials/single_tutorial") 
Call<DescriptionModel> getAllPhotos(@Query("tutorial_id") String id);