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

  • Home
  • SEARCH
  • 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 6230899
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T09:50:09+00:00 2026-05-24T09:50:09+00:00

So I am reading Commonsware’s Android Programming Tutorials and I am stuck with the

  • 0

So I am reading Commonsware’s Android Programming Tutorials and I am stuck with the part where the book asks me to add a ListView. Here is my layout’s xml

    <?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_height="fill_parent"
            android:layout_width="fill_parent">
    <RelativeLayout
            android:layout_height="fill_parent"
            android:layout_width="fill_parent">

        <TableLayout
                android:id="@+id/details"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentBottom="true"
                android:stretchColumns="1">
            <TableRow>
                <TextView android:text="Name:"/>
                <EditText android:id="@+id/name"/>
            </TableRow>

            <TableRow>
                <TextView android:text="Address:"/>
                <EditText android:id="@+id/address"/>
            </TableRow>
            <TableRow>
                <TextView android:text="Type: "/>
                <RadioGroup android:id="@+id/types">
                    <RadioButton android:layout_height="wrap_content" android:layout_width="fill_parent"
                                 android:id="@+id/take_out" android:text="Take-Out"/>
                    <RadioButton android:layout_height="wrap_content" android:layout_width="fill_parent"
                                 android:id="@+id/sit_down" android:text="Sit-Down"/>
                    <RadioButton android:layout_height="wrap_content" android:layout_width="fill_parent"
                                 android:id="@+id/delivery" android:text="Delivery"/>
                </RadioGroup>
            </TableRow>

            <Button android:id="@+id/save"
                    android:text="Save"
                    android:layout_height="wrap_content"
                    android:layout_width="fill_parent"/>
        </TableLayout>
        <ListView android:id="@+id/restaurants"
                  android:layout_width="fill_parent"
                  android:layout_height="fill_parent"
                  android:layout_alignParentTop="true"
                  android:layout_above="@id/details"
                />

    </RelativeLayout>
</ScrollView>

and this is my activity code

package com.example;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.*;

import java.util.LinkedList;
import java.util.List;

public class LunchList extends Activity {

    List<Restaurant> model = new LinkedList<Restaurant>();
    ArrayAdapter<Restaurant> arrayAdapter = null;

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

        Button save = (Button) findViewById(R.id.save);

        save.setOnClickListener(onSave);

        ListView listView = (ListView) findViewById(R.id.restaurants);
        arrayAdapter = new ArrayAdapter<Restaurant>(this, android.R.layout.simple_list_item_1, model);
        listView.setAdapter(arrayAdapter);

    }


    private View.OnClickListener onSave = new View.OnClickListener(){

        public void onClick(View view) {
            EditText nameField = (EditText) findViewById(R.id.name);
            EditText addressField = (EditText) findViewById(R.id.address);

            Restaurant restaurant = new Restaurant();
            restaurant.setName(nameField.getText().toString());
            restaurant.setAddress(addressField.getText().toString());


            RadioGroup radioGroup = (RadioGroup) findViewById(R.id.types);

            switch (radioGroup.getCheckedRadioButtonId()) {

                case (R.id.take_out):
                    restaurant.setType("take_out");
                    break;

                case (R.id.sit_down):
                    restaurant.setType("sit_down");
                    break;

                case (R.id.delivery):
                    restaurant.setType("delivery");
                    break;

                case (R.id.korean):
                    restaurant.setType("korean");
                    break;

                case (R.id.chinese):
                    restaurant.setType("chinese");
                    break;

                case (R.id.japanese):
                    restaurant.setType("japanese");
                    break;

                case (R.id.italian):
                    restaurant.setType("italian");
                    break;

                case (R.id.indonesian):
                    restaurant.setType("indonesian");
                    break;

            }

            arrayAdapter.add(restaurant);
            Log.i("LunchList", "Array Adapter Size: " + arrayAdapter.getCount());
        }
    };
}

I added a logging line to see whether the object is being added to the adapter or not and it looks like it is being added in there. The UI however is not showing the ListView and I do not see stuff getting added in the list.

Edit XML:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_height="fill_parent"
            android:layout_width="fill_parent">
    <RelativeLayout
            android:layout_height="wrap_content"
            android:layout_width="fill_parent">

        <TableLayout
                android:id="@+id/details"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentBottom="true"
                android:stretchColumns="1">
            <TableRow>
                <TextView android:text="Name:"/>
                <EditText android:id="@+id/name"/>
            </TableRow>

            <TableRow>
                <TextView android:text="Address:"/>
                <EditText android:id="@+id/address"/>
            </TableRow>
            <TableRow>
                <TextView android:text="Type: "/>
                <RadioGroup android:id="@+id/types">
                    <RadioButton android:layout_height="wrap_content" android:layout_width="fill_parent"
                                 android:id="@+id/take_out" android:text="Take-Out"/>
                    <RadioButton android:layout_height="wrap_content" android:layout_width="fill_parent"
                                 android:id="@+id/sit_down" android:text="Sit-Down"/>
                    <RadioButton android:layout_height="wrap_content" android:layout_width="fill_parent"
                                 android:id="@+id/delivery" android:text="Delivery"/>
                </RadioGroup>
            </TableRow>

            <Button android:id="@+id/save"
                    android:text="Save"
                    android:layout_height="wrap_content"
                    android:layout_width="fill_parent"/>
        </TableLayout>
        <ListView android:id="@+id/restaurants"
                  android:layout_width="fill_parent"
                  android:layout_height="wrap_content"
                  android:layout_alignParentTop="true"
                  android:layout_above="@id/details"
                />

    </RelativeLayout>
</ScrollView>
  • 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-24T09:50:10+00:00Added an answer on May 24, 2026 at 9:50 am

    As far as I can see, you initialise model:

    List<Restaurant> model = new LinkedList<Restaurant>();
    

    But don’t put any content in it, so there is nothing for your list to show

    EDIT: If you are adding content to your list dynamically, make sure that you are updating the list like this:

    model.add(restaurant);
    arrayAdapter.notifyDataSetChanged();
    

    Or:

    arrayAdapter.add(restaurant);
    arrayAdapter.notifyDataSetChanged();
    

    notifyDataSetChanged() lets the ListView know that the list contents have changed and it should redraw itself

    EDIT: Also, you are adding the ListView above the TableLayout called details, which has its heigh and width set to fill_parent, so you may not see the ListView if the TableLayout is taking up the whole screen. Try changing the height of details to wrap_content

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

Sidebar

Related Questions

So I just started learning Android and I am reading the commonsware android development
Reading on SQL Server Book online and my understanding SQL Server Buffer Pool or
Reading the book I found the following: The way of thinking when you model
Reading through more SICP and I'm stuck on exercise 1.3.8 . My code works
Reading through Thinking in Java i stuck in ex:6 of Inner Classes chapter. Exercise
Reading the section Zend_Application_Resource_Modules in the docs here: http://framework.zend.com/manual/1.10/en/zend.application.available-resources.html I noticed this: You can
reading the SCJP book, I've found something like this in the chapter 1 self-test
Reading this: http://guides.rubyonrails.org/routing.html#adding-more-restful-actions What does it mean to add a 'member route'? or do
Reading the questions here and here has given me some insight into the situation,
Reading through the existing unit testing related threads here on Stack Overflow, I couldn't

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.