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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T06:18:52+00:00 2026-05-27T06:18:52+00:00

The app I’m struggling to make has a simple list and a button present

  • 0

The app I’m struggling to make has a simple list and a button present in the bottom no matter what. My problem is that my custom BaseAdapter doesn’t show elements. I know that since my elements are only a string I could use an ArrayAdapter, but the assignment requires it. The code:

class ListaOrase extends BaseAdapter{
    private Activity context;
    ArrayList<String> orase;

    public ListaOrase(Activity context){
        this.context=context;
        orase=new ArrayList<String>();
    }
    public void add(String string){
        orase.add(string);
    }
public int getCount() {
        // TODO Auto-generated method stub
        return 0;
    }

    public Object getItem(int arg0) {
        // TODO Auto-generated method stub
        return null;
    }

    public long getItemId(int arg0) {
        // TODO Auto-generated method stub
        return 0;
    }


    public View getView (int position, View convertView, ViewGroup list)  {
        View element;
        if (convertView == null)
        {
         LayoutInflater inflater = context.getLayoutInflater();
         element = inflater.inflate(R.layout.lista, null);
        }
        else element = convertView;
        TextView elementLista=(TextView)element.findViewById(R.id.elementLista);    
        elementLista.setText(orase.get(position));
        return element;
    }

}
public class WeatherAppActivity extends ListActivity {

    Button buton;
    ListaOrase lista;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        lista=new ListaOrase(this);
        buton=(Button)findViewById(R.id.buton);
        setListAdapter(lista);

        lista.add("Bucuresti");
        lista.add("Sibiu");

    }
}

My XML files go like this:

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



<ListView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:id="@android:id/list"
    android:layout_alignParentTop="true"/>

<RelativeLayout 
    android:id="@+id/relative"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true">
<Button
        android:id="@+id/buton"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:onClick="add"
        android:text="Add"
        android:layout_gravity=""
        /> 
        </RelativeLayout>

</RelativeLayout>
lista.xml -- for the list
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >
<TextView 
        android:id="@+id/elementLista"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        />


</LinearLayout>

The button “downstairs” opens a dialog that adds items to my list. It obviously doesn’t work, but I think it’s the BaseAdapter (ListaOrase) itself, as the intents throw no exceptions. I would be thankful if the items I hardcoded in would show up (Bucuresti and Sibiu).

What am I doing wrong?
Thank you very much! 🙂

  • 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-27T06:18:52+00:00Added an answer on May 27, 2026 at 6:18 am

    Your code almost perfect issue is return orase.size() in getcount() method,you are returning 0, add unimplemented methods in ListaOrase class.
    your ListaOrase should be like this:

    class ListaOrase extends BaseAdapter{
        private Activity context;
        ArrayList<String> orase;
    
        public ListaOrase(Activity context){
            this.context=context;
            orase=new ArrayList<String>();
        }
        public void add(String string){
            orase.add(string);
        }
    
        public View getView (int position, View convertView, ViewGroup list)  {
            View element;
            if (convertView == null)
            {
             LayoutInflater inflater = context.getLayoutInflater();
             element = inflater.inflate(R.layout.lista, null);
            }
            else element = convertView;
            TextView elementLista=(TextView)element.findViewById(R.id.elementLista);    
            elementLista.setText(orase.get(position));
            Log.e("",orase.get(position));
            return element;
        }
        public int getCount() {
            // TODO Auto-generated method stub
            return orase.size();
        }
        public Object getItem(int position) {
            // TODO Auto-generated method stub
            return null;
        }
        public long getItemId(int position) {
            // TODO Auto-generated method stub
            return 0;
        }
    
    }
    

    hope this helps

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

Sidebar

Related Questions

My app has a DataGridView object and a List of type MousePos. MousePos is
My app has an advanced feature that accepts SQL queries written by the user.
My app has many controls on its surface, and more are added dynamically at
App A has this BroadcastReceiver in its manifest (within <application>): And this receiver: public
My app interacts with both Oracle and SQL Server databases using a custom data
App Description: I have a UIWebview and a Toolbar beneath it. A button on
The app I'm working on is relatively simple but it is throwing memory warnings.
My app allows users to have custom subdomains, as in user1.domain.com. I am integrating
my app has a submit feedback form. Is there a way to can capture
My app has supports multiple size widgets per the scheme outlined here how to

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.