【问题标题】:Android ScrollView add data on end scrollAndroid ScrollView 在结束滚动时添加数据
【发布时间】:2014-03-18 03:16:29
【问题描述】:

我已经阅读了很多帖子,但从未找到解决我的问题的方法: 我在 ScrollView 中有 LinearLayout。 LinearLayout 包含膨胀的布局。最后我有按钮。当用户单击按钮时,它会膨胀更多布局(添加更多表格行)。现在,我想删除按钮并在用户滚动到底部时调用它的函数。

--编辑过--

这是我的代码的一部分...

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...
        }
    }

}

【问题讨论】:

  • 请发布您的代码,以便我可以使用。

标签: android scrollview


【解决方案1】:

我建议在这种情况下使用 ListView。您将能够检测显示最后一个项目的时间并调用与单击按钮相同的方法。 您可以通过调用 bMore.setVisibility(View.GONE); 来隐藏按钮

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-12-22
    • 1970-01-01
    • 1970-01-01
    • 2017-07-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多