2014-09-30 32 views
1

我有问题,我想为我的列表视图创建一个自定义设计,但我不知道该怎么做。我使用了一个在我的列表视图中的sql数据库。哈哈对不起,我不知道该怎么说这个......因为我是德国人......所以对我的englsih感到抱歉。这里是我的代码:如何更改我的ListView项目的字体?

private void populateListViewFromDB() { 
    Cursor cursor = myDb.getAllRows(); 

    startManagingCursor(cursor); 


    String[] fromFieldNames = new String[] 
      {DBAdapter.KEY_NAME, DBAdapter.KEY_STUDENTNUM, DBAdapter.KEY_FAVCOLOUR, DBAdapter.KEY_STUDENTNUM}; 
    int[] toViewIDs = new int[] 
      {R.id.item_name,  R.id.item_icon,   R.id.item_favcolour,  R.id.item_studentnum}; 


    SimpleCursorAdapter myCursorAdapter = 
      new SimpleCursorAdapter(
        this,  
        R.layout.item_layout, 
        cursor,     
        fromFieldNames,   
        toViewIDs    
        ); 

    // Set the adapter for the list view 
    ListView myList = (ListView) findViewById(R.id.listViewFromDB); 
    myList.setAdapter(myCursorAdapter); 
} 

谢谢你的帮助:)

+0

你必须创建一个自定义适配器来做到这一点.. – 2014-09-30 12:47:55

+0

但我已经使用了一个适配器。这可以工作吗? – 360Productions 2014-09-30 12:48:49

+0

1)你可以设定你想要的任何自定义字体。 2)但是,只有在真正需要时才应该这样做。用户可以在设备的设置中选择他们想要的任何自定义字体。如果你强制使用其他字体,你只会惹恼那些想要自定义字体的字体。 – 2014-09-30 12:48:53

回答

1

试试这个办法,希望这将帮助你解决你的问题。

下面是该问题的详细说明。

http://javatechig.com/android/using-external-fonts-in-android-view

基本上适合你,因为它是在ListView我建议你创建自定义的TextView。将字体文件放置在资产文件夹中很重要。

+0

感谢洛特! – 360Productions 2014-09-30 13:16:54

+0

@ 360Productions,很高兴帮助你.. – 2014-10-01 04:37:24