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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T07:08:02+00:00 2026-06-01T07:08:02+00:00

I want to display a simple array of strings in a ListPopupWindow that is

  • 0

I want to display a simple array of strings in a ListPopupWindow that is shown on a button click. I’m running into problems however, as when I do some minimal setup of either an ArrayAdapter<String> or a custom-built adapter, I run into a resources not found exception when I go to show the popup window. Here is the code I’m using (with the stack trace after it). Any ideas as to what is happening?

public class AndroidSandboxActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        final Button btn = (Button)findViewById(R.id.btn1);
        btn.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                showListPopup(btn);
            }
        });
    }

    public void showListPopup(View anchor) {
        ListPopupWindow popup = new ListPopupWindow(this);
        popup.setAnchorView(anchor);

        ListAdapter adapter = new MyAdapter(this);
        popup.setAdapter(adapter);
        popup.show();
    }

    public static class MyAdapter extends BaseAdapter implements ListAdapter {
        private final String[] list = new String[] {"one","two","three"};
        private Activity activity;
        public MyAdapter(Activity activity) {
            this.activity = activity;
        }

        @Override
        public int getCount() {
            return list.length;
        }

        @Override
        public Object getItem(int position) {
            return list[position];
        }

        @Override
        public long getItemId(int position) {
            return position;
        }

        private static int textid = 1234;
        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            TextView text = null;
            if (convertView == null) {
                LinearLayout layout = new LinearLayout(activity);
                layout.setOrientation(LinearLayout.HORIZONTAL);

                text = new TextView(activity);
                text.setId(textid);
                layout.addView(text);
                convertView = layout;
            } else {
                text = (TextView)convertView.findViewById(textid);
            }
            text.setText(list[position]);
            return convertView;
        }
    }
}

And here’s the stack trace (the thing that boggles my mind is that it says it’s using an ArrayAdapter when I’m using my own custom adapter):

Thread [<1> main] (Suspended (exception Resources$NotFoundException))   
    Resources.loadXmlResourceParser(int, String) line: 2047 
    Resources.getLayout(int) line: 853  
    PhoneLayoutInflater(LayoutInflater).inflate(int, ViewGroup, boolean) line: 389  
    ArrayAdapter.createViewFromResource(int, View, ViewGroup, int) line: 375    
    ArrayAdapter.getView(int, View, ViewGroup) line: 366    
    ListPopupWindow$DropDownListView(AbsListView).obtainView(int, boolean[]) line: 2146 
    ListPopupWindow$DropDownListView.obtainView(int, boolean[]) line: 1156  
    ListPopupWindow$DropDownListView(ListView).measureHeightOfChildren(int, int, int, int, int) line: 1261  
    ListPopupWindow.buildDropDown() line: 1083  
    ListPopupWindow.show() line: 517    
    AndroidSandboxActivity.showListPopup() line: 41 
    AndroidSandboxActivity$1.onClick(View) line: 28 
    Button(View).performClick() line: 3122  
    View$PerformClick.run() line: 11942 
    ViewRoot(Handler).handleCallback(Message) line: 587 
    ViewRoot(Handler).dispatchMessage(Message) line: 92 
    Looper.loop() line: 132 
    ActivityThread.main(String[]) line: 4028    
    Method.invokeNative(Object, Object[], Class, Class[], Class, int, boolean) line: not available [native method]  
    Method.invoke(Object, Object...) line: 491  
    ZygoteInit$MethodAndArgsCaller.run() line: 844  
    ZygoteInit.main(String[]) line: 602 
    NativeStart.main(String[]) line: not available [native method]  

Any help would be appreciated!

  • 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-01T07:08:03+00:00Added an answer on June 1, 2026 at 7:08 am

    I figured out why an ArrayAdapter didn’t work; I was choosing an incorrect resource id for the array adapter, as I did not entirely understand how ArrayAdapters worked regarding list views. Using this builtin android resource:

    android.R.layout.simple_dropdown_item_1line
    

    in the relevant resource argument when constructing the array adapter, I was able to get things to work. I’m not sure exactly why my custom adapter above didn’t work, though, as my custom adapter in the code above didn’t reference any specific ID. The stack trace I provided was probably from an old version of the code that did use an ArrayAdapter.

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

Sidebar

Related Questions

I want to display a simple GIF image in a VBox using GTK+ from
I have a simple quiz application and I want display a nice timer /
i want to use facebook's fb:dialog tag to display a simple pop-up form for
I have this simple Java Script code to display the date. I want to
I have a simple PHP Array called $categories that looks like this: Array (
I want to display: Name [Textbox] Age: [Textbox] BlahBlahCatfish: [Textbox] but if I simply
here the sample case.. i want to display banner randomly by percentage based on
I want display data from database in Listbox...Here is my code, It is not
i want display 1 record from colums zodys , I'm programint in C# I
I have db with this table (TableToDo): http://goo.gl/NlTEk I want display all records in

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.