N Sharma
N Sharma

Reputation: 34497

How to scroll the second row of listview to top of the screen

Hello I am working on demo application where I am using listview and custom adapter. I want to do that when I scroll the list when you come at position to 2 or 3 then that row should be on top of the screen means previous row should be hide completely.

Example I am on first row first time and started to scroll listview then comes to second when getview call with position 2 then list should only show of row 2 on the screen. How I can achieve this ? Please assist.

See screenshot when I scroll then both rows appear when I even move to row 2 then first row also appears until I move up list manually.

enter image description here

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    if(convertView == null) {
        LayoutInflater mInflator = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        convertView = mInflator.inflate(R.layout.home_list_item, parent, false);
    }

    TextView mChapterContent = (TextView) convertView.findViewById(R.id.contentTextView);

    // get the data from verse instance
    Verse verse = rowItem.get(position);

    // setting the content
    mChapterContent.setText(Html.fromHtml("<html><body style=\"text-align:justify\">" + verse.getText() + "</body></html>"));



    return convertView;
}

Thanks in advance.

Upvotes: 0

Views: 863

Answers (2)

vipul mittal
vipul mittal

Reputation: 17401

Judging from the state, it looks to me as a good use-case of Vertical View pager.

Checkout these likes:

https://github.com/JakeWharton/Android-DirectionalViewPager/

Android: Vertical ViewPager

Upvotes: 2

Brian
Brian

Reputation: 8085

You can use the ListView's setSelection feature to scroll to a particular item in the list as follows...

listView.setSelection(2)

Or if you want it animated...

listView.smoothScrollToPosition(2)

This answer is referenced from this answer.

Upvotes: 0

Related Questions