首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用tamil新闻API进行Android XML解析

使用tamil新闻API进行Android XML解析
EN

Stack Overflow用户
提问于 2013-04-06 19:19:46
回答 1查看 1.3K关注 0票数 2

我正在对我的XML解析"http://cinema.dinamalar.com/rss.php“使用此API来获取列表中的泰米尔语新闻,但它不起作用。请帮帮我..这是我的代码..

代码语言:javascript
复制
public class MainActivity extends Activity {
  TextView tv1,tv2,tv3;
  String URL = "http://cinema.dinamalar.com/rss.php";

  // XML node keys
  String KEY_ITEM = "item"; // parent node
  String KEY_TITLE = "title";
  String KEY_LINK = "link";
  String KEY_DESC = "description";
  String KEY_DATE = "pubDate";


  @SuppressLint("SetJavaScriptEnabled")
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    tv1 = (TextView) findViewById(R.id.textView1);
    tv2 = (TextView) findViewById(R.id.textView2);
    tv3 = (TextView) findViewById(R.id.textView3);

    StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();

    StrictMode.setThreadPolicy(policy);

    XMLParser parser = new XMLParser();

    String xml = parser.getXmlFromUrl(URL); // getting XML
    Document doc = parser.getDomElement(xml); // getting DOM element

    //p.getElementsByTagName('Category')[0].firstChild.wholeText

    tv1.setText(parser.getValue((Element) doc.getElementsByTagName(KEY_ITEM).item(0),KEY_TITLE).toString());

    tv2.setText(parser.getValue((Element) doc.getElementsByTagName(KEY_ITEM).item(0),KEY_AUTHOR).toString());
    tv3.setText(parser.getValue((Element) doc.getElementsByTagName(KEY_ITEM).item(0),KEY_LINK).toString());
    Toast.makeText(this,parser.getValue((Element) doc.getElementsByTagName(KEY_ITEM).item(0),KEY_LINK),Toast.LENGTH_SHORT).show();

  }
}
EN

回答 1

Stack Overflow用户

发布于 2019-02-27 15:41:33

首先,你必须明白,在安卓操作系统中没有泰米尔语支持(除了少数三星和SE手机),直到ICS(4.0)。即使在那时,它也有bug,并且Jelly Bean (4.2)提供了完整的支持。

如果你在你的应用程序中使用Unicode Tamil字体,你会看到方框。原因是系统中没有泰米尔字体。

1.手动操作方式

这个解决方案有一个变通的方法。您所要做的就是下载Bamini字体并将其放入您的assets文件夹中。并使用Bamini字体创建TypeFace,并将其设置为TextView。

代码语言:javascript
复制
Typeface font1 = Typeface.createFromAsset(getAssets(), "fonts/Bamini.ttf");
customText1.setTypeface(font1);

现在使用转换器将Unicode字体转换为Bamini编码。将转换后的Bamini编码脚本提供到setText方法中,而不是Unicode文本。

2.使用库

如果您讨厌所有这些手动编码转换,请查看此库

正如我在上面一行中所说的,如果你想在运行应用程序时动态更改编码,那么可以考虑使用我为Android编写的库。这个库可以帮助你将Unicode字符串转换成Bamini,TSCII,TAB,TAM和Anjal。

设置非常简单。您所要做的就是简单地将库导入到您的Android项目中,并调用该库,如下所示。

代码语言:javascript
复制
// Initialise the Typeface (assumes TSCII, Bamini, Anjal, TAB or TAM font located inside assets/fonts folder)
Typeface tf = Typeface.createFromAsset(getAssets(),"fonts/mylai.ttf");
// Initialises the TextView
TextView tv = (TextView)findViewById(R.id.textView1);
//Setting the Typeface
tv.setTypeface(tf);
//Magic happens here ;) encoding conversion
String TSCIIString = TamilUtil.convertToTamil(TamilUtil.TSCII, "வணக்கம் அன்ரொயிட்");
//Setting the new string to TextView
tv.setText(TSCIIString);

该库提供了一个示例应用程序。查看该应用程序,了解如何利用该库将Unicode字符串转换为Bamini、TAB、TAM、TSCII和Anjal。

您需要使用Android中提供的TypeFace类。您可以使用Bamini或TSCII编码(Mylai是TSCII字体)。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15850261

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档