English 中文(简体)
如何在Android网站服务中显示 Marathi 文字
原标题:How to show marathi text in Android coming from webservice

事实上我知道程序。我用了这个代码:

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

But this is hardcoded and limited. Actually my webservice data which i want to show contains some marathi and English data. whenever marathi data comes it shows me only boxes. here my outputs which looks like this: output

Can anyone know what should i need to do so that i can show data in marathi form. thanks in advance

Here is my code: XMLHandler class

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."
                                    + "
"
                                    + "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) {
            }

        }

    }
}
问题回答

而不是此:

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

写入

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

您实际上需要做的是创建 xml 链接, 其中包含 marathi 单词, 并使用 json 或 sax 剖析器分析 xml 链接 。 用于创建 xml 链接, u 需要 php 开发者的支持 。

如果需要帮助或支持 普尔兹联系我





相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...

热门标签