我刚刚接触安卓并正在使用自定义字体来显示列表视图。我不知道如何在列表视图中使用字体,尝试了不同的示例但无法解决我的问题。以下是我的代码:
public class HomeScreen extends ListActivity {
private static final int QUICK_START_INDEX =0;
private static final int CUSTOM = 1;
private static final int CALL_LIST = 2;
private static final int CALENDAR = 3;
private static final int TEMPLATES=4;
private static final int USER_GUIDE = 5;
static final String[] LIST =
new String[] { "QuickStart", "Custom", "CallList", "Calendar","Templates","UserGuide"};
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setListAdapter(new MobileArrayAdapter(this, LIST));
/*Typeface font = Typeface.createFromAsset(getAssets(), "earthkid.ttf"); */
}
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
//get selected items
String selectedValue = (String) getListAdapter().getItem(position);
/*Toast.makeText(this, selectedValue, Toast.LENGTH_SHORT).show();*/
if(position==QUICK_START_INDEX){
startActivity(new Intent(HomeScreen.this,ConfDialer.class));
}
}
}
MobileArrayAdapter.java
public class MobileArrayAdapter extends ArrayAdapter<String> {
private final Context context;
private final String[] values;
public MobileArrayAdapter(Context context, String[] values) {
super(context, R.layout.list_home, values);
this.context = context;
this.values = values;
}
@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.list_home, parent, false);
TextView textView = (TextView) rowView.findViewById(R.id.label);
ImageView imageView = (ImageView) rowView.findViewById(R.id.logo);
textView.setText(values[position]);
// Change icon based on name
String s = values[position];
System.out.println(s);
if (s.equals("QuickStart")) {
imageView.setImageResource(R.drawable.quick_strat);
} else if (s.equals("Custom")) {
imageView.setImageResource(R.drawable.customize);
} else if (s.equals("CallList")) {
imageView.setImageResource(R.drawable.call_list);
} else if(s.equals("Calendar")){
imageView.setImageResource(R.drawable.calendar);
} else if(s.equals("Templates")){
imageView.setImageResource(R.drawable.templates);
}
else{
imageView.setImageResource(R.drawable.user_guide);
}
return rowView;
}
}
有人能提供这个问题的解决方案吗?