2012-05-25 40 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

相關問題