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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T13:07:01+00:00 2026-06-14T13:07:01+00:00

I want to use a base adapter for a listview but my data is

  • 0

I want to use a base adapter for a listview but my data is in a String[]
is this not allowed? cant seem to get the items to inflate in the views… my XML layouts are built correctly. The java below for the activity in question is posted below. Im not getting any exceptions, just the list isn’t being displayed.

public class SuggestedRest extends Activity{
    MediaPlayer clickSound;
    Context context;
    private String[] restaurantSuggestions = {
            "Applebees",
            "Arby's",
            "Baskin Robbins",
            "Ben & Jerry's",
            "Bojangles'",
            "Bonefish Grill",
            "Buffalo Wild Wings",
            "Burger King",
            "Captain D's",
            "Carl's Jr.",
            "Carrabba's",
            "Checkers",
            "Cheeburger Cheeburger",
            "Cheesecake Factory",
            "Chick-Fil-A",
            "Chili's",
            "Church's",
            "Cold Stone Creamery",
            "Cracker Barrel",
            "Dairy Queen",
            "Dave & Buster's",
            "Denny's",
            "Domino's Pizza",
            "Dunkin' Donuts",
            "Five Guys",
            "Hardee's",
            "Hooters",
            "Huddle House",
            "IHOP",
            "Jack in the Box",
            "Jack's",
            "Jason's Deli",
            "Jersey Mike's Subs",
            "Jimmy John's",
            "KFC",
            "Krystal",
            "Little Caesars",
            "Logan's Roadhouse",
            "Lone Star",
            "Long John Silver's",
            "LongHorn Steakhouse",
            "Macaroni Grill",
            "McAlister's Deli",
            "McDonald's",
            "Moe's Southwest Grill",
            "Olive Garden",
            "Outback",
            "P. F. Chang's China Bistro",
            "Panda Express",
            "Panera Bread",
            "Papa John's",
            "Pizza Hut",
            "Popeyes Chicken & Biscuits",
            "Quiznos",
            "Rally's",
            "Red Lobster",
            "Red Robin",
            "Ruby Tuesday",
            "Ruth's Chris Steak House",
            "Sbarro",
            "Schlotzsky's",
            "Shoney's",
            "Smashburger",
            "Sonic",
            "Starbucks",
            "Steak 'n Shake",
            "Subway",
            "Taco Bell",
            "TGI Friday",
            "Waffle House",
            "Wendy's",
            "Whataburger",
            "White Castle",
            "Zaxby's"};


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.suggested_rest_layout);
        context = getApplicationContext();
        final AdapterSuggestionsList asl = new AdapterSuggestionsList(context, restaurantSuggestions);
        final ListView lv = (ListView) findViewById(R.id.list_view_suggested);
        //lv.setAdapter(asl);

    }


    public class AdapterSuggestionsList extends BaseAdapter {

        private final Context context;
        private final String[] sugArray;

        public AdapterSuggestionsList(Context context, String[] sugArray) {
                    super();
                    this.context = context;
                    this.sugArray = sugArray;
                }

                @Override
                public View getView(int position, View convertView , ViewGroup parent){
                    LayoutInflater inflator = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                    final ViewHolder holder;

                    if (convertView == null){  // if null then inflate view. if not null then get the view from the stored ViewHolder class object  ("holder")
                        // 
                    convertView = inflator.inflate(R.layout.suggested_row, parent, false);
                    holder = new ViewHolder();
                    // holder is used as a recycle bin of sorts. once we inflate the view we store it as a holder object and just update the values since inflating is expensive
                        holder.tv1 = (TextView) convertView.findViewById(R.id.suggested_name);
                        holder.btnAdd= (Button) convertView.findViewById(R.id.btn_add_sugg_to_fav);

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

                    // this is the restaurant name
                    holder.name_value = sugArray[position];
                    holder.tv1.setText(holder.name_value);

                    holder.btnAdd.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            clickSound.start();
                            Intent intent  = new Intent(getApplicationContext(), AddMoreRestaurant.class);
                            intent.putExtra("TAG_THENAME", holder.name_value);  // this tag is opened by the AddMoreRestaurants activity when it is started by this intent
                            startActivity(intent);
                        }
                    });
                    return convertView;
                }

                @Override
                public int getCount() {
                    // TODO Auto-generated method stub
                    return sugArray.length;
                }
                @Override
                public Object getItem(int position) {
                    // TODO Auto-generated method stub
                    return position;
                }
                @Override
                public long getItemId(int position) {
                    // TODO Auto-generated method stub
                    return position;
                }
            }

        private static class ViewHolder {
            private TextView tv1;
            private Button btnAdd; // the button to add to the favorites
            private String name_value;  // set this to the name of the restaurant and pass it to the intent if needed
        }

}
  • 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-14T13:07:03+00:00Added an answer on June 14, 2026 at 1:07 pm

    Uncomment the line lv.setAdapter(asl);

    You need to set the adapter.

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

Sidebar

Related Questions

I want to use a custom template file which shoud use the base layout
I have a code base I want to use for both an ASP.NET MVC
I want use this 1 for using Bar code or QR code scanner. I
I want use BYTE_ORDER macro in my Xcode project but i can't because i
i want use some data from a website with web service. i have a
I want use JQuery mobile for the front-end of my mobile application, but I
I use BaseAdapter to show row of ListView. The activity and adapter are writen
I want use javascript setInterval function to achieve a box rotate animate effect, I
I want use a single php file to handle all of my voting requests.
I want use groovy findAll with my param to filtering closure filterClosure = {

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.