How can I update a single row in a ListView?

前端 未结 11 2067
时光说笑
时光说笑 2020-11-22 17:07

I have a ListView which displays news items. They contain an image, a title and some text. The image is loaded in a separate thread (with a queue and all) and w

11条回答
  •  谎友^
    谎友^ (楼主)
    2020-11-22 17:49

    int wantedPosition = 25; // Whatever position you're looking for
    int firstPosition = linearLayoutManager.findFirstVisibleItemPosition(); // This is the same as child #0
    int wantedChild = wantedPosition - firstPosition;
    
    if (wantedChild < 0 || wantedChild >= linearLayoutManager.getChildCount()) {
        Log.w(TAG, "Unable to get view for desired position, because it's not being displayed on screen.");
        return;
    }
    
    View wantedView = linearLayoutManager.getChildAt(wantedChild);
    mlayoutOver =(LinearLayout)wantedView.findViewById(R.id.layout_over);
    mlayoutPopup = (LinearLayout)wantedView.findViewById(R.id.layout_popup);
    
    mlayoutOver.setVisibility(View.INVISIBLE);
    mlayoutPopup.setVisibility(View.VISIBLE);
    

    For RecycleView please use this code

提交回复
热议问题