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 5992399
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T23:31:33+00:00 2026-05-22T23:31:33+00:00

I have a listview in which i wanted to have custom typeface e.g. Arial.

  • 0

I have a listview in which i wanted to have custom typeface e.g. Arial. for this i subclassed the SimpleAdapter and implemented the the typeface for textviews in the list. But after this implementation, the list appears to be blank but the onClick is still working and clicking on the blank list item navigates me to the next activity as required.

Code

public class TopNewsActivity extends ListActivity {

public static final String LOG_TAG = "Infra";
private ProgressDialog progressDialog;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.listplaceholder);
    new BackgroundAsyncTask().execute();
}

public class BackgroundAsyncTask extends AsyncTask<String, Integer, ArrayList<HashMap<String, String>>> {

    @Override
    protected void onPreExecute() {
        progressDialog = new ProgressDialog(TopNewsGroup.group);
        progressDialog.setCancelable(true);
        progressDialog.setMessage("Loading...");
        progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
        progressDialog.setProgress(0);
        progressDialog.show();
    }

    @Override
    protected ArrayList<HashMap<String, String>> doInBackground(String... paths) {

        ArrayList<HashMap<String, String>> mylist = new ArrayList<HashMap<String, String>>();

        String xml = XMLfunctions.getTopNewsXML();
        Document doc = XMLfunctions.XMLfromString(xml);

        int numResults = XMLfunctions.numResults(doc);
        Log.d(LOG_TAG, "Number of Results: " + numResults);
        if ((numResults <= 0)) {
            Toast.makeText(TopNewsActivity.this, "No Result Found",Toast.LENGTH_LONG).show();
            return null;
        }

        NodeList nodes = doc.getElementsByTagName("result");

        for (int i = 0; i < nodes.getLength(); i++) {
            HashMap<String, String> map = new HashMap<String, String>();

            Element e = (Element) nodes.item(i);
            map.put("id", XMLfunctions.getValue(e, "id"));
            map.put("title", XMLfunctions.getValue(e, "title"));
            map.put("date", XMLfunctions.getValue(e, "date"));
            map.put("recordDate", XMLfunctions.getValue(e, "recordDate"));
            mylist.add(map);
        }
        return mylist;
    }

    @Override
    protected void onProgressUpdate(Integer... values) {
        super.onProgressUpdate(values);
    }

    protected void onPostExecute(ArrayList<HashMap<String, String>> result) {



        ListAdapter adapter = new MySimpleAdapter(TopNewsActivity.this, result, R.layout.list_item, new String[] { "title", "date" }, new int[] { R.id.item_title, R.id.item_subtitle });
        setListAdapter(adapter);
        progressDialog.dismiss();

        final ListView lv = getListView();

        lv.setTextFilterEnabled(true);  
        lv.setOnItemClickListener(new OnItemClickListener() {
            @SuppressWarnings("unchecked")
            @Override
            public void onItemClick(AdapterView<?> a, View view, final int position, long id) {

                HashMap<String, String> o = (HashMap<String, String>) lv.getItemAtPosition(position);

                Intent i = new Intent(TopNewsActivity.this, NewsDetails.class);
                i.putExtra("content_id", o.get("id"));
                i.putExtra("title", o.get("title"));
                i.putExtra("date", o.get("recordDate"));
                i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

                View v = TopNewsGroup.group.getLocalActivityManager().startActivity("ShowNews", i).getDecorView();

                // Again, replace the view
                TopNewsGroup.group.replaceView(v);
            }
        });
    }
}

public class MySimpleAdapter extends SimpleAdapter {
    public MySimpleAdapter(Context context, List<? extends Map<String, ?>> data, int resource, String[] from, int[] to) {
        super(context, data, resource, from, to);
    }

    public View getView(int position, View view, ViewGroup parent){

        Typeface localTypeface1 = Typeface.createFromAsset(getAssets(), "fonts/arial.ttf");
        View v = view;
        if (v == null) {
            LayoutInflater vi = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            v = vi.inflate(R.layout.list_item, null);
        }
        TextView tt = (TextView) v.findViewById(R.id.item_title);
        tt.setBackgroundColor(R.color.white);
        tt.setTypeface(localTypeface1);
        tt.setTextColor(android.R.color.black);
        TextView bt = (TextView) v.findViewById(R.id.item_subtitle);
        bt.setBackgroundColor(R.color.white);
        bt.setTypeface(localTypeface1);
        bt.setTextColor(R.color.grey);
        return v;
        /*Typeface localTypeface1 = Typeface.createFromAsset(getAssets(), "fonts/arial.ttf");
        View v = super.getView(position, view, parent);
        ((TextView) v).setTypeface(localTypeface1);
        return v;*/
    }
}

 }
  • 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-05-22T23:31:34+00:00Added an answer on May 22, 2026 at 11:31 pm

    the answer is quite simple as it was my mistake, wasn’t providing the ItemText to be viewed to the getView method:

    public class MySimpleAdapter extends SimpleAdapter {
    
        private ArrayList<HashMap<String, String>> results;
    
        public MySimpleAdapter(Context context, ArrayList<HashMap<String, String>> data, int resource, String[] from, int[] to) {
            super(context, data, resource, from, to);
            this.results = data;
        }
    
        public View getView(int position, View view, ViewGroup parent){
    
            Typeface localTypeface1 = Typeface.createFromAsset(getAssets(), "fonts/arial.ttf");
            View v = view;
            if (v == null) {
                LayoutInflater vi = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                v = vi.inflate(R.layout.list_item, null);
            }
            TextView tt = (TextView) v.findViewById(R.id.item_title);
            tt.setText(results.get(position).get("title"));
            tt.setTypeface(localTypeface1);
            TextView bt = (TextView) v.findViewById(R.id.item_subtitle);
            bt.setText(results.get(position).get("date"));
            bt.setTypeface(localTypeface1);
            return v;
        }
    }
    

    🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have ListView which shows images from an ImageList. Now wanted to get index
I have a ListView which sometimes I need to put around 10000 items in.
I have a WPF ListView which repeats the data vertically. I cannot figure out
I have an app with a large ListView which is terribly slow so I'm
I currently have a list view which has several rows of data and I
I have a list view control which at the moment only allows one item
I have a ListView on a page that displays a list of widgets. When
I have a ListView inside of an Update Panel and wanted to change the
I have a listview which I have binded (twoWay) to a datatable. The binding
ASP.NET application, VB or C# doesn't matter. I have Listview which databound to Dataset

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.