错误:找不到符号变量父级错误:找不到符号变量位置

时间:2019-03-25 07:30:10

标签: android android-recyclerview

我一直遇到这两个错误,我尝试添加依赖项并安装android支持存储库,但此错误未解决。我尝试使catche无效并重新启动项目,但这也无济于事。尝试了所有我希望你们能提供的帮助

this is the snapshot

这是我的代码

package ankittx.com.forsale.util;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import java.util.ArrayList;
import ankittx.com.forsale.R;
import ankittx.com.forsale.models.Post;

public class PostListAdapter extends 
RecyclerView.Adapter<PostListAdapter.ViewHolder>{

private static final String TAG = "PostListAdapter";
private static final int NUM_GRID_COLUMNS = 3;

private ArrayList<Post> mPosts;
private Context mContext;

public class ViewHolder extends RecyclerView.ViewHolder{

    ImageView mPostImage;

    public ViewHolder(@NonNull View itemView) {
        super(itemView);
        mPostImage = (ImageView)itemView.findViewById(R.id.post_image);
        int gridWidth = 
mContext.getResources().getDisplayMetrics().widthPixels;
        int imageWidth = gridWidth/NUM_GRID_COLUMNS;
        mPostImage.setMaxHeight(imageWidth);
        mPostImage.setMaxWidth(imageWidth);

    }
}

public PostListAdapter(Context mContext ,ArrayList<Post> mPosts) {
    this.mPosts = mPosts;
    this.mContext = mContext;
}

@NonNull
@Override
public ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
    View view = LayoutInflater.from(mContext).inflate(R.layout.layout_view_post, parent, false);
    return new ViewHolder(view);
}

@Override
public void onBindViewHolder(@NonNull ViewHolder viewHolder, int i) {
    UniversalImageLoader.setImage(mPosts.get(position).getImage(), viewHolder.mPostImage);

}

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

}

1 个答案:

答案 0 :(得分:1)

在参数中使用int i代替int position参数。

更改方法

@Override
public void onBindViewHolder(@NonNull ViewHolder viewHolder, int i) {
    UniversalImageLoader.setImage(mPosts.get(position).getImage(), viewHolder.mPostImage);

}

收件人

@Override
public void onBindViewHolder(@NonNull ViewHolder viewHolder, int position) {
    UniversalImageLoader.setImage(mPosts.get(position).getImage(), viewHolder.mPostImage);

}

使用parent作为父viewGroup而不是viewGroup参数。

@Override
public ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
    View view = LayoutInflater.from(mContext).inflate(R.layout.layout_view_post, parent, false);
    return new ViewHolder(view);
}

@Override
public ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
    View view = LayoutInflater.from(mContext).inflate(R.layout.layout_view_post, viewGroup, false);
    return new ViewHolder(view);
}