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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T15:32:08+00:00 2026-06-04T15:32:08+00:00

After i click more button, it suppose will extend the listview from 10 to

  • 0

After i click “more” button, it suppose will extend the listview from 10 to 20.

However after clicked, the list view did not extend and remain original size.

It only can keep the position of scroll bar. This is half of what i need.

newsid = new int[webservice.news.size()];
        title = new String[webservice.news.size()];
        date = new String[webservice.news.size()];
        imagepath = new String[webservice.news.size()];
        for (int i = 0; i < webservice.news.size(); i++) {
            newsid[i] = webservice.news.get(i).getID();
            title[i] = webservice.news.get(i).getNtitle();
            date[i] = webservice.news.get(i).getNArticalD();
            imagepath[i] = webservice.news.get(i).getImagePath();
        }
        adapter = new CustomAdapter_ParticularCategoryAllNews(this, title,
                date, imagepath);
        lv.addFooterView(footermore);
        if (constant.isOnline()) {
            lv.addFooterView(constant.AdMob());
        }
        TextView titletext = (TextView) findViewById(R.id.text_pagetitle);
        titletext.setText(pagetitletext.toString());
        lv.setAdapter(adapter);

This is call when launch activity.

btnmore.setOnClickListener(new OnClickListener() {
    public void onClick(View arg0) {
for (int i = 0; i < webservice.news.size(); i++) {                                                                           
newsid[i] = webservice.news.get(i).getID();
title[i] = webservice.news.get(i).getNtitle();
date[i] = webservice.news.get(i).getNArticalD();
imagepath[i] = webservice.news.get(i).getImagePath();
}       
adapter.setTitle(title);
adapter.setDate(date);
adapter.setImagepath(imagepath);
position = lv.getFirstVisiblePosition();
lv.smoothScrollToPosition(position);
adapter.notifyDataSetChanged();

This is what i call after i click “more button”. However the list did not extend from 10 to 20 items.

public class CustomAdapter_ParticularCategoryAllNews extends BaseAdapter {

private Activity activity;
private String[] title, date, imagepath;
private static LayoutInflater inflater = null;
private ImageLoader_Loader imageLoader;
private WindowManager wm = null;
private Display display;
private Config_ConstantVariable constant;

public CustomAdapter_ParticularCategoryAllNews(Activity a, String[] title,
        String[] date, String[] imagepath) {
    activity = a;
    this.title = title;
    this.date = date;
    this.imagepath = imagepath;
    inflater = (LayoutInflater) activity
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    wm = (WindowManager) activity.getSystemService(Context.WINDOW_SERVICE);
    imageLoader = new ImageLoader_Loader(activity.getApplicationContext());
    constant = new Config_ConstantVariable(activity);
}

public int getCount() {
    return title.length;
}

public Object getItem(int position) {
    return position;
}

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

public void setTitle(String[] title) {
    this.title = title;
}

public void setDate(String[] date) {
    this.date = date;
}

public void setImagepath(String[] imagepath) {
    this.imagepath = imagepath;
}

public View getView(int position, View convertView, ViewGroup parent) {
    View vi = convertView;
    if (convertView == null)
        vi = inflater.inflate(R.layout.main_particularcategoryallnewslist,
                parent, false);

    LinearLayout linear = (LinearLayout) vi.findViewById(R.id.layout_image);

    ImageView imageview = (ImageView) vi
            .findViewById(R.id.image_categoryallnewstitle);

    TextView titletext = (TextView) vi
            .findViewById(R.id.text_categoryallnewstitle);

    TextView datetext = (TextView) vi.findViewById(R.id.text_newsdate);

    if (!imagepath[position].toString().equals("no picture")) {
        imageview.setVisibility(View.VISIBLE);
        linear.setVisibility(View.VISIBLE);
        imageLoader.DisplayImage(imagepath[position], imageview);
    } else {
        imageview.setVisibility(View.GONE);
        imageview.setImageDrawable(null);
        linear.setVisibility(View.GONE);
        display = wm.getDefaultDisplay();
        int screenWidth = display.getWidth();
        titletext.setWidth(screenWidth);
    }
    if (constant.getscreenresolution() >= 800 && constant.ScreenOrientation() == 1) {
        titletext.setTextSize(TypedValue.COMPLEX_UNIT_PX, 30);
        datetext.setTextSize(TypedValue.COMPLEX_UNIT_PX, 20);
    }
    titletext.setText(title[position].toString());
    datetext.setText(date[position].toString());
    return vi;
}

}

This is the CustomAdapter class.

  • 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-04T15:32:10+00:00Added an answer on June 4, 2026 at 3:32 pm

    In your adapter add:

    public void setTitle(String[] title) {
        this.title = title;
    }
    
    public void setDate(String[] date) {
        this.date = date;
    }
    
    public void setImagepath(String[] imagepath) {
        this.imagepath = imagepath;
    }
    

    When the more button is pressed call the three methods above with arrays containing 20 objects. Then call notifyDataSetChanged on your adapter.

    Update:

    This is working for me:
    Activity:

    public class HelpProjectActivity extends Activity {
    
        private ArrayList<Item> items;
        private boolean extend = false;
        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
    
            createArray();
    
            ListView lv = (ListView)findViewById(R.id.list);
            lv.setAdapter(new HelpListAdapter());
        }
    
        private void createArray() {
            items = new ArrayList<Item>();
            for(int i = 0; i < 20; i++) {
                Item item = new Item();
                item.title = "Title " + i;
                item.subtitle = "Subtitle " + i;
                item.image = "default";
                items.add(item);
            }
        }
    
        public void morePressed(View v) {
            extend = !extend;
            Button b = (Button) findViewById(R.id.button);
            b.setText(extend ? R.string.less_button : R.string.more_button);
            ListView lv = (ListView)findViewById(R.id.list);
            ((BaseAdapter)lv.getAdapter()).notifyDataSetChanged();
        }
    
        private class HelpListAdapter extends BaseAdapter {
    
            @Override
            public int getCount() {
                if (extend) {
                    return items.size();
                } 
                return items.size()/2;
            }
    
            @Override
            public Object getItem(int pos) {
                return items.get(pos);
            }
    
            @Override
            public long getItemId(int pos) {
                return pos;
            }
    
            @Override
            public View getView(int pos, View convertView, ViewGroup parent) {
                View v = convertView;
                if (v == null) {
                    v = View.inflate(getApplicationContext(), R.layout.litst_item, null);
                }
                Item item = items.get(pos);
                TextView titleText = (TextView) v.findViewById(R.id.list_item_title);
                titleText.setText(item.title);
                TextView subtitleText = (TextView) v.findViewById(R.id.list_item_subtitle);
                subtitleText.setText(item.subtitle);
                ImageView image = (ImageView) v.findViewById(R.id.list_image);
                if (item.image.equalsIgnoreCase("default")) {
                    image.setImageResource(R.drawable.default_list_image);
                } else {
                    // what ever
                }
                return v;
            }
    
        }
    }
    

    main.xml:

    <?xml version="1.0" encoding="utf-8"?>
    <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/button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal"
            android:layout_margin="10dp"
            android:onClick="morePressed"
            android:text="@string/more_button" />
    
        <ListView
            android:id="@+id/list"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" />
    
    </LinearLayout>
    

    list_item.xml:

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >
    
        <ImageView
            android:id="@+id/list_image"
            android:layout_width="40dp"
            android:layout_height="40dp"
            android:layout_margin="5dp"
            android:layout_gravity="center_vertical"
            android:contentDescription="@string/list_image" />
    
        <LinearLayout
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:orientation="vertical" >
    
            <TextView
                android:id="@+id/list_item_title"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:textStyle="bold" />
    
            <TextView
                android:id="@+id/list_item_subtitle"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:textStyle="italic" />
        </LinearLayout>
    
    </LinearLayout>
    

    Item.java:

    public class Item {
        String image;
        String title;
        String subtitle;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to change data on listview runtime after button click... here is my
I want when I click load more button content will automatic scroll to the
I am facing a problem while disabling the command button after one click. I
I want to make a button that starts my php script after I click
What are the ways to restrict the User to click a button more than
I need to click an html button and navigate to another page. After click
Let's suppose I have 2 forms: FormA and FormB . On FormA button click
Steps to reproduce : Click the append button more than 10 times on -
I want an alert dialog box to pop up after I click a button
I have a list of posts and a load more button to load more

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.