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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T10:18:27+00:00 2026-06-12T10:18:27+00:00

I have a ListView in a PopupWindow . The PopupWindow is initialized like this

  • 0

I have a ListView in a PopupWindow. The PopupWindow is initialized like this

    window.setContentView(root);
    window.setTouchable(true);
    window.setFocusable(true);
    window.setOutsideTouchable(true);
    window.setWidth(WindowManager.LayoutParams.WRAP_CONTENT);
    window.setHeight(WindowManager.LayoutParams.WRAP_CONTENT);

Then the ListView:

    fileList = (ListView) root.findViewById(R.id.explorer_list);
    fileList.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
    fileList.setSelector(android.R.drawable.screen_background_light_transparent);
    fileList.setOnItemClickListener(this);

    [...]

    @Override
    public void onItemClick(AdapterView<?> adapter, View v, int pos, long id) {
        selected = (File) fileList.getItemAtPosition(pos);      
    }

Like this, everything works correctly except that the selector will not show up on selection until ListView is scrolled (nothing shows visually as selected until the list is scrolled, although the item is correctly selected).

If I set the PopupWindow not focusable, then the visual selection works correctly (the item is visually selected right when clicked into) but onItemClick() is never called and thus I cannot get the selected item.

ListView.getSelectedItem() always returns null in both cases, even if there’s a selected item.

Any idea on how to solve this situation? Thanks in advance.

  • 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-12T10:18:29+00:00Added an answer on June 12, 2026 at 10:18 am

    I finally used a custom adapter to store the selected value and use it from there to mark it:

    public class FileExplorerAdapter extends ArrayAdapter<File> {
    
        /** File names */
        private List<File> values = new ArrayList<File>();
    
        /** Currently selected position */
        private int selected = -1;
    
        public FileExplorerAdapter(Context context, List<File> values) {
            super(context, R.layout.explorer_row, values);
            this.values = values;
        }
    
        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
    
            // I know that my layout is always a TextView
            TextView row = (TextView) convertView;
            if (row == null) {
                row = (TextView) ViewHelper.inflateViewById(getContext(),
                        R.layout.explorer_row);
            }
    
            // More code...
    
            // Set up the background for selected element
            if (selected == position) {
                row.setBackgroundColor(Color.LTGRAY);
    
            // Override background selector
            } else {
                row.setBackgroundColor(Color.TRANSPARENT);
            }
    
            // More code...
    
            return row;
        }
    
        /** This sets the selected position */
        public void setSelected(int position) {
            selected = position;
        }
    }
    

    And on the class that implements the OnItemClickListener for the associated ListView, I set up the currently selected item in the adapter.

    @Override
    public void onItemClick(AdapterView<?> adapter, View v, int pos, long id) {
        FileExplorerAdapter fileadapter = (FileExplorerAdapter) fileList
                .getAdapter();
        fileadapter.setSelected(pos);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a ListView in a WPF window containing a number of GridViewColumns. The
I have a ListView and each item have a TextView. I would like add
I have listview with some listadapter after click on item from list I'd like
I have listview with combox=true containg images. Each item is assigned a tag. I
I have ListView. I would like to fill each row of ListView with a
I have ListView with custom Adapter which supplies View to ListView in this way:
I have an activity which have ListView. When I want to access this ListView
I have some EditViews in the rows of a ListView. This works just fine
I have listview item like below <LinearLayout xmlns:android=http://schemas.android.com/apk/res/android android:layout_width=match_parent android:layout_height=60dp android:orientation=horizontal android:descendantFocusability=blocksDescendants > <TextView
I have listview similar to this: Add code, it isn't much, but maybe helpful:

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.