Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8741077
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T11:14:39+00:00 2026-06-13T11:14:39+00:00

I have some data in an xml file put it in /res/values/mydata.xml. I want

  • 0

I have some data in an xml file put it in /res/values/mydata.xml. I want to show data in a listview with a custom font. Everything is great in emulator but in real device (using samsung galaxy tab 10.1 2 with android 4.0.3) is too slow when scroll listview. Actually it works great with default font but the problem appears when set the custom font.

This is my java code:

public class ShowFoodCalorie extends ListActivity {
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // reading data from xml file
    setListAdapter(new MyAdapter(this, android.R.layout.simple_list_item_1,
            R.id.textView1,  getResources().getStringArray(R.array.food_cal)));
}
private class MyAdapter extends ArrayAdapter<String> {
    public MyAdapter(Context context, int resource, int textViewResourceId,
            String[] string) {
        super(context, resource, textViewResourceId, string);
    }

    public View getView(int position, View convertView, ViewGroup parent) {
        LayoutInflater inflater = (LayoutInflater)
getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View row = inflater.inflate(R.layout.show_all, parent, false);
        String[] item = getResources().getStringArray(R.array.food_cal);
        TextView tv = (TextView) row.findViewById(R.id.textView1);
        try {
            Typeface font = Typeface.createFromAsset(getAssets(),"myFont.ttf");
            tv.setTypeface(font);
        } catch (Exception e) {
            Log.d("Alireza", e.getMessage().toString());
        }

        tv.setText(item[position]);
        return row;
    }
}

what is this problem? it’s about my device? Any solution can help me.
Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T11:14:40+00:00Added an answer on June 13, 2026 at 11:14 am

    Your problem is that line:

    Typeface font = Typeface.createFromAsset(getAssets(),"myFont.ttf");
    

    You should do that once in the constructor of your Adapter, make font a member variable and than just use the variable to call setTypeface(font) on your TextView.

    Heavy loading in the getView() method should be prevented.

    Also read about the convertView / ViewHolder pattern for adapter, that would give you a performance boost, too.

    Update with example:

    private class MyAdapter extends ArrayAdapter<String> {
        Typeface font;
    
        public MyAdapter(Context context, int resource, int textViewResourceId,
                String[] string) {
            super(context, resource, textViewResourceId, string);
            font = Typeface.createFromAsset(context.getAssets(),"myFont.ttf");
        }
    
        public View getView(int position, View convertView, ViewGroup parent) {
            LayoutInflater inflater = (LayoutInflater)
    getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            View row = inflater.inflate(R.layout.show_all, parent, false);
            String[] item = getResources().getStringArray(R.array.food_cal);
            TextView tv = (TextView) row.findViewById(R.id.textView1);
            try {
                tv.setTypeface(font);
            } catch (Exception e) {
                Log.d("Alireza", e.getMessage().toString());
            }
    
            tv.setText(item[position]);
            return row;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have one problem , I want to get some data from XML file
I have some data that I export into an XML file and put in
I have some data stored as an XML file. I put it into a
I have an 'xml file' file that has some unwanted characters in it <data>
I have some xml data contained in three files (Database.xml, Participants.xml, and ConditionTokens.xml). I
I have some data in an XML element that looks like this: <?xml version=1.0
I have grabbed some XML data using this piece of jQuery: $.ajax({ type: POST,
I have some data in an SQL table with an XML datatype column where
I have some data in a database that I need represented in an XML
I have to import some XML data into my app. Now I open a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.