android: listview inside a scrollView doesn't work?

后端 未结 3 576
生来不讨喜
生来不讨喜 2020-12-21 15:37

I am having a listview inside a scrollview, but the problem is that the scrollview is scrolling but listview is not scrol

3条回答
  •  既然无缘
    2020-12-21 16:07

    ListView must have fixed height as below in your XML file

            
    

    In Java file, write below code after setContentView()

            lv = (ListView)findViewById(R.id.lv);
            lv.setAdapter(your adapter here);  // you have to add your adapter here             
    
            lv.setOnTouchListener(new ListView.OnTouchListener() {
                @Override
                public boolean onTouch(View v, MotionEvent event) {
                    if (event.getAction() == MotionEvent.ACTION_MOVE)
                    {
                        lv.scrollBy(0, 1);
                    }
                    return false;
                }
            });
    

    Make these changes to your code and test it. After too many experiments i written this code. It is working 100% fine.

提交回复
热议问题