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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T03:46:22+00:00 2026-06-05T03:46:22+00:00

I have a listview populated like this: lv1 = (ListView) findViewById(R.id.ListView01); ArrayList<HashMap<String, String>> mylist

  • 0

I have a listview populated like this:

lv1 = (ListView) findViewById(R.id.ListView01);

ArrayList<HashMap<String, String>> mylist = new ArrayList<HashMap<String, String>>();
HashMap<String, String> map = new HashMap<String, String>();
map.put("product", "Bread");
map.put("quantity", "1");
map.put("unit", "pcs");
mylist.add(map);

map = new HashMap<String, String>();
map.put("product", "Books for mom");
map.put("quantity", "14");
map.put("unit", "pcs");
mylist.add(map);

map = new HashMap<String, String>();
map.put("product", "Mineral water");
map.put("quantity", "2");
map.put("unit", "l");
mylist.add(map);

SimpleAdapter mSchedule = new SimpleAdapter(this, mylist, R.layout.grlists,
    new String[] {"product", "quantity", "unit"}, new int[] {R.id.CPRODUCT, R.id.CQUANTITY, R.id.CUNIT});
lv1.setAdapter(mSchedule);

This is the layout of the listview (grlists.xml):

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
     xmlns:android="http://schemas.android.com/apk/res/android"
     android:paddingTop="4dip"
     android:paddingBottom="6dip"
     android:layout_width="fill_parent"
     android:layout_height="wrap_content"
     android:orientation="horizontal">
    <CheckBox android:id="@+id/checkbox"
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" />
     <TextView android:id="@+id/CPRODUCT"
         android:layout_width="200dip"
         android:layout_height="wrap_content"
         android:textColor="#000000"
         android:paddingLeft="5dip"
         android:background="#EBDDE2"/>

     <TextView android:id="@+id/CQUANTITY"
         android:layout_width="30dip"
         android:layout_height="wrap_content" android:layout_weight="1"
          android:textColor="#000000"
          android:background="#B4CFEC"/>

     <TextView android:id="@+id/CUNIT"
         android:layout_width="30dip"
         android:layout_height="wrap_content"  android:layout_weight="1"
          android:textColor="#000000"
          android:background="#A5A1A0"/>
</LinearLayout>

This gives me nullpointerexception because it looks for the CPRODUCT textview in the main layout.

Typeface tf = Typeface.createFromAsset(getAssets(), "fonts/PopStarAutograph.ttf");
TextView tv1 = (TextView) findViewById(R.id.CPRODUCT);
tv1.setTypeface(tf);

