I simplified my code to make it more understandable. I am reading some data from a database and insert in Table Rows. Since there are thousands of entries it takes time to load and freezes the UI. What I want is to move the process in a Fragment, changing the SQL query to load only 100 entries every time. I want this fragment to be added to the end of the activity every time we reach the end of the scroll. Is that possible to easily implement?
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);
}
});
}
}