gpt4 book ai didi

android - Android 模拟器上不显示 Tifinagh 字符

转载 作者:行者123 更新时间:2023-11-29 01:49:36 25 4
gpt4 key购买 nike

如您在所附图片中所见,Eclipse 正确显示了 Tifinagh资源文件中 XML 的文本。但是当我将此 XML 解析为 listView 时,它没有显示。我教过它与 XML 解析有关,所以我基于 Hello world 教程创建了一个新项目并替换为“Hello world!”使用 Tifinagh 字符(我从 XML 中复制)并再次;他们不显示。

我检查了一个 similar question在 stackoverflow 上,但还没有答案。

所以;

  1. Android 是否支持 Tifinagh?
  2. 如果没有,是否有解决此问题的解决方法?

感谢您的帮助。

Tifinagh_not_displayed_on_android_emulator

更新

我设法在 hello world 界面中设置了字体:

// Set the tifinagh font
Typeface tf = Typeface.createFromAsset(getAssets(), "t_ircam-webfont.ttf");
TextView tv = (TextView) MainActivity.this.findViewById(R.id.txt);
tv.setTypeface(tf);

但是如何为 ListView 设置它?

    package com.theopentutorials.android.activities;

import java.io.IOException;
import java.util.List;

import android.app.Activity;
import android.graphics.Typeface;
import android.os.Bundle;
import android.view.Menu;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;

import com.theopentutorials.android.beans.PostObj;
import com.theopentutorials.android.xml.XMLPullParserHandler;

public class XMLPullParserActivity extends Activity {

ListView listView;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

// Prepare the list view to publish item to.
listView = (ListView) findViewById(R.id.list);

List<PostObj> posts = null;
try {
XMLPullParserHandler parser = new XMLPullParserHandler();
posts = parser.parse(getAssets().open("amawal_posts.xml"));

System.out.println("============================== ");
System.out.println("Posts fresh "+ posts);
System.out.println("============================== ");

ArrayAdapter<PostObj> adapter = new ArrayAdapter<PostObj>(this, R.layout.list_item, posts);
listView.setAdapter(adapter);
} catch (IOException e) {
e.printStackTrace();
}

}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.xmlpull_parser, menu);
return true;
}

}

最佳答案

经过更多的尝试和错误,我让它工作了:)由于我将原始数据从 XML 获取到 ListView ,因此我必须创建一个自定义适配器,查看完整代码:

package com.theopentutorials.android.xml;

import java.util.List;

import android.content.Context;
import android.graphics.Typeface;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import android.widget.TextView;

public class MyAdapter<T> extends BaseAdapter {

private final Typeface mTypeface;

private List<T> objects; // obviously don't use object, use whatever
// you really want

private final Context context;

public MyAdapter(Context context, int resource, List<T> objects) {//Context context, int resource, List<T> objects
this.context = context;
this.objects = (List<T>) objects;
mTypeface = Typeface.createFromAsset(context.getAssets(), "t_ircam-webfont.ttf");
}

@Override
public int getCount() {
return objects.size();
}

@Override
public Object getItem(int position) {
return objects.get(position);
}

@Override
public long getItemId(int position) {
return position;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {

Object obj = objects.get(position);

TextView tv = new TextView(context);
tv.setTypeface(mTypeface);
tv.setText(obj.toString()); // use whatever method you want for the
// label
// set whatever typeface you want here as well
return tv;
}
}

在我的主要 Activity 中

public class XMLPullParserActivity extends Activity {

ListView listView;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

// Prepare the list view to publish item to.
listView = (ListView) findViewById(R.id.list);

List<PostObj> posts = null;
try {
// Parse the XML
XMLPullParserHandler parser = new XMLPullParserHandler();
posts = parser.parse(getAssets().open("amawal_posts.xml"));

/*System.out.println("============================== ");
System.out.println("Posts fresh " + posts);
System.out.println("============================== ");*/

listView.setAdapter(new MyAdapter<PostObj>(this, R.layout.list_item, posts));


} catch (IOException e) {
e.printStackTrace();
}

}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.xmlpull_parser, menu);
return true;
}
}

在layout/list_item.xml

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >


</TextView>

在layout/main.xml中

    <TextView
android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:text="@string/hello_world"
android:textColor="#CC0033"
android:textSize="16sp" />

<ListView
android:id="@+id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="@id/text" />

</RelativeLayout>

关于android - Android 模拟器上不显示 Tifinagh 字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19053719/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com