How can i change the font type of the textviews programmatically?

  • 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-05T03:46:25+00:00Added an answer on June 5, 2026 at 3:46 am

    As Dmytro Danylyk did not add his solution as an answer I add it to close this question. However, in the past months I have mastered this area, so I add a bit different answer as he posted.

    First of all, we need arrays to show in a listview. This listview is built upon a custom adapter that receives the items from the arrays. In this custom adapter we can do whatever want with the items in each row of a listview, no matter what kind of elements we are talking about. Be it a textview, imageview, or a checkbox, etc.

    Let’s imagine we have 5 elements in a list row: 5 textviews. After populating the 5 arrays, we define our adapter as:

    adapter = new ListViewCustomAdapter(Calllogs.this, arr_calllog_name, arr_calllog_phone, arr_calllog_type,arr_calllog_duration, arr_calllog_date);
    

    And this is how we set our adapter to the listview:

    lv1.setAdapter(adapter);
    

    And finally, we need to create our ListViewCustomAdapter (name it as you want):

    public class ListViewCustomAdapter extends BaseAdapter
    {
        public String title[];
        public String description[];
        ArrayList<String> arr_calllog_name = new ArrayList<String>();
        ArrayList<String> arr_calllog_phone = new ArrayList<String>();
        ArrayList<String> arr_calllog_type = new ArrayList<String>();
        ArrayList<String> arr_calllog_date = new ArrayList<String>();
        ArrayList<String> arr_calllog_duration = new ArrayList<String>();
    
        public Activity context;
        public LayoutInflater inflater;
    
        public ListViewCustomAdapter(Activity context,  ArrayList<String> arr_calllog_name, ArrayList<String> arr_calllog_phone, ArrayList<String> arr_calllog_type, ArrayList<String> arr_calllog_duration, ArrayList<String> arr_calllog_date) {
            super();
    
            this.context = context;
            this.arr_calllog_type = arr_calllog_type;
            this.arr_calllog_name = arr_calllog_name;
            this.arr_calllog_phone = arr_calllog_phone;
            this.arr_calllog_date = arr_calllog_date;
            this.arr_calllog_duration = arr_calllog_duration;
    
    
            this.inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        }
    
        @Override
        public int getCount() {
            // TODO Auto-generated method stub
            return arr_calllog_name.size();
        }
    
        @Override
        public Object getItem(int position) {
            // TODO Auto-generated method stub
            return null;
        }
    
        @Override
        public long getItemId(int position) {
            // TODO Auto-generated method stub
            return 0;
        }
    
        public static class ViewHolder
        {
            TextView txtViewTitle;
            TextView txtViewDescription;
            TextView txtDate;
            TextView txtDuration;
        }
    
        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            // TODO Auto-generated method stub
    
            ViewHolder holder;
            if(convertView==null)
            {
                holder = new ViewHolder();
                convertView = inflater.inflate(R.layout.calllog_row, null);
    
                holder.txtViewTitle = (TextView) convertView.findViewById(R.id.calllogquery_name);
                holder.txtViewDescription = (TextView) convertView.findViewById(R.id.calllogquery_phone);
                holder.txtDate = (TextView) convertView.findViewById(R.id.calllogquery_date);
                holder.txtDuration = (TextView) convertView.findViewById(R.id.calllogquery_duration);
    
                convertView.setTag(holder);
            }
            else
                holder=(ViewHolder)convertView.getTag();
    
            int teljes = Integer.parseInt(arr_calllog_duration.get(position));
            int h = teljes / 3600;
            int mar_h = teljes - h * 3600;
            int m = mar_h / 60;
            int s = mar_h - m * 60;
            String hh, mm, ss;
            if (h < 10)                 {                   hh = "0" + Integer.toString(h);             }
            else                {                   hh = Integer.toString(h);               }
            if (m < 10)                 {                   mm = "0" + Integer.toString(m);             }
            else                {                   mm = Integer.toString(m);               }
            if (s < 10)             {                   ss = "0" + Integer.toString(s);             }
            else                {                   ss = Integer.toString(s);               }
    
            String dur_edited = hh + ":" + mm + ":" + ss;
    
    
            holder.txtViewTitle.setText(arr_calllog_name.get(position));
            holder.txtViewDescription.setText(arr_calllog_phone.get(position));
            holder.txtDate.setText(arr_calllog_date.get(position));
            holder.txtDuration.setText(dur_edited);
    
            return convertView;
        }
    
    }
    

    As you see this adapter has 5 parameters, just like our 5 arrays. That’s all.
    Oh, and we also need to define our adapter as ListViewCustomAdapter adapter; first.

    You can have this adapter class in a separate class or in your activity, outside the onCreate() method.

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

Sidebar

Related Questions

I have 3 ListView's that are populated like this (well this can be anything,
I have a listView, populated with an ArrayList of object (xml parsing) and an
I am using an ListAdapter to populate a ListView like this: static final String[]
I have a DataTemplate with a Combobox inside a ListView like this <GridViewColumn.CellTemplate> <DataTemplate>
I have a simple 3-column ListView. This control is programatically populated with data from
I have a ListView that is being populated with a custom adapter. I'd like
I have a ListView which is populated from a string-array resource. I'm trying to
I have a ListView which is populated using a CursorAdapter. I'd also like to
I have a ListView that is populated using an XML file. However, I want
I am currently implementing a ListView populated with CheckedTextViews and have everything working just

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.