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

The Archive Base Latest Questions

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

I am trying to build a custom adapter for my app, who’s main screen

  • 0

I am trying to build a custom adapter for my app, who’s main screen is a ListActivity with a ListView in the center. I am absolutely clueless as to how I’d create the adapter, so I was wondering if anyone knew of any good tutorials to walk me through it.

  • 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-18T11:02:13+00:00Added an answer on May 18, 2026 at 11:02 am

    Right now I am not having any reference to give you, but this is what you might be doing to get what you want:

    You might have the ListView in the XML, so instantiate a ListView object in your code:

    ListView myList = (ListView)findViewById(R.id.myListView)
    

    As soon as you get reference to it, create a custom class that extends BaseAdapter.

    A good idea will be to put this class inside your Activity class so that it can access all the data that your Activity holds.

    While extending BaseAdapter, there are some things that you need to do in order to get things working.

    I am explaining all of them below, but implementing the getView() method of the BaseAdapter is the most important thing.
    This method will be called by the runtime system everytime the ListView draws a row.

    So you should be doing all inside this method, that you would want to be done for a single row.

    Find the code below:

    Class myListActivity extends Activity{
    ... some code here...
    public void onCreate(Bundle savedInstanceState){
    .....
    myList.setAdapter(new myCustomAdapter());
    .....
    }
    
    /**
    *Custom Adapter class for the ListView containing data
    */
    class myCustomAdapter extends BaseAdapter{
    
    TextView userName;
    /**
     * returns the count of elements in the Array that is used to draw the text in rows 
       * @see android.widget.Adapter#getCount()
     */
    @Override
    public int getCount() {
        //return the length of the data array, so that the List View knows how much rows it has to draw   
    return DataArr.length;
    }
    
    /**
     * @param position The position of the row that was clicked (0-n)
     * @see android.widget.Adapter#getItem(int)
                         */
    @Override
    public String getItem(int position) {
        return null;
    }
    
    /**
     * @param position The position of the row that was clicked (0-n)
     * @see android.widget.Adapter#getItemId(int)
     */
    @Override
    public long getItemId(int position) {
        return position;
    }
    
    /**
     * Returns the complete row that the System draws.
     * It is called every time the System needs to draw a new row;
     * You can control the appearance of each row inside this function.
     * @param position The position of the row that was clicked (0-n)
     * @param convertView The View object of the row that was last created. null if its the first row
     * @param parent The ViewGroup object of the parent view
     * @see android.widget.Adapter#getView(int, android.view.View, android.view.ViewGroup)
     */
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View row = convertView;
        final int pos = position;
        if(row == null){
                        //getting custom layout to the row
            LayoutInflater inflater=getLayoutInflater();
            row=inflater.inflate(R.layout.list_row, parent, false);
        }
                //get the reference to the textview of your row. find the item with row.findViewById()
        userName= (TextView)row.findViewById(R.id.user_name);
        userName.setText(DataArr[position]);
    return row; //the row that ListView draws
    }
    }
    }
    

    Hope it helped you.

    Remember to create the layout of the row in a separate layout file.

    If you’re trying to get deeper, try this link at CommonsGuy’s website. It is an excerpt to his awesome book, that specifically deals with the ListView custom adapters

    EDIT: here’s my blog post about it and a sample project too: http://thetechnib.blogspot.com/2010/12/android-tutorial-custom-adapter-for.html

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

Sidebar

Related Questions

I'm trying to build a custom post to publish to one of my app
I'm trying to build a custom multivaluewidget in my django app. Widget class DayInputWidget(MultiWidget):
I am trying to build a help message output for my custom app like
I'm trying to build a custom clock view in Android. See image http://twitpic.com/1devk7 So
I'm trying to build a custom segue, but i can't seem to get the
I'm fairly new to Android, and am trying to build a custom component in
I'm trying to build my own custom django form widgets (putting them in widgets.py
I am trying to add some custom build steps to my headless build process
I'm trying to build a menu using a UItableView with Custom cells which have
Im trying to create a custom version of the RequiredAttribute to replace the built

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.