gpt4 book ai didi

android - 在 Recyclerview 图像在滚动时放错了位置

转载 作者:行者123 更新时间:2023-12-03 18:06:08 26 4
gpt4 key购买 nike

我使用 customview 包含 ImageView 和两个 TextViews,这是我的 RecyclerView.Adapter 我使用 Picasso 库来显示图像。

 public void onBindViewHolder(final ViewHolder holder, final int position) {
Picasso.with(context)
.load(url)
.placeholder(R.drawable.placeholder)
.error(R.drawable.error)
.resize(100, 100)
.into(ivProfile);

holder.tvFirstName.setText(object.getFirstName();
holder.tvSecondName.setText(object.getSecondName);}


public int getItemCount()
{
return profileListDetails.size();
}

class ViewHolder extends RecyclerView.ViewHolder {

public TextView tvFirstName ;
public TextView tvSecondName ;
public ImageView ivProfile;

public ViewHolder(View itemView) {
super(itemView);
ivProfile= (ImageView) itemView.findViewById(R.id.ivProfile);
tvFirstName = (TextView) itemView.findViewById(R.id.tvFirstName );
tvSecondName = (TextView) itemView.findViewById(R.id.tvSecondName );

}
}

还有我的 RecyclerView -
      <android.support.v7.widget.RecyclerView               
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbarAlwaysDrawVerticalTrack="true"
android:scrollbars="vertical>

</android.support.v7.widget.RecyclerView>

Activity 课是:-
public class MainActivity extends AppCompatActivity {

private RecyclerView rv_profileList;
private List<ProfilePOJO> profileList;
private RecyclerView.LayoutManager layoutManager;
private RecyclerView.Adapter recycleAdapter;

protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_profile_list);

rv_profileList = (RecyclerView) findViewById(R.id.rv_profileList );
profileList = new ArrayList<>();

getProfileDetails("");

}


public void getProfileDetails(String ID) {

RestAdapter adapter = new RestAdapter.Builder()
.setEndpoint(Constants.PROFILE_URL)
.build();
API objGetProfile = adapter.create(API.class);


objGetProfile.getProfile(
ID,
new Callback<String>() {
@Override
public void success(String result, Response response) {
try {

Gson gson = new Gson();
Type listType = new TypeToken<List<ProfilePOJO>>() {
}.getType();

profileList = (List<ProfilePOJO>) gson.fromJson(result, listType);

if (profileList.size() != 0) {

recycleAdapter = new ProductListAdapter(productList, MainActivity.this);

rv_profileList.setAdapter(recycleAdapter);

}
} catch (Exception e) {
e.printStackTrace();
}

}

@Override
public void failure(RetrofitError error) {
error.printStackTrace();
Toast.makeText(MainActivity .this, "Please check Internet connection !", Toast.LENGTH_LONG).show();

}

}
);

}
}

问题是当我试图滚动 recyclerview 然后图像改变了,
谁能帮我吗。

最佳答案

谢谢各位回复...
最后我解决了这个问题

public void onBindViewHolder(final ViewHolder holder, final int position) {
Picasso.with(context)
.load(url)
.placeholder(R.drawable.placeholder)
.error(R.drawable.error)
.resize(100, 100)
.into(ivProfile);

我已经在上面的代码中做了一些小的改动......
在上面的代码中,ivProfile 声明为全局,因此无法与 ViewHolder 引用链接。所以我改变了它像下面......
public void onBindViewHolder(final ViewHolder holder, final int position) {
Picasso.with(context)
.load(url)
.placeholder(R.drawable.placeholder)
.error(R.drawable.error)
.resize(100, 100)
.into(holder.ivProfile);

关于android - 在 Recyclerview 图像在滚动时放错了位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39425428/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com