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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T08:16:48+00:00 2026-06-09T08:16:48+00:00

I have a custom dialog which extends Dialog and has a ListView inside its

  • 0

I have a custom dialog which extends Dialog and has a ListView inside its layout. I populate my ListView via a custom adapter which extends ArrayAdapter. Here is my adapter which contains the onClick event for a given list item:

public class PendingTimeslotArrayAdapter extends ArrayAdapter<PendingTimeslot> {
    private final Context context;
    private final PendingTimeslot[] values;
    private final View[] views;

    public PendingTimeslotArrayAdapter(Context context, PendingTimeslot[] values) {
        super(context, R.layout.mystuff_timeslot_picker_dialog_list_item, values);
        this.context = context;
        this.values = values;
        this.views = new View[values.length];
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if(views[position] == null){
            LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

            View rowView = inflater.inflate(R.layout.mystuff_timeslot_picker_dialog_list_item, parent, false);
            rowView.setTag((Integer)position);

            ((TextView)rowView.findViewById(R.id.mystuff_timeslot_picker_list_item_date_time)).setText(values[position].getDateTime());
            ((TextView)rowView.findViewById(R.id.mystuff_timeslot_picker_list_item_stage_name)).setText(values[position].getStageName());

            rowView.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    System.out.println("getting touch event");
                    PendingTimeslot t = values[(Integer)(v.getTag())];
                    CheckBox checkBox = (CheckBox) v.findViewById(R.id.mystuff_timeslot_picker_list_item_checkbox);
                    checkBox.setChecked(!checkBox.isChecked());
                    t.toggle();
                }
            });

            views[position] = rowView;
            return rowView;
        }
        else
            return views[position];
    }
}

My problem is that when list items are clicked, they do not get touch events, hence my onClick does not get called. Funny thing is, the ListView is fully scrollable and when an item goes out of the visible region and comes back, it becomes touchable and the onClick event is fired.

I tried overriding the ListView and its onTouchEvent method; when an item is clicked, the onTouchEvent on the ListView is really not fired. I also tried overriding the dispatchTouchEvent method and it works correctly, getting all touch events as it is supposed to.

I have used a similar custom ArrayAdapter elsewhere (but not within a Dialog) and it works flawlessly. I am now considering this to be a bug. Am I missing something or should I do this (ListView with clickable items inside a Dialog) another way?

Edit:

Adding

rowView.setClickable(true);
rowView.setFocusable(true);

does absolutely nothing.

Edit2:

Setting an onItemClickListener for my ListView does not work either, even for the items which are scrolled out of and back into the visible region.

Edit3:

I also noticed that when there are 16 items (not a special number) in the ListView, the last 5 items do not get the height I specified (e.g 100px) in the layout I inflate, they behave like wrap_content instead. All in all, I’m starting to believe that a ListView should not be used in a Dialog.

  • 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-09T08:16:50+00:00Added an answer on June 9, 2026 at 8:16 am

    One possible solution I found is to quit trying to use a ListView and instead use a ScrollView with a vertical LinearLayout inside. The layout of this ScrollView is like this:

    <ScrollView
        android:layout_width="wrap_content"
        android:layout_height="0dp"
        android:layout_weight="1" >
    
        <LinearLayout
            android:id="@+id/mystuff_timeslot_picker_list"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="vertical" >
        </LinearLayout>
    </ScrollView>
    

    After I get the list data, I inflate a row for each of them and add them to the LinearLayout manually:

    LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    for(PendingTimeslot p : timeslots){
        View rowView = inflater.inflate(R.layout.mystuff_timeslot_picker_dialog_list_item, timeslotList, false);
        //((TextView)rowView.findViewById(R.id.mystuff_timeslot_picker_list_item_date_time)).setText(values[position].getDateTime());
        ((TextView)rowView.findViewById(R.id.mystuff_timeslot_picker_list_item_date_time)).setText("just testing");
        //((TextView)rowView.findViewById(R.id.mystuff_timeslot_picker_list_item_stage_name)).setText(values[position].getStageName());
    
        rowView.setClickable(true);
        rowView.setFocusable(true);
    
        rowView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                System.out.println("just testing");
                //PendingTimeslot t = values[(Integer)(v.getTag())];
                CheckBox checkBox = (CheckBox) v.findViewById(R.id.mystuff_timeslot_picker_list_item_checkbox);
                checkBox.setChecked(!checkBox.isChecked());
            }
        });
    
        timeslotList.addView(rowView);
    }
    

    timeslotList is the LinearLayout I mentioned. This workaround works as expected. Still, I’m feeling very stupid having to use ScrollViews instead of ListViews when they are perfect for the job.

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

Sidebar

Related Questions

I have a custom dialog which described below. My Custom Dialog layout ( *my_dialog.xml*
Hello i'm implementing a custom dialog. I have a class which extends Dialog .
I have created a My custom Dialog which extends org.eclipse.jface.dialogs.Dialog. But whenever it displays,
I currently have a custom Dialog class that extends DialogPreference(which of course is a
I have created a custom dialog called MyCustomDialog which extends Dialog . I create
I have a VideoView inside a custom Dialog. The first time the Dialog is
I have a custom activity which has inargument<MyClass>. MyClass has several properties. I want
I have a custom build print dialog that is used for many reports. Its
Possible Duplicate: Dismiss a custom dialog? I have a customized dialog, the layout file
ok, I'm here again to ask one dummy question. I have a custom dialog

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.