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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:51:17+00:00 2026-05-27T22:51:17+00:00

I want to populate a list activity class with my custom object Person ,

  • 0

I want to populate a list activity class with my custom object Person, I wrote the following code

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

    liPerson = new ArrayList<Person>();
    person = new Person("Pritom Kumar Mondal", "Software Engineer", "bd");
    liPerson.add(person);
    person = new Person("Pritom Kumar Mondal", "Software Engineer", "bd");
    liPerson.add(person);
    person = new Person("Pritom Kumar Mondal", "Software Engineer", "bd");
    liPerson.add(person);
    person = new Person("Pritom Kumar Mondal", "Software Engineer", "bd");
    liPerson.add(person);
    Person[] persons = (Person[]) liPerson.toArray();
    setListAdapter(new MyAdapter(this, 
            android.R.layout.simple_list_item_1,
            persons));
}

private class MyAdapter extends ArrayAdapter<Person> {
    private Person[] persons;
    public MyAdapter(Context context, int resource, Person[] persons) {
        super(context, resource, persons);
        // TODO Auto-generated constructor stub
        this.persons = persons;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View row = inflater.inflate(R.layout.list_item, parent, false);
        //String[] items = getResources().getStringArray(R.array.countries);
        Person p = persons[position];
        ImageView iv = (ImageView) row.findViewById(R.id.imageView1);
        TextView tv = (TextView) row.findViewById(R.id.textView1);

        tv.setText(p.getName());

        String mDrawableName = "bd";
        int resID = getResources().getIdentifier(mDrawableName , "drawable", getPackageName());
        iv.setImageResource(resID);


        return row;
    }
}

It does not work. I can populate a list activity from my xml file, but I want this as my custom object.

  • 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-27T22:51:18+00:00Added an answer on May 27, 2026 at 10:51 pm

    Just pass the whole ArrayList to the ArrayAdapter. You can then get your object with getItem(position).”your method here”

    ArrayList<Person> personList = new ArrayList<Person>();
    
        ArrayAdapter<Person> adapter = new ArrayAdapter<Person>(this,
                R.layout.person_item, personList) {
            @Override
            public View getView(int position, View convertView, ViewGroup parent) {
                View row;
    
                if (null == convertView) {
                    row = mInflater.inflate(R.layout.person_item, null);
                } else {
                    row = convertView;
                }
    
                TextView tView = (TextView) row.findViewById(R.id.tvName);
                tView.setText(getItem(position).getName()); // This is where you get the name from your object
    
                return row;
            }
        };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have following code: public class ShowActivity extends ListActivity implements OnItemClickListener { /** Called
I have an activity that extends ListView. I populate my list with the results
I want to populate the weeks in a dropdown list when selecting month like
I have a class having a Boolean member and I want to populate a
I want to populate a List dynamically and display the list when i hover
I have an NSOutlineView that I want to populate with a list of NSURL
I want to use an AutoCompleteTextView in my activity and populate the data as
I'm experimenting with ASP.NET MVC3 and want to simply populate a dropdown list with
I have a full list that populates a UITableView . This I want to
I want to populate GridView below with images: <asp:GridView ID=GrdDynamic runat=server AutoGenerateColumns=False> <Columns> </Columns>

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.