[英]How to get list row item(textview) id and text in onScroll of Listview in android?
I have used base adapter in to create a custom listview. 我已经使用基本适配器创建了一个自定义列表视图。 There is an ImageView and TextView in each row of listview. 列表视图的每一行中都有一个ImageView和TextView。 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. 我想做的是,当我滚动列表视图时,我想在列表视图的firstvisible行中获取textview的文本,然后使textview在列表视图的firstvisible行中不可见。 How can I get Id and data of a view in onScroll method of listview. 如何在ListView的onScroll方法中获取视图的ID和数据。
@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();
}*/
}
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, 希望对您有帮助,
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.