Android更改自定义列表视图的字体有子项

时间:2015-09-13 10:55:45

标签: android listview android-listview

这里我有一个基本的列表视图。我想更改listView中文本的字体。当然,我希望有subItem。我该怎么办?

MainActivity中的

IN ON CREATE METHOD:

list.setOnItemClickListener(new OnItemClickListener(){
    @Override
    public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
            long arg3) {

        Intent info=new Intent(Main.this, Info.class);
        info.putExtra("id", id[arg2]+"");
        startActivity(info);
    }
});

ON RESUME:

protected void onResume() {
    super.onResume();
    refresh();
}

public void refresh(){
    final dbHandler db=new dbHandler(this);

    final ListView list=(ListView) findViewById(R.id.searchh_list);

    db.open();
    int count=db.Count();

    name=new String[count];
    id=new int[count];

    for(int i=0; i<count; i++){  
     name[i]=db.Display(i,1)+"      =      "+db.Display(i, 2);
     id[i]=Integer.parseInt(db.Display(i, 0));
    }
    db.close();
    list.setAdapter(
        newArrayAdapter<String>(this,android.R.layout.simple_list_item_1,name));
} 

我想在subItems上显示db.Display(i, 2);

1 个答案:

答案 0 :(得分:0)

您可以使用自定义适配器来完成任务。这是一个简单的例子:

public class CustomAdapter extends BaseAdapter {

    Context context;
    public CustomAdapter(Context context) {
        this.context = context;
    }
    .......

    @Override
    public View getView(int position, View view, ViewGroup viewGroup) {
        if (view == null)
            view = LayoutInflater.from(context).inflate(R.layout.yout_list_row_layout);

        TextView textView = view.findViewById(R.id.text_view_id);
        textView.setTypeface(Typeface);
        return view;
    }
}