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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T10:38:30+00:00 2026-06-07T10:38:30+00:00

I have a ListView and a widget. I want the widget to be always

  • 0

I have a ListView and a widget. I want the widget to be always on the top of ListView, and it should be able to scroll with the items but when there is no items in adapter it should still be visible. This is how it doesn’t scroll:

enter image description here

enter image description here

The layout file:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent"
              android:orientation="vertical">
    <Button
            android:id="@+id/btn_togle_empty"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="toggle empty"
            />


    <FrameLayout
            android:layout_width="fill_parent"
            android:layout_height="0dp"
            android:layout_weight="1">
        <ListView
                android:id="@+id/list_test"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"


                />
        <ViewStub
                android:id="@+id/empty_layout"
                android:layout="@layout/empty"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"/>
    </FrameLayout>

</LinearLayout>

The code for the activity:

public class MyActivity extends Activity {
    private MyAdapter adapter;
    private ListView v;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_test);
         v = (ListView) findViewById(R.id.list_test);
        View empty = findViewById(R.id.empty_layout);
        v.setEmptyView(empty);
        final MyAdapter adapter = new MyAdapter();
        v.setAdapter(adapter);
        Button btn = (Button) findViewById(R.id.btn_togle_empty);
        btn.setOnClickListener(new View.OnClickListener(){
            @Override
            public void onClick(View view) {
                adapter.togleEmpty();
            }
        });
    }

    private  class MyAdapter extends BaseAdapter {
       boolean empty = false;
        @Override
        public int getCount() {
            return empty ? 0 : 50;
        }

        @Override
        public Object getItem(int i) {
            return new Object();
        }

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

        @Override
        public View getView(int i, View view, ViewGroup viewGroup) {
            TextView v =  new TextView(MyActivity.this);
            v.setText("STRING");
            return v;
        }


        public void togleEmpty() {
            empty = !empty;
            notifyDataSetChanged();
        }
    }
}

I had one more idea, add the widget as header, but it disappears when the ListView is empty. How can I achieve the result I want?

  • 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-07T10:38:32+00:00Added an answer on June 7, 2026 at 10:38 am
            @Override
            public View getView(int i, View view, ViewGroup viewGroup) {
                if (i == 0) { return custom_widget_view; }
            }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have listview control.There is an option to remove selected items.After the user removes
I want get data in db to listview. but it have error I cannot
I have a ListView that uses a customized adapter, but I can't click on
i have a ListView that simly shows items on it. I want to load
I want to tap a control on the screen and have the ListView scroll
I would have listview and a lot of items inside. I want that user
I have a listview extends Activity and use custom adapter because I want icon
I have the following problem: I display items on a ListView and I want
I have a ListView with Horizontal WrapPanel as its ItemsPanelTemplate. I want to get
I have a listview with two labels, title and subtitle. I want to have

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.