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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T03:48:29+00:00 2026-06-13T03:48:29+00:00

I am new to the android api and I have some problems with ..

  • 0

I am new to the android api and I have some problems with .. the basics.
I’m trying to get a list working, but the list displays the wrong text:

Each row has two TextViews (title, subtitle), heres the xml:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:padding="5dip" >

    <TextView
        android:id="@+id/row_title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="TITLE"
        android:textSize="15dip"
        android:layout_gravity="center_vertical" />

    <TextView
        android:id="@+id/row_subtitle"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/row_title"
        android:text="SUBTITLE"
        android:textSize="10dip"
        android:layout_gravity="center_vertical" />

</RelativeLayout>

I extend ListFragment (I need this fragment thing, because of a slidingMenu library), have a custom adapter and an item class.
in the onActivityCreated() method I add some random items to the adapter:

package com.slidingmenu.example;

import android.app.Fragment;
import android.app.ListFragment;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;


public class SampleListFragment extends ListFragment {

    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        return inflater.inflate(R.layout.list, null);
    }

    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);

        SampleAdapter adapter = new SampleAdapter(getActivity());
        for (int i = 0; i < 20; i++) {
            adapter.add(new SampleItem(new Fragment(), "title no. " + i, "some subtitle"));
        }
        setListAdapter(adapter);
    }

    private class SampleItem {
        public Fragment frag;
        public String title;
        public String subTitle;
        public SampleItem(Fragment frag, String title, String subTitle) {
            this.frag = frag; 
            this.title = title; 
            this.subTitle = subTitle;
        }
    }

    public class SampleAdapter extends ArrayAdapter<SampleItem> {

        public SampleAdapter(Context context) {
            super(context, 0);
        }

        public View getView(int position, View convertView, ViewGroup parent) {
            if (convertView == null) {
                convertView = LayoutInflater.from(getContext()).inflate(R.layout.row, null);
            }
            TextView title = (TextView) convertView.findViewById(R.id.row_title);
            TextView subTitle = (TextView) convertView.findViewById(R.id.row_subtitle);

            return convertView;
        }

    }
}

So I thougt that the list would display something like this:

title no. 0
some subtitle
-
title no. 1
some subtitle
-
title no. 2
some subtitle
-

etc.

but instead it just displays what I defined in the row.xml:

TITLE
SUBTITLE
-
TITLE
SUBTITLE
-

etc.

I think getView() needs to be changed (at least it doesn’t make to much sense to me) but I’m not sure.
Everything I try results in some nullpointer exception or worse.

Please, can someone tell me what I need to change?

  • 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-13T03:48:30+00:00Added an answer on June 13, 2026 at 3:48 am

    The error is int the Adapter:

      public View getView(int position, View convertView, ViewGroup parent) {
                if (convertView == null) {
                    convertView = LayoutInflater.from(getContext()).inflate(R.layout.row, null);
                }
                TextView title = (TextView) convertView.findViewById(R.id.row_title);
                TextView subTitle = (TextView) convertView.findViewById(R.id.row_subtitle);
    
                return convertView;
            }
    

    the getView never fills up the title and subtitle. Second you never submit to the superclass the dataset you want to show in the ListFragment.

    Here you have to ways. Or you ovveride the getCount and getItem and getItemId methods, or feed up the superclass with the dataset, using this constructor. Read carefully the documentation.

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

Sidebar

Related Questions

I'm new to Android development and have some question regarding overlays in googlemaps API.
I'm new to Android development and have some question regarding overlays in googlemaps API.
I have some questions about android ui api. Give a example, that I want
I'm new to android. I have some java knowledge (not extensive), and I've done
i am new to android programming and i want to create an api with
I am new in android and i want to do parsing through api and
How to access google calendar with new api on android ? Using GData APIs
i am creating a new android application.i am using the table layout. I have
I am searching for some way of using any Google API or android framework
I have an BroadcastReceiver for handling new or modified applications: <receiver android:name=.PackageHandler > <intent-filter>

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.