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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T19:13:18+00:00 2026-05-24T19:13:18+00:00

I’m trying to create an element within a ListView which displays a few TextViews

  • 0

I’m trying to create an element within a ListView which displays a few TextViews and a custom view in which I plan to draw to the canvas by overriding onDraw(). The method I’m attempting works fine with just the TextViews, but fails when I try and use the custom element (Graph), so the problem definitely lies here.

I have the following XML file which I use as the layout for each ListView item:

year_row.xml:

<?xml version="1.0" encoding="UTF-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/year_row_linear"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:padding="6dp"
    >
    <TextView android:id="@+id/year_name"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:textSize="20dip"
        android:textColor="@android:color/white"
        />
    <com.android.gradetracker.Graph android:id="@+id/year_graph"
        android:layout_width="fill_parent"
        android:layout_height="50dip"
        />
    <TextView android:id="@+id/year_average"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:textColor="@android:color/white"
        />
    <TextView android:id="@+id/year_progress"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        />    
</LinearLayout>

My Graph class is as follows:

Graph.java:

package com.android.gradetracker;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.util.AttributeSet;
import android.view.View;

public class Graph extends View {

    public Graph(Context context) {
        super(context);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        // to test if it works
        canvas.drawColor(Color.WHITE);
        super.onDraw(canvas);
    }
}

My main class which sets up the elements of the ListView then contains the following code:

    private ArrayList <HashMap<String,Object>> list = new ArrayList <HashMap<String,Object>>();
    private SimpleAdapter adapter;
    private ListView listView;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        listView = (ListView) findViewById(R.id.listview);
        listView.setClickable(true);

        String[] from = {"name", "graph", "average", "progress"};
        int[] to = new int[] {R.id.year_name, R.id.year_graph, R.id.year_average, R.id.year_progress};

        adapter = new SimpleAdapter(this.getApplicationContext(), list, R.layout.year_row, from, to);
        listView.setAdapter(adapter);
        listView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
    }

    public void addYear(String name) {
        Graph graph = new Graph(this);
        HashMap<String,Object> map = new HashMap<String,Object>();
        map.put("name", name);
        map.put("graph", graph);
        map.put("average", "--%");
        map.put("progress", "--/--%");
        list.add(map);
        adapter.notifyDataSetChanged();
    }

As I said, removing all references to the Graph class, the application works fine. I’m just having trouble getting Graph to display.

Logcat gives the error:

    08-04 17:09:50.415: ERROR/AndroidRuntime(397): android.view.InflateException: Binary XML file line #16: Error inflating class com.android.gradetracker.Graph

Thanks for any help in advance.

  • 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-24T19:13:19+00:00Added an answer on May 24, 2026 at 7:13 pm

    Okay, the main problem seemed to be that SimpleAdaptor does not allow you to use custom views. I had to create a custom adaptor which extends BaseAdapter in order to display the custom view, with the following code for the getView() method:

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
    if (convertView == null) {
        convertView = mInflater.inflate(R.layout.year_row, parent, false);
    }
    
    TextView name = (TextView) convertView.findViewById(R.id.year_name);
    Graph graph = (Graph) convertView.findViewById(R.id.year_graph);
    TextView average = (TextView) convertView.findViewById(R.id.year_average);
    TextView progress = (TextView) convertView.findViewById(R.id.year_progress);
    
        ArrayList<Object> row = list.get(position);
    
        name.setText(String.valueOf(row.get(0)));
        graph = (Graph)row.get(1);
        average.setText(String.valueOf(row.get(2)));
        progress.setText(String.valueOf(row.get(3)));
    
        return convertView;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
I am trying to understand how to use SyndicationItem to display feed which is
I'm trying to create an if statement in PHP that prevents a single post
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I used javascript for loading a picture on my website depending on which small
I am currently running into a problem where an element is coming back from
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have an MVC Razor view @{ ViewBag.Title = Index; var c = (char)146;

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.