我简化了我的代码,使其更容易理解。我正在从数据库中读取一些数据并在Table Rows中插入。由于有数千个条目,因此加载和冻结UI需要时间。我想要的是在Fragment中移动进程,将SQL查询更改为每次只加载100个条目。我希望每次到达滚动结束时都将此片段添加到活动的末尾。这可以轻松实现吗?
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.order_det_v2);
TableLayout tl = (TableLayout) findViewById(R.id.prodTable);
newProductButton = (Button) findViewById(R.id.newProductButton);
//creates and open the database so we can use it
dataBase = DataBaseManager.instance();
Cursor cursor = dataBase.select("SELECT * FROM " + TABLE_NAME_PRODUCTS);
while (cursor.moveToNext()) {
int id = cursor.getInt(cursor.getColumnIndex(COLUMN_PRODUCTS_ID));
TextView textProdCode = new TextView(order_det_v2.this);
textProdCode.setLayoutParams(new TableRow.LayoutParams(0, 60, 0.08f));
textProdCode.setBackground(getResources().getDrawable(R.drawable.row_background1));
textProdCode.setTextColor(Color.BLACK);
textProdCode.setTextSize(18);
tr.addView(textProdCode);
String code = cursor.getString(cursor.getColumnIndex(COLUMN_PRODUCTS_CODE));
textProdCode.append(" " + code + "\n");
tr.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(order_det_v2.this, order_det_v2.class);
intent.putExtra("currentProduct", currentProductID);
startActivity(intent);
}
});
}
}