2012-05-25 47 views
5

我需要在我的应用程序中显示marathi文本。其实我知道这个程序。我已经使用此代码:如何显示来自webservice的Android中的marathi文本

Typeface font = Typeface.createFromAsset(getAssets(), "Marathi-Saras.TTF"); 
     userNameTxt.setTypeface(font); 
     userNameTxt.setText("Marathi"); 

但是这是硬编码和有限的。其实我想显示的web服务数据包含一些马拉地语和英语数据。每当marathi数据到来时,它只显示箱子。 这里我输出看起来像这样: output

谁能知道我应该怎么需要做的,这样我可以显示马拉表单数据。 由于事先

这里是我的代码: XMLHandler类

package com.app.unipune.announcements.parserHandler; 

import org.xml.sax.Attributes; 
import org.xml.sax.SAXException; 
import org.xml.sax.helpers.DefaultHandler; 

import android.text.Html; 

public class AnnouncementHandler extends DefaultHandler { 
    public static ItemList itemList; 
    public boolean current = false; 
    public String currentValue = null; 

    @Override 
    public void startElement(String uri, String localName, String qName, 
      Attributes attributes) throws SAXException { 
     current = true; 
     if (localName.equals("channel")) { 
      itemList = new ItemList(); 
     } 
    } 

    @Override 
    public void endElement(String uri, String localName, String qName) 
      throws SAXException { 
     current = false; 
     if (localName.equals("title")) { 
      itemList.setTitle(currentValue); 
     } else if (localName.equals("author")) { 
      itemList.setLink(currentValue); 
     } else if (localName.equals("description")) { 
      itemList.setDescription(currentValue); 

     }else if(localName.equals("guid")) 
     { 
      itemList.setGuid(currentValue); 
      System.out.println(currentValue); 
     } 
    } 

    @Override 
    public void characters(char[] ch, int start, int length) 
      throws SAXException { 
     if (current) { 
      currentValue = new String(ch, start, length); 
      current = false; 
     } 
    } 

} 

这里我使用它:

package com.app.unipune.announcements; 

import java.net.URL; 
import java.util.ArrayList; 

import javax.xml.parsers.SAXParser; 
import javax.xml.parsers.SAXParserFactory; 

import org.xml.sax.InputSource; 
import org.xml.sax.XMLReader; 

import android.app.Activity; 
import android.app.AlertDialog; 
import android.app.ProgressDialog; 
import android.content.Context; 
import android.net.ConnectivityManager; 
import android.net.NetworkInfo; 
import android.os.Bundle; 
import android.os.Handler; 
import android.os.Message; 
import android.text.method.LinkMovementMethod; 
import android.widget.ListView; 

import com.app.unipune.announcements.parserHandler.Adapter; 
import com.app.unipune.announcements.parserHandler.AnnouncementHandler; 
import com.app.unipune.announcements.parserHandler.ItemList; 

public class Announcements extends Activity { 
    private ProgressDialog dialog; 
    ItemList itemList; 

    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 

     setContentView(R.layout.descriptionlist); 
     if (isInternetOn() == true) { 
      dialog = ProgressDialog.show(this, "Loading", "Please Wait...", 
        true, false); 

      System.out.println("start call"); 
      Handler myHandler = new DoParsing(); 
      Message m = new Message(); 
      myHandler.sendMessageDelayed(m, 2000); 
      System.out.println("end Call"); 
     } else { 
      new AlertDialog.Builder(Announcements.this) 
        .setTitle("Error") 
        .setMessage(
          "Your device is not Connected to the Internet." 
            + "\n" 
            + "Please make connection to proceed ") 
        .setPositiveButton("OK", null).show(); 
     } 

    } 

    public final boolean isInternetOn() { 
     ConnectivityManager connec = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); 
     if (connec.getNetworkInfo(0).getState() == NetworkInfo.State.CONNECTED 
       || connec.getNetworkInfo(0).getState() == NetworkInfo.State.CONNECTING 
       || connec.getNetworkInfo(1).getState() == NetworkInfo.State.CONNECTING 
       || connec.getNetworkInfo(1).getState() == NetworkInfo.State.CONNECTED) { 
      return true; 
     } else if (connec.getNetworkInfo(0).getState() == NetworkInfo.State.DISCONNECTED 
       || connec.getNetworkInfo(1).getState() == NetworkInfo.State.DISCONNECTED) { 
      return false; 
     } 
     return false; 
    } 

    public class DoParsing extends Handler { 
     @Override 
     public void handleMessage(Message msg) { 
      try { 

       URL url = new URL(
         "http://uopnews.unipune.ac.in/_layouts/listfeed.aspx?List={E1D35B2C-88CA-40FF-A956-C01C44A45DC8}"); 
       System.out.println("URL= " + url); 
       SAXParserFactory saxPF = SAXParserFactory.newInstance(); 
       SAXParser saxP = saxPF.newSAXParser(); 
       XMLReader xmlR = saxP.getXMLReader(); 
       AnnouncementHandler handler = new AnnouncementHandler(); 
       xmlR.setContentHandler(handler); 
       xmlR.parse(new InputSource(url.openStream())); 

       itemList = new ItemList(); 
       itemList = AnnouncementHandler.itemList; 

       ArrayList<String> title = itemList.getTitle(); 
       System.out.println("title=" + title); 
       ArrayList<String> des = itemList.getDescription(); 
       ArrayList<String> link = itemList.getLink(); 

       Adapter adapter = new Adapter(Announcements.this, title, des,link); 

       ListView lview = (ListView) findViewById(R.id.searchList); 
       lview.setAdapter(adapter); 

       dialog.dismiss(); 
      } catch (Exception e) { 
      } 

     } 

    } 
} 
+0

检查此链接http://stackoverflow.com/a/10637645/1012284 –

+0

@Agarwal,我需要20 reputaion和你谈谈:(我刚刚有5个,因为我在这里是新的。 – Neha

+0

@Neha:你是否设法解决这个问题?如果是的话请告诉我怎么做? – dd619

回答

0

什么ü真正需要做的是创建一个包含一个XML链接马拉地语的话,并解析XML链接使用JSON或SAX解析器..创建XML链接,你需要一个PHP开发人员的支持。

如果您需要任何帮助或支持,请与我联系。

+0

plz请访问此链接:view-source:http://uopnews.unipune。 ac.in/_layouts/listfeed.aspx?List={E1D35B2C-88CA-40FF-A956-C01C44A45DC8}及其页面源码。我是direc tly使用SAX解析器解析它。我需要为这个只有英语和另一个为MArathi做两个单独的Web服务吗? – Neha

+0

Neha,我无法看到刚刚发送给我的链接中的内容。当我尝试查看内容时,收到此消息 - “返回站点 错误”缺少必需的查询字符串:列表。 解决Windows SharePoint Services的问题。 – DeepakAndroid

+0

请勿直接点击此链接。复制它,然后将其粘贴到谷歌Chrome – Neha

2

,而不是这样的:

Typeface font = Typeface.createFromAsset(getAssets(), "Marathi-Saras.TTF"); 

Typeface font = Typeface.createFromAsset(getAssets(), "fonts/Marathi-Saras.TTF"); 
+0

也将您的.ttf文件放置在您需要在资产文件夹中创建的字体文件夹中。 –

+0

我认为用户想要使用两种字体而不是单个ttf。 Bocz收到的数据就像是英语和马拉地语的混合物。它如何帮助实际? –

+0

@Agarwal,请检查我的输出你可能会知道我真的想要显示 – Neha

相关问题