Android Square Picasso无法加载土耳其语字符图片网址
作者:互联网
我尝试使用方形毕加索Web应用程序.
但是,如果我的img网址包含土耳其语字符.
毕加索无法加载img.
这个网址有效.
http://www.bulenttiras.com/wp-content/uploads/2014/02/kokhucre.jpg
但
此网址不起作用
http://www.bulenttiras.com/wp-content/uploads/2014/03/t%C3%BCp-bebek-tedavisi.jpg
public class CategoryAdapterClass extends BaseAdapter {
private List<CategoryHelper> categoryHelpers;
private Context context;
public CategoryAdapterClass(List<CategoryHelper> categoryHelpers, Context context) {
this.categoryHelpers = categoryHelpers;
this.context = context;
}
@Override
public int getCount() {
return categoryHelpers.size();
}
@Override
public CategoryHelper getItem(int position) {
return categoryHelpers.get( position );
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder viewHolder;
CategoryHelper categoryHelper = getItem( position );
if( convertView == null ) {
viewHolder = new ViewHolder();
convertView = LayoutInflater.from( context ).inflate(R.layout.all_categories_inflate, parent, false);
viewHolder.categoryImage = (ImageView) convertView.findViewById( R.id.categoryImage );
viewHolder.category_title = (TextView) convertView.findViewById( R.id.category_title );
viewHolder.category_excerpt = (TextView) convertView.findViewById( R.id.category_excerpt );
convertView.setTag( viewHolder );
}
else {
viewHolder = (ViewHolder) convertView.getTag();
}
String query = null;
try {
query = URLEncoder.encode(categoryHelper.getCategory_image(), "utf-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
viewHolder.category_title.setText( categoryHelper.getCategory_image() );
viewHolder.category_excerpt.setText( categoryHelper.getCategory_excerpt() );
Picasso.with( context ).load( query ).into( viewHolder.categoryImage );
return convertView;
}
private class ViewHolder {
ImageView categoryImage;
TextView category_title;
TextView category_excerpt;
}
}
请帮忙.
对不起英语不好.
谢谢.
解决方法:
我遇到过同样的问题.我唯一能找到的选择就是用编码后的字符替换所有单个土耳其语字符.
public static String encodeTurkishCharactersInUrl(String url) {
String[] list = new String[] {"ü","ç","ı","ö","ğ","ş"," ","Ü","Ç","İ","Ö","Ğ","Ş"};
for (int i = 0; i< list.length ; i++) {
try {
url = url.replace(list[i], URLEncoder.encode(list[i],"UTF-8"));
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
}
return url;
}
标签:picasso,android 来源: https://codeday.me/bug/20191122/2056119.html