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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T01:55:03+00:00 2026-05-27T01:55:03+00:00

I have a ListView with a Custom Adapter, and I need to access the

  • 0

I have a ListView with a Custom Adapter, and I need to access the View of individual rows of this ListView. I am trying to do it using getChildAt(), but it is returning null.

Here’s my ListView:

myListView = (ListView) findViewById (R.id.listViewLayout);

This is the custom adapter:

    public class MyListAdapter extends BaseAdapter {
       ...
        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            if (convertView == null) {
                LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                convertView = inflater.inflate(R.layout.list_row_layout, parent, false);
            }
            ...
    }

I create a List, and set it for the ListView:

List <String> myList = new ArrayList<String>();
myList.add("entry 1");
myList.add("entry 2");
myList.add("entry 3");
MyListAdapter myListAdapter = new MyListAdapter(getApplicationContext(), myList);
myListView.setAdapter(myListAdapter);

Now, I want to access the View for individual rows.

View v = myListView.getChildAt(myListView.getFirstVisiblePosition());

This v is null, no matter what. Additionally, myListView.getChildCount() always returns null.

What am I missing? Do I need to add the convertView to parent in getView()? Am I passing wrong parameters to inflate?

I have struggled a lot to figure this out. Please help me!

EDIT: I am posting the MyListAdapter class:

public class MyListAdapter extends BaseAdapter {

    private Context context;
    private List<String> myList;

    public MyListAdapter(Context c, List<String> m) {
        context = c;
        myList = m;
    }

    @Override
    public int getCount() {
        return myList.size();
    }

    @Override
    public Object getItem(int position) {
        return myList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        final int pos = position;

        if (convertView == null) {
            LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            convertView = inflater.inflate(R.layout.list_row_layout, parent, false);
        }

            TextView text = (TextView) convertView.findViewById(R.id.itemText);
            text.setText(myList.get(pos));

            // Set the onClick Listener on this button
            Button rowButton = (Button) convertView.findViewById(R.id.itemButton);

            //commenting next two lines makes the list row clickable
            rowButton.setFocusableInTouchMode(false);
            rowButton.setFocusable(false);

            rowButton.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    Toast.makeText(context, myList.get(pos), Toast.LENGTH_SHORT).show();
                } 
            });  
            convertView.setTag(pos);
            return convertView;
    }
}
  • 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-27T01:55:03+00:00Added an answer on May 27, 2026 at 1:55 am

    In all probability you’re doing all of this in onCreate(). Any view-related methods will return null (or empty) because the list has not been rendered yet. What do you need the child view for?

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

Sidebar

Related Questions

I have created a custom listview using adapter. Each row of the list view
I have ListView with custom Adapter which supplies View to ListView in this way:
I have a Listview with custom cursor adapter. I'm trying to prevent input in
I have a listview with custom array adapter, the view allows the user to
I need to make a custom ListView with multiple view types. I found this
I have a ListView view I need to populate using data I am fetching
I have a custom ListView Adapter , with which I'm creating rows for a
Summary: Trying to dynamically add heading rows to a ListView via a custom adapter
I have a ListView which uses a custom adapter to display rows of data.
I have a button that should sort a ListView using a custom adapter. The

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.