我正在对我的XML解析"http://cinema.dinamalar.com/rss.php“使用此API来获取列表中的泰米尔语新闻,但它不起作用。请帮帮我..这是我的代码..
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();
}
}发布于 2019-02-27 15:41:33
首先,你必须明白,在安卓操作系统中没有泰米尔语支持(除了少数三星和SE手机),直到ICS(4.0)。即使在那时,它也有bug,并且Jelly Bean (4.2)提供了完整的支持。
如果你在你的应用程序中使用Unicode Tamil字体,你会看到方框。原因是系统中没有泰米尔字体。
1.手动操作方式
这个解决方案有一个变通的方法。您所要做的就是下载Bamini字体并将其放入您的assets文件夹中。并使用Bamini字体创建TypeFace,并将其设置为TextView。
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项目中,并调用该库,如下所示。
// 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字体)。
https://stackoverflow.com/questions/15850261
复制相似问题