我是android.i中的新手使用Picasso库在列表视图中显示图像,但问题是当我向下滚动图像时覆盖并向上滚动图像覆盖。请帮助我。
我认为当我第一次登录时发生的事情看起来很完美,但是一旦我退出并立即登录(没有关闭申请),我就会看到图像被覆盖。
所以请给我解决方案
Homepage.java
superDistributorlist = new listview_data[]
{
new listview_data(R.drawable.adduser, register),
new listview_data(R.drawable.topuptransfer, topup),
new listview_data(R.drawable.memberdebit, mdebit),
new listview_data(R.drawable.voucher, voucher),
new listview_data(R.drawable.complaint, complaint),
new listview_data(R.drawable.complaintstatus, complaint_status),
new listview_data(R.drawable.changesmspin, smspin),
new listview_data(R.drawable.changepwd, changepwd),
new listview_data(R.drawable.mobilenochange, change_mobileno),
new listview_data(R.drawable.table2, reports)
};
adapter = new ListviewAdapter(HomePage.this, R.layout.listview_item_row, superDistributorlist);
lv.setAdapter(adapter);
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
LinearLayout ll = (LinearLayout) view; // get the parent layout view
TextView tv = (TextView) ll.findViewById(R.id.txtTitle); // get the child text view
final String item = tv.getText().toString();
Intent i;
if (item.equals(getResources().getString(R.string.txt_Registration))) {
i = new Intent(HomePage.this, Registration.class);
overridePendingTransition(R.anim.pull_in_right, R.anim.push_out_left);
startActivity(i);
finish();
}else if (item.equals(getResources().getString(R.string.txt_topup))) {
i = new Intent(HomePage.this, TopupTransfer.class);
overridePendingTransition(R.anim.pull_in_right, R.anim.push_out_left);
startActivity(i);
finish();
}else if (item.equals(getResources().getString(R.string.txt_changesmspin))) {
Log.d("Item2 ", "" + item);
i = new Intent(HomePage.this, ChangeSmspin.class);
overridePendingTransition(R.anim.pull_in_right, R.anim.push_out_left);
startActivity(i);
finish();
}else if (item.equals(getResources().getString(R.string.txt_changepwd))) {
Log.d("Item3 ", "" + item);
i = new Intent(HomePage.this, ChangePwd.class);
overridePendingTransition(R.anim.pull_in_right, R.anim.push_out_left);
startActivity(i);
finish();
}else if (item.equals(getResources().getString(R.string.txt_complaint))) {
i = new Intent(HomePage.this, ComplaintRegister.class);
overridePendingTransition(R.anim.pull_in_right, R.anim.push_out_left);
startActivity(i);
finish();
}else if (item.equals(getResources().getString(R.string.txt_reports))) {
i = new Intent(HomePage.this, ReportList.class);
overridePendingTransition(R.anim.pull_in_right, R.anim.push_out_left);
startActivity(i);
finish();
}else if (item.equals(getResources().getString(R.string.txt_complaint_status))) {
i = new Intent(HomePage.this, ComplaintStatus.class);
overridePendingTransition(R.anim.pull_in_right, R.anim.push_out_left);
startActivity(i);
finish();
}else if (item.equals(getResources().getString(R.string.txt_mdebit))) {
i = new Intent(HomePage.this, memberdebit.class);
overridePendingTransition(R.anim.pull_in_right, R.anim.push_out_left);
startActivity(i);
finish();
}else if (item.equals(getResources().getString(R.string.changemobileno))) {
i = new Intent(HomePage.this, ChangeMobNo.class);
overridePendingTransition(R.anim.pull_in_right, R.anim.push_out_left);
startActivity(i);
finish();
}
}
});
}
ListviewAdaper.java
public class ListviewAdapter extends ArrayAdapter<listview_data> {
Context context;
int layoutResourceId;
listview_data data[] = null;
ImageLoader imgloader;
String url;
public ListviewAdapter(Context context, int layoutResourceId, listview_data[] data) {
super(context, layoutResourceId, data);
this.layoutResourceId = layoutResourceId;
this.context = context;
this.data = data;
imgloader = new ImageLoader(context);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View row = convertView;
listHolder holder = null;
if(row == null)
{
LayoutInflater inflater = ((Activity)context).getLayoutInflater();
row = inflater.inflate(layoutResourceId, parent, false);
holder = new listHolder();
listHolder.imgIcon = (ImageView)row.findViewById(R.id.imgIcon);
holder.txtTitle = (TextView)row.findViewById(R.id.txtTitle);
row.setTag(holder);
}
else
{
holder = (listHolder)row.getTag();
}
listview_data list = data[position];
holder.txtTitle.setText(list.title);
//holder.imgIcon.setImageResource(list.icon);
Picasso.with(context).cancelRequest(listHolder.imgIcon);
Picasso.with(context)
.load(list.icon)
.resize(48,48)
.error(R.drawable.imagenotavailable)
.into(holder.imgIcon);
return row;
}
static class listHolder
{
static ImageView imgIcon;
TextView txtTitle;
}
}
答案 0 :(得分:0)
Picasso
.with(context)
.load(imageUrls[position])
.fit() // will explain later
.into((ImageView) convertView);
使用持有人模式,
Picasso.with(this.context).load(history.icon).into(holder.imageIcon)
希望这会对你有所帮助。
答案 1 :(得分:0)
更改 listHolder.imgIcon =(ImageView)row.findViewById(R.id.imgIcon);
要
holder.imgIcon =(ImageView)row.findViewById(R.id.imgIcon);