search

Home  >  Q&A  >  body text

java - 安卓 如何实现RecyclerView嵌套listview 实现类似淘宝购物车这种的数据显示

PHP中文网PHP中文网2804 days ago936

reply all(3)I'll reply

  • 迷茫

    迷茫2017-04-18 10:48:03

    Why does it have to be nested? You can have a listview on the left and a listview or fragment on the right. When you click on the item of the listview, wouldn’t it be nice to change the data on the right

    reply
    0
  • 伊谢尔伦

    伊谢尔伦2017-04-18 10:48:03

    The layout of item can be a TextView and a LinearLayout, where LinearLayout can addView.
    The pseudo code is as follows, first encapsulate the data

    class CourseList{
    
    String name;
    List<Course> courses;
    
    }

    When binding data in Adapter,

    TextView.setText(name)
    
    for(i=0;i<courses.size();i++){
    
      TextView tv =new TextView();
      tv.setText(courses.get(i).name);
      LinearLayout.add(tv);
    
    }
    
    

    Another idea is that the layout of the item is TextView and RecycleView, but considering that when the number of specific courses exceeds the screen height, there will be a sliding conflict with the parent ListView, which is very troublesome to solve.

    reply
    0
  • 阿神

    阿神2017-04-18 10:48:03

    The solution mentioned above is a solution, but actually nesting is not that troublesome. You rewrite the onDispatchTouchEvent event of the child view and make a sliding gesture judgment. If it is sliding, give up processing the entire event sequence, or rewrite the parent view. OnDispatchTouchEvent is no longer distributed when it slides. The principle is the same.

    reply
    0
  • Cancelreply