问题
I am new in android. this is my first project.I am trying to make a Name dictionary in bangla so i need to change the list view font. I already added the font into the asset folder..
private void showResults(String query) {
Cursor cursor = managedQuery(DictionaryProvider.CONTENT_URI, null, null,
new String[] {query}, null);
if (cursor == null) {
// There are no results
mTextView.setText(getString(R.string.no_results, new Object[] {query}));
} else {
// Display the number of results
int count = cursor.getCount();
String countString = getResources().getQuantityString(R.plurals.search_results,count, new Object[] {count, query});
mTextView.setText(countString);
// Specify the columns we want to display in the result
String[] from = new String[] { DictionaryDatabase.KEY_WORD,
DictionaryDatabase.KEY_DEFINITION };
// Specify the corresponding layout elements where we want the columns to go
int[] to = new int[] { R.id.word,
R.id.definition };
// Create a simple cursor adapter for the definitions and apply them to the ListView
SimpleCursorAdapter words = new SimpleCursorAdapter(this, R.layout.result, cursor, from, to);
mListView.getAdapter();
// Define the on-click listener for the list items
mListView.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
// Build the Intent used to open WordActivity with a specific word Uri
Intent wordIntent = new Intent(getApplicationContext(), WordActivity.class);
Uri data = Uri.withAppendedPath(DictionaryProvider.CONTENT_URI,
String.valueOf(id));
wordIntent.setData(data);
startActivity(wordIntent);
}
});
}
}
回答1:
public class myAdapter extends CursorAdapter {
public myAdapter(Context context, Cursor c) {
super(context, c);
}
@Override
public void bindView(View view, Context context, Cursor cursor) {
Typeface tf = Typeface.createFromAsset(context.getAssets(), "font/Rupali.ttf");
TextView tv = (TextView)view.findViewById(R.id.definition);
String s = cursor.getString(cursor.getColumnIndex(DictionaryDatabase.KEY_DEFINITION));
tv.setText(s);
tv.setTypeface(tf);
//Any other modifications you want
}
@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
LayoutInflater infl = LayoutInflater.from(context);
View v = infl.inflate(R.layout.result, parent, false);
bindView(v, context, cursor);
return v;
}
}
来源:https://stackoverflow.com/questions/13713513/how-to-use-custom-font-in-simplecursoradapter-for-a-list-view-at-searchable-dict