5

I need to show marathi text in my application. Actually i know the procedure . I have used this code :

 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;
        }
    }

}

here i am using it :

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) {
            }

        }

    }
}
Neha
  • 245
  • 5
  • 17

2 Answers2

2

instead of this:

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

write

 Typeface font = Typeface.createFromAsset(getAssets(), "fonts/Marathi-Saras.TTF");
PrincessLeiha
  • 3,144
  • 4
  • 32
  • 53
0

What u actually need to do is create an xml link that contains the marathi words,and parse that xml link using json or sax parser..for creating the xml links,u need the support of a php developer.

If u need any help or support,plz contact me.

DeepakAndroid
  • 137
  • 1
  • 8
  • plz visit this link: view-source:http://uopnews.unipune.ac.in/_layouts/listfeed.aspx?List={E1D35B2C-88CA-40FF-A956-C01C44A45DC8} and its page source. i am directly parsing this using SAX parser. Can i need to make two seperate webservices for this one for only English and another for MArathi? – Neha May 25 '12 at 07:19
  • Neha,am not able to see the contents in the link that u have just sent me.When i try to see the contents,am getting this message-"Go back to site Error "Missing required query string: List. Troubleshoot issues with Windows SharePoint Services. – DeepakAndroid May 25 '12 at 07:25
  • do not click directly on this link. Copy it and then paste it in google Chrome – Neha May 25 '12 at 07:29