简体   繁体   English

Android ScrollView在最终滚动上添加数据

[英]Android ScrollView add data on end scroll

I've read a lot of posts but never find solution for my problem which is: I have LinearLayout inside ScrollView. 我已经阅读了很多文章,但是从来没有找到解决我的问题的方法:我在ScrollView中有LinearLayout。 LinearLayout containt inflated Layout. LinearLayout包含膨胀的Layout。 At the end I have button. 最后,我有一个按钮。 When user clicks on the button it inflates more Layouts (adds more table rows). 当用户单击按钮时,它会放大更多的布局(添加更多的表行)。 Now, I want to remove the button and call its function when user scrolls to bottom. 现在,我想删除按钮并在用户滚动到底部时调用其功能。

--edited-- -编辑-

Here is part of my code... 这是我的代码的一部分...

public void showRows(){
    try {
        mydb = openOrCreateDatabase(DBNAME, Context.MODE_PRIVATE, null);
        Cursor select = mydb.rawQuery("SELECT * from TRANSACTIONS "+
          "limit "+nRow+",20", null);

        if (select.moveToFirst()) {
            do {
                LinearLayout item = (LinearLayout)findViewById(R.id.item);
                View child = getLayoutInflater().inflate(R.layout.child, null);
                item.addView(child);

                TextView txt = (TextView) child.findViewById(R.id.txt);
                txt.setText(select.getString(0));

            } while (select.moveToNext());
        }
    } catch (Exception e) {
        Toast.makeText(getApplicationContext(), "Reading error.", Toast.LENGTH_LONG).show();
    } finally {
        mydb.close();

        if(nRow+11 <= nTotalRows){
            LinearLayout item = (LinearLayout)findViewById(R.id.item);
            child_more = getLayoutInflater().inflate(R.layout.transaction_more, null);
            item.addView(child_more);
            bMore = (Button) child_more.findViewById(R.id.bMore);
            bMore.setOnClickListener(this);

            // on click nRow = nRow + 20 ... and calls again the same function

            //TODO...
            //...remove button but call more if ScrollView reachs end...
        }
    }

}

I'll suggest to use ListView for this case. 我建议在这种情况下使用ListView。 You'll be able to detect when last item was shown and call the same method that button's click called. 您将能够检测到何时显示最后一项,并调用与按钮单击相同的方法。 You can hide button by calling bMore.setVisibility(View.GONE); 您可以通过调用bMore.setVisibility(View.GONE)来隐藏按钮。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM