0

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);
            }
        });
    }
}
Cœur
  • 37,241
  • 25
  • 195
  • 267
user2315641
  • 161
  • 3
  • 15
  • This is wrong practice bro. Just use Listview for smoother loading. Even there is lacks of entries Listview will handle properly – Biraj Zalavadia Oct 13 '14 at 12:13
  • @BirajZalavadia I simplified my code, but I need add different data to a row, so a list view is not possible. – user2315641 Oct 13 '14 at 12:52
  • why not possible? Who told you that you can not add different data to row in listview – Biraj Zalavadia Oct 13 '14 at 12:55
  • @BirajZalavadia I just read this answer: http://stackoverflow.com/questions/5757083/does-android-have-a-table-like-adapter-for-listview. I thought it concerned my problem. I am new to Android development and can't understand some concepts. – user2315641 Oct 13 '14 at 12:59

0 Answers0