似乎是一个简单的问题,但由于我是Android开发的新手,我对AndroID ListVIEws一无所知.以下是我在项目中用于ListVIEw的代码.
/*ListvIEw code starts*/mainListVIEw = (ListVIEw) findVIEwByID( R.ID.mainListVIEw );ArrayList<String> planetList = new ArrayList<String>(); planetList.addAll( Arrays.asList(values) );listadapter = new ArrayAdapter<String>(this, R.layout.List1, values);mainListVIEw.setAdapter(listadapter); mainListVIEw.setonItemClickListener(new OnItemClickListener() { @OverrIDe public voID onItemClick(AdapterVIEw<?> parent, VIEw vIEw, int position, long ID) {// Todo auto-generated method stub int itemposition = position; String itemValue = (String) mainListVIEw.getItemAtposition(position); Toast.makeText(getApplicationContext(), "position :"+itemposition+" ListItem : " +itemValue , Toast.LENGTH_LONG) .show(); }});/*ListvIEw code ends*/
我想更改ListVIEw文本的字体.我怎么做?随处读取使用自定义适配器,但不明白.任何人都可以帮我代码吗?
解决方法:
如果你想通过创建一个新的ArrayAdapter并通过覆盖getVIEw()方法来访问ListVIEw中的项目.请查看Adapter#getView .. Here和Here是关于自定义ListVIEw的好教程.
示例自定义ArrayAdapter将是这样的.
public class CustomArrayAdapter extends ArrayAdapter<String> { private final Context context; private final String[] values; public CustomArrayAdapter(Context context, String[] values) { super(context, R.layout.List_mobile, 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_mobile, parent, false); TextVIEw textVIEw = (TextVIEw) rowVIEw.findVIEwByID(R.ID.label); ImageVIEw imageVIEw = (ImageVIEw) rowVIEw.findVIEwByID(R.ID.logo); // Customization to your textVIEw here textVIEw.setText("Hello"); textVIEw.setTypeface(my_custom_typeface); textVIEw.setTextSize(20); return rowVIEw; }}
你可以像这样创建一个新的CustomArrayAdapter.
CustomArrayAdapter my_adapter = new CustomArrayAdapter();setlistadapter(my_adapter);
参考:Android TextView Methods.
总结以上是内存溢出为你收集整理的Android更改ListView字体全部内容,希望文章能够帮你解决Android更改ListView字体所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)