如何获得RecyclerView在改造界面上的位置?

时间:2017-02-06 11:13:18

标签: android android-recyclerview retrofit2

我正在尝试将标记重定向到该特定标记的帖子关联列表中,我在找到并传递下面给出的代码上点击的RecyclerView的位置时遇到问题

private final static String TAG_KEY = "1"; //How Do I Make it to take Position of RecyclerView so that post associate with that Tag can be opened

 ApiInterface apiService =
            ApiClient.getClient().create(ApiInterface.class);



    Call<Tag> call = apiService.getTag(TAG_KEY);
    call.enqueue(new Callback<Tag>() {
        @Override
        public void onResponse(Call<Tag> call, Response<Tag> response) {
            int statusCode = response.code();
            List<Post> tags = response.body().getTagPosts();
            recyclerView.setAdapter(new PostListAdapter(tags, R.layout.list_item_post, getApplicationContext()));
        }

        @Override
        public void onFailure(Call<Tag> call, Throwable t) {
            // Log error here since request failed
            Log.e(TAG, t.toString());
        }
    });

如何在Intent的适配器实例上调用接口

 @Override
public void onBindViewHolder(TagAdapter.Tag_ViewHolder holder, final int position) {
    holder.tagName.setText(Tags.get(position));
    holder.itemView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            //Toast.makeText(context, "Recycle Click" + position, Toast.LENGTH_SHORT).show();
            if (position == 0){
                Intent intent = new Intent (view.getContext(), TagToPostActivitiy.class);
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                context.startActivity(intent);

            }

List of Post Associated with Tag C List of Tag

1 个答案:

答案 0 :(得分:0)

你的问题不明确,如果我告诉你我假设你想发送不同的请求,具体取决于当前点击的recycleView项目。所以: 在里面

<div id="modal" style="witdh: {{(100 / $t->spotdiff)}}"></div>

你正在膨胀一些视图,所以只需将它设置在onClickListener:

<script type="text/javascript">
    $("#modal").css("width", "{{(100 / $t->spotdiff)}}");
</script>

clickListener应该处理具有正确位置的api请求

public Adapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType)