0

I have used base adapter in to create a custom listview. There is an ImageView and TextView in each row of listview. What I want to do is that when I scroll listview I want to get the text of textview in firstvisible row of listview and then I want to make the textview invisible of firstvisible row of listview. How can I get Id and data of a view in onScroll method of listview.

@Override
        public View getView(int arg0, View convertView, ViewGroup arg2) {
            // TODO Auto-generated method stub

            convertView = LayoutInflater.from(MainActivity.this).inflate(R.layout.list_row, arg2, false);
            TextView tv = (TextView)convertView.findViewById(R.id.textViewrow);
            tv.setText("position " + arg0);
            tv_item = tv;
//          tv.setTag("position " + arg0);




            return convertView;
        }





@Override
            public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
                // TODO Auto-generated method stub
//              ViewGroup viewGroup = (ViewGroup) view.getAdapter()
//                        .getView(firstVisibleRow, null, view);//
                int post = lv.getFirstVisiblePosition();
                TextView tv = (TextView)lv.findViewWithTag("position " + post);
                System.out.println("position " + post);
//              View v= lv.findViewWithTag("position " + post);
//              v.findViewById(R.id.textViewrow).gett
//              System.out.println("position text" + tv.getText());



                /*tv_item.getHitRect(rect2);
                if (Rect.intersects(rect1, rect2)) {
                    Toast.makeText(getApplicationContext(), "intersected", Toast.LENGTH_LONG).show();
                }*/

            }
rahul
  • 2,613
  • 8
  • 32
  • 55

1 Answers1

1

I guess this problem is connected with this :)

To resolve your problem I searched a little and I found this

Now to fix your problem you have to follow these steps:

You have to get the View of your first visible row like this:

    ....
    @Override
    public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {

        View view = mListView.getAdapter().getView(firstVisibleItem, null, mListView);
        TextView mTextView = (TextView) view.findViewById(R.id.textViewrow);
        mTextView.setVisbility(View.GONE);

I hope it helps you,

Community
  • 1
  • 1
Ultimo_m
  • 4,724
  • 4
  • 38
  • 60
  • Your answer is perfect and helped me alot but there is a problem that my list scroll is not smooth now. once I scroll then I can't scroll my list until the list scrolling stops. Can you please suggest me a solution for that? – rahul Jun 22 '14 at 17:17
  • Take a look at section 8 here: http://www.vogella.com/tutorials/AndroidListView/article.html or here: http://developer.android.com/training/improving-layouts/smooth-scrolling.html – Ultimo_m Jun 22 '14 at 17:41