3

我尝试使用方形毕加索 Web 应用程序。但是如果我的 img url 包含土耳其语字符。毕加索不加载img。

此 URL 有效。 http://www.bulenttiras.com/wp-content/uploads/2014/02/kokhucre.jpg

此 URL 无效 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;
        }
    }

请帮忙。对不起英语不好。谢谢你。

4

2 回答 2

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;
    }
于 2014-11-14T13:49:53.620 回答
1

您的清单上可能缺少 Internet 权限。

编辑:这是代码。

<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!");
            }
        });
    }
}   
于 2014-03-13T13:28:57.150 回答