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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:02:21+00:00 2026-06-16T00:02:21+00:00

I am trying to Create a Array Adapter to set content from an Array

  • 0

I am trying to Create a Array Adapter to set content from an Array of text to the adapter but i am not able to set the adapter from the Activity. Am not sure what i should pass for the resource as Int

PlacesListAdapter.java

public class PlacesListAdapter extends ArrayAdapter<Place> {
    public Context context;
    private List<Place> places;

    public PlacesListAdapter(Context context, int textViewResourceId) {
        super(context, textViewResourceId);
    }

    public PlacesListAdapter(Context context, int resource, List<Place> places) {
        super(context, resource, places);
        this.context = context;
        this.places = places;
        // imageLoader = new ImageLoader(context.getApplicationContext());

    }

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

        ViewHolder holder;
        View view = convertView;
        Place p = places.get(position);

        if (convertView == null) {
            LayoutInflater viewInflater;
            viewInflater = LayoutInflater.from(getContext());
            view = viewInflater.inflate(R.layout.item_place, null);

            holder = new ViewHolder();
            holder.placeTitle = (TextView) view.findViewById(R.id.place_title);
            holder.placeDistance = (TextView) view
                    .findViewById(R.id.place_distance);

            view.setTag(holder);

        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        holder.placeTitle.setText(p.getPlaceTitle());
        holder.placeDistance.setText("200");
        holder.placeCategoryIcon.setImageResource(R.drawable.marker);

        return view;
    }

    static class ViewHolder {
        TextView placeId;
        TextView placeTitle;
        TextView placeDistance;
        ImageView placeCategoryIcon;
    }

}

Place.java

public class Place {

    String placeId = "", placeTitle = "", placeDistance = "",
            placeCategoryIcon = "";

    public Place(String placeId, String placeTitle, String placeDistance,
            String placeCategoryIcon) {
        this.placeId = placeId;
        this.placeTitle = placeTitle;
        this.placeDistance = placeDistance;
        this.placeCategoryIcon = placeCategoryIcon;
    }

    public String getPlaceId() {
        return placeId;
    }

    public void setPlaceId(String placeId) {
        this.placeId = placeId;
    }

    public String getPlaceTitle() {
        return placeTitle;
    }

    public void setPlaceTitle(String placeTitle) {
        this.placeTitle = placeTitle;
    }

    public String getPlaceDistance() {
        return placeDistance;
    }

    public void setPlaceDistance(String placeDistance) {
        this.placeDistance = placeDistance;
    }

    public String getPlaceCategoryIcon() {
        return placeCategoryIcon;
    }

    public void setPlaceCategoryIcon(String placeCategoryIcon) {
        this.placeCategoryIcon = placeCategoryIcon;
    }

}

Now in MainActiivty i am trying to set the adapter so that it populates the list from the Array

public class MainActivity extends SherlockFragmentActivity implements
        SearchView.OnQueryTextListener {

    private final String[] places = new String[] { "Mysore", "Bangalore", "Mangalore",
            "Wayanad", "Bandipur National Park", "Chickmaglur",
            "Bandipura", "Coorg", "Kodaikanal", "Hampi",
            "Ghati Subramanya", "Mekedatu", "Muththathhi", "Shivasamudram",
            "Talakadu", "Savana Durga" };

    public SearchView mSearchView;
    private TextView mStatusView;

    private Menu mainMenu = null;

    PlacesListAdapter adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        Log.i("Nomad", "onCreate");

        ListView listView = (ListView) findViewById(R.id.place_list);


        adapter = new PlacesListAdapter(this, resource, places);

    }
}

I am not sure what to set for resources in adapter = new PlacesListAdapter(this, resource, places);

  • 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-16T00:02:22+00:00Added an answer on June 16, 2026 at 12:02 am

    Initialize the resource variable:

    // it doesn't matter what values you assing to the resource variable because you build
    // the row layout yourself in the getView method of the adapter
    int resource = android.R.layout.simple_list_item_1;
    adapter = new PlacesListAdapter(this, resource, places);
    

    Edit:

    List<Place> thePlaces = new ArrayList<Place>();
    for (int i = 0; i < places.length; i++) {
         Place pl = new Place("NO_ID", places[i], "NO_DISTANCE", "NO_CATEGORYICON");
         thePlaces.add(pl);
    }
    int resource = android.R.layout.simple_list_item_1;
    adapter = new PlacesListAdapter(this, resource, thePlaces);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to create a simple Icon+Text ListView but it does not work.
I'm trying to create an array from selected table rows so I can push
Im trying to create an array of tm* structs, and then return them at
I am trying to create an array of product SKU's which I can then
I am trying to create an array of class objects taking an integer argument.
I'm trying to create an array to display the last 5 products a customer
I am trying to create an array or list that could handle in theory,
I'm trying to create an array of strings that can be randomized and limited
I'm trying to create an array (States) of arrays (Cities). Whenever I try to
I'm trying to create an array in MIPS Assembly, and then add all 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.