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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T13:29:25+00:00 2026-06-09T13:29:25+00:00

Hello, I am doing tutorials from book Android programming tutorials, I am having problems

  • 0

Hello, I am doing tutorials from book “Android programming tutorials”, I am having problems understanding Tutorial 5. This is the main Java class:

package tiago.tutorial;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.view.LayoutInflater;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.RadioGroup;
import android.widget.TextView;
import java.util.ArrayList;
import java.util.List;

public class Now extends Activity {
  List<Restaurant> model = new ArrayList<Restaurant>();
  RestaurantAdapter adapter = 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 list = (ListView) findViewById(R.id.restaurants);

    adapter = new RestaurantAdapter();
    list.setAdapter(adapter);
  }

  private View.OnClickListener onSave = new View.OnClickListener() {
    public void onClick(View v) {
      Restaurant r = new Restaurant();

      EditText name = (EditText) findViewById(R.id.name);
      EditText address = (EditText) findViewById(R.id.addr);

      r.setName(name.getText().toString());
      r.setAddress(address.getText().toString());

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

      switch (types.getCheckedRadioButtonId()) {
        case R.id.sit_down:
          r.setType("sit_down");
          break;

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

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

      adapter.add(r);
    }
  };

  class RestaurantAdapter extends ArrayAdapter<Restaurant> {
    RestaurantAdapter() {
      super(Now.this, R.layout.row, model);
    }

    public View getView(int position, View convertView, ViewGroup parent) {
      View row = convertView;
      RestaurantHolder holder = null;

      if (row==null) {                          
        LayoutInflater inflater = getLayoutInflater();

        row=inflater.inflate(R.layout.row, parent, false);
        holder = new RestaurantHolder(row);
        row.setTag(holder);
      }
      else {
        holder = (RestaurantHolder) row.getTag();
      }

      holder.populateFrom(model.get(position));

      return(row);
    }
  }

  static class RestaurantHolder {
    private TextView name = null;
    private TextView address = null;
    private ImageView icon = null;

    RestaurantHolder(View row) {
      name = (TextView) row.findViewById(R.id.title);
      address = (TextView) row.findViewById(R.id.address);
      icon = (ImageView) row.findViewById(R.id.icon);
    }

    void populateFrom(Restaurant r) {
      name.setText(r.getName());
      address.setText(r.getAddress());

      if (r.getType().equals("sit_down")) {
        icon.setImageResource(R.drawable.ball_red);
      }
      else if (r.getType().equals("take_out")) {
        icon.setImageResource(R.drawable.ball_yellow);
      }
      else {
        icon.setImageResource(R.drawable.ball_green);
      }
    }
  }
}

My real doubt at this moment is where is \getView()\ method ever called? This is working, but in code I cannot understand when is it called. If anyone is familiar with this book, please can you provide me a fast explanation about what’s happening in this code?

Thanks 🙂

  • 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-09T13:29:27+00:00Added an answer on June 9, 2026 at 1:29 pm

    getView() is basically called when something is trying to create the View that is associated with an element in that ArrayAdapter.

    It will return the View that is created for the element in the ArrayAdapter.


    A similar question has been asked before, see if this question helps you any.

    Another great tutorial on this subject that may be helpful in explaining what is going on with Adapaters.

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

Sidebar

Related Questions

I am doing the Android Hello, Testing Tutorial using Eclipse Galileo. ( http://developer.android.com/resources/tutorials/testing/helloandroid_test.html )
I am doing a tutorial according to this article . This is basic Hello
I was following the ListView official tutorial - [url]http://developer.android.com/resources/tutorials/views/hello-listview.html[/url], because I get the entries
Hello I am a new user to Python and I am having problem doing
Currently I am doing this: I have text that looks like: Hello ${user.name}, this
I am following this tutorial that is like the hello world for post-commit I
I am going through the android hello world tutorial, and have been stuck when
Hello I am doing some simple inserting into a table from my <php> and
I want to create an application on Facebook, after doing like the tutorial from
I'm doing the tutorial here . I got everything working up until this point:

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.