Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/224.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/http/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
具有特殊字符的Android http post_Android_Http_Utf 8_Special Characters - Fatal编程技术网

具有特殊字符的Android http post

具有特殊字符的Android http post,android,http,utf-8,special-characters,Android,Http,Utf 8,Special Characters,我的php站点呼应着“härär du/x vår i sikte”,它在我的chrome浏览器中显示为“härär du/x vår i sikte” 但当我在java/android应用程序中使用httppost阅读时,所有特殊字符(åäö)都显示为问号。我的网络托管服务使用UtF-8。 有没有办法转换我的字符串 这是我的密码: StringBuffer response = new StringBuffer(); try { // Create a new HTTP Client

我的php站点呼应着“härär du/x vår i sikte”,它在我的chrome浏览器中显示为“härär du/x vår i sikte”

但当我在java/android应用程序中使用httppost阅读时,所有特殊字符(åäö)都显示为问号。我的网络托管服务使用UtF-8。 有没有办法转换我的字符串

这是我的密码:

StringBuffer response = new StringBuffer();
try {
    // Create a new HTTP Client
    DefaultHttpClient defaultClient = new DefaultHttpClient();
    // Setup the get request
    HttpPost post = new HttpPost("my.php");
    try {
        post.setHeader("Content-Type",
                "application/x-www-form-urlencoded;charset=UTF-8");

        MultipartEntityBuilder builder = MultipartEntityBuilder
                .create();
        builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);

        final HttpEntity entity = builder.build();
        post.setEntity((HttpEntity) entity);

        //builder.addTextBody("rubrik_nr", all_rubrik, ContentType.TEXT_PLAIN);     
        HttpResponse resp = defaultClient.execute(post);
    }catch(Exception E){

    }
    // Execute the request in the client
    HttpResponse httpResponse = defaultClient
            .execute(post);

    BufferedReader in = new BufferedReader(new InputStreamReader(
            httpResponse.getEntity().getContent(),"UTF-8"));
    String inputLine;

while ((inputLine = in.readLine()) != null) {
    response.append(inputLine);
}
in.close();
Log.d("DEBUG", "response: " + response.toString());


} catch (IOException e) {
Log.d("DEBUG", "j " + response.toString());
e.printStackTrace();
}

return response.toString();
}

我认为,因为setonclikListener是一个函数/监听器,而I变量是局部变量,您不需要将此变量作为参数传递,所以可以将此变量作为属性,将public int I=x放在类的顶部

首先,变量
I
超出了监听器的范围,因此您不能使用它

其次,请记住,for循环完成后将调用click侦听器,因此不可能使用变量
i
(它不再存在)。但是,当您声明最后一个变量时,它将始终在侦听器中可用。但是,您将无法更改它的值

for(int i=0;i<end;i++)
{   
    //bilder
    ImageView replace_img= new ImageView(this);
    replace_img.setImageResource(R.drawable.image_replace);
    RelativeLayout.LayoutParams tmp= new RelativeLayout.LayoutParams(250,250);
    newImg.add(replace_img);                
    ImageView v=  newImg.get(i);
    v.setId(i+1);

    // Set the final int that will be available in inner classes
    final int myInt = i;

    v.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View vi) {            
            vi.setOnClickListener(new View.OnClickListener() 
            { 
                @Override
                public void onClick(View v) 
                { 
                    // "myInt" is still usable here, however "i" is not
                    Intent o = new Intent(getBaseContext(), Edit_post2.class);
                    o.putExtra("POST_NR", myInt);
                    Post_list.this.startActivity(o); 
                }
            });
        }
    });
}

for(int i=0;i因为
onClick
方法与循环和变量
i
不在同一范围内。