如何使用适配器将自定义字体设置为 ListView 项中的 TextView 之一?
我使用了这段代码,但在getView方法中出现运行时异常。
import java.util.ArrayList;
import java.util.HashMap;
import android.view.ViewGroup;
import com.hands.daily.duas.database.MyDbClass;
import android.app.Activity;
import android.content.Context;
import android.graphics.Typeface;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.BaseAdapter;
import android.widget.TextView;
public class LazyAdapter extends BaseAdapter {
static int i=11;
private Activity activity;
public ArrayList<HashMap<String, String>> data;
private static LayoutInflater inflater=null;
First fst=new First();
// public ImageLoader imageLoader;
String urlString="";
MyDbClass mdbclass;
public LazyAdapter(Activity a, ArrayList<HashMap<String, String>> list) {
data=new ArrayList<HashMap<String, String>>();
activity = a;
data=list;
inflater=(LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
// imageLoader=new ImageLoader(activity.getApplicationContext());
}
public int getCount() {
return data.size();
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
View vi=convertView;
if(convertView==null)
vi = inflater.inflate(R.layout.duas_rowlist, null);
TextView duatv = (TextView)vi.findViewById(R.id.textView1); // duatv
Typeface tf = Typeface.createFromAsset(convertView.getContext().getAssets(),"fonts/Molot.otf");
duatv.setTypeface(tf);
HashMap<String, String> song = new HashMap<String, String>();
song = data.get(position);
// Setting all values in listview
// String eventName1=song.get(First.Duas).toString();
duatv.setTextSize(i);
duatv.setText(song.get(First.Duas));
return vi;
}
}