Как решить проблемы с кодировкой?

Пытаюсь добавить через webview текст в формате txt или html, но вместо текста крокозябры (вопросы), в чем проблема?

1 активити

public class FGD extends Activity 
{
	private ListView lv1;
	private ImageView splash;
	private static final int STOPSPLASH = 0;
	private static final long SPLASHTIME = 0; 
	
	
	private String lv_arr[]={
			"1.  0",//n0
			"2. 1",//n1
			"3. 2",//n2
			"4. 3"//n7
			};
	
	private Handler splashHandler = new Handler() 
	{
		@Override
		public void handleMessage(Message msg) 
		{
			switch (msg.what) 
			{
			    case STOPSPLASH:
				    
				    splash.setVisibility(View.GONE);
				    break;
			}
			super.handleMessage(msg);
		}
	};
	
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        
        splash = (ImageView) findViewById(R.id.splashscreen); 
        Message msg = new Message();
        msg.what = STOPSPLASH;
        splashHandler.sendMessageDelayed(msg, SPLASHTIME);
        
        
        lv1 = (ListView)findViewById(R.id.listView);
        
        lv1.setAdapter(
        		new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1 , lv_arr));
        lv1.setTextFilterEnabled(true);
              
        
        lv1.setOnItemClickListener(new OnItemClickListener() 
        {
        	public void onItemClick(AdapterView<?> a, View v, int position, long id) 
        	{
                
                String itemname = new Integer(position).toString();  
                
                Intent intent = new Intent();
                
                intent.setClass(CribActivity.this, ViewActivity.class);
                
                Bundle b = new Bundle();
                
               
                b.putString("defStrID", itemname); 
                
                intent.putExtras(b);
                
                
                startActivity(intent);
             }
		});
    }
}


2 активити
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.Window;
import android.view.WindowManager;
import android.webkit.WebView;

public class ViewActivity extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
        requestWindowFeature(Window.FEATURE_NO_TITLE); 
        
        setContentView(R.layout.view);
        
        
        
        
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
        WindowManager.LayoutParams.FLAG_FULLSCREEN);
        
        Bundle bundle = getIntent().getExtras();
        
		String itemname = "n" + bundle.getString("defStrID"); 
		
		Context context = getBaseContext(); 
		
		
		String text = readRawTextFile(context, getResources().getIdentifier(itemname, "raw", "ass.ds.ds"));
		
        WebView myWebView = (WebView) findViewById(R.id.webView);
        String summary = "<!Doctype html><html><head><meta charset=utf-8></head><body>" + text + "</body></html>";
        myWebView.loadData(summary, "text/html; charset=utf-8", "utf-8"); 
    }
    
    public static String readRawTextFile(Context ctx, int resId) 
    {
         InputStream inputStream = ctx.getResources().openRawResource(resId);

            InputStreamReader inputreader = new InputStreamReader(inputStream);
            BufferedReader buffreader = new BufferedReader(inputreader);
             String line;
             StringBuilder text = new StringBuilder();

             try {
               while (( line = buffreader.readLine()) != null) {
                   text.append(line);
                   text.append('\n');
                 }
           } catch (IOException e) {
               return null;
           }
             return text.toString();
    }
}
  • Вопрос задан
  • 2861 просмотр
Решения вопроса 1
mbhusty
@mbhusty
я так делал
myWebView.loadDataWithBaseURL(null,summary,"text/html" ,"utf-8",null);
Ответ написан
Пригласить эксперта
Ответы на вопрос 1
@bamond
попробуй charset=windows-1251
Ответ написан
Комментировать
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы