Android Square Picasso无法加载土耳其语角色图片网址

时间:2014-03-13 13:07:19

标签: android picasso

我尝试使用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;
        }
    }

请帮忙。 抱歉坏英语。 谢谢。

2 个答案:

答案 0 :(得分:2)

我有同样的问题。我能找到的唯一选择是将所有单一的土耳其字符替换为编码的字符。

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;
    }

答案 1 :(得分:1)

您可能缺少清单上的互联网权限。

编辑:这是代码。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:src="@drawable/ic_launcher" />

</LinearLayout>




public class MainActivity extends Activity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Picasso.with(this).load("http://www.bulenttiras.com/wp-content/uploads/2014/03/t%C3%BCp-bebek-tedavisi.jpg").into((ImageView)findViewById(R.id.imageView1), new Callback() {

            @Override
            public void onSuccess() {
                Log.v("Information", "Success!");
            }

            @Override
            public void onError() {
                Log.v("Information", "FAIL!");
            }
        });
    }
}