1

私はアンドロイドが初めてです。これは私の最初のプロジェクトです。バングラで名前辞書を作成しようとしているので、リスト ビューのフォントを変更する必要があります。私はすでにアセットフォルダにフォントを追加しました..

    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);
            }
        });
    }     
}

4

1 に答える 1

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;
}

}

于 2012-12-09T18:57:34.590 に答える