Я использую ListView в своем приложении с пользовательским адаптером, где в методе getView я устанавливаю свой собственный шрифт, используя TypeFace. Но я не могу видеть этот пользовательский шрифт, а также нет ошибки в моем приложении. Вот файл Java для ListViewПользовательский шрифт в ListView Android
public class Act_Category_ListView extends Activity {
ListView act_list;
//TextView act_tv;
ArrayAdapter<String> listAdapter;
String[] values = new String[]{
"સેવકનુ ખોટુ", "do", "teen", "4", "5", "6", "6", "7", "8", "9", "10"
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.act_category_listview);
act_list = (ListView) findViewById(R.id.act_category_listview);
// act_tv = (TextView)findViewById(R.id.tv_act_category);
// TextView textView = (TextView) rowView.findViewById(R.id.tv_act_category);
listAdapter = new CustomAdapter_ActCategory(this,R.layout.act_category_listview_textview,values);
act_list.setAdapter(listAdapter);
act_list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
int itemPosition = position;
String itemValue = (String) act_list.getItemAtPosition(position);
switch (itemPosition) {
case 0:
Toast.makeText(getApplicationContext(),
"Position :" + itemPosition + " ListItem : " + itemValue, Toast.LENGTH_LONG)
.show();
Intent i1 = new Intent(Act_Category_ListView.this, Main_Activity.class);
startActivity(i1);
break;
case 1:
Toast.makeText(getApplicationContext(),
"Position :" + itemPosition + " ListItem : " + itemValue, Toast.LENGTH_LONG)
.show();
Intent i2 = new Intent(Act_Category_ListView.this, Button2_Class.class);
startActivity(i2);
break;
}
}
});
}
}
CustomAdapter файл
public class CustomAdapter_ActCategory extends ArrayAdapter<String> {
private final Context context;
int layoutResourceId;
String[] values = new String[]{};
TextView textView;
Typeface tf;
public CustomAdapter_ActCategory(Context context,int layoutResourceId,String[] values) {
super(context,layoutResourceId,values);
this.layoutResourceId=layoutResourceId;
this.context=context;
this.values=values;
// tf = Typeface.createFromAsset(context.getAssets(),FONT);
// act_tv = new TextView(context);
// act_tv.findViewById(R.id.tv_act_category);
// act_tv.setTypeface(tf); // set typeface here
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View rowView = inflater.inflate(R.layout.act_category_listview_textview, parent, false);
textView = (TextView) rowView.findViewById(R.id.tv_act_category);
Typeface tf = Typeface.createFromAsset(getContext().getAssets(),"fonts/NotoSansGujarati-Bold.ttf");
textView.setTypeface(tf);
textView.setTextColor(Color.DKGRAY);
return rowView;
}
}
ListView.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff">
<ListView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/act_category_listview"
>
</ListView>
TextView.xml для ListView
<?xml version="1.0" encoding="utf-8"?>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/tv_act_category"
android:layout_gravity="center_horizontal"
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:paddingTop="8dp"
android:paddingBottom="8dp"
android:textColor="@color/dark_gray"
xmlns:android="http://schemas.android.com/apk/res/android" />
Да я с папку шрифтов и да нет никакого текста показ в TextView @ saeed –
Вы не хотите показывать текст в своем тексте? вы не задали текст в текстовом поле – saeed
Шрифт может быть плохо написан –