0

我需要暂停我的屏幕一段时间,因为我有一个要显示的数据库.....我将每行的数据库显示为一个 xml 布局......问题是 xml 布局总是显示我的数据库的最底部.. .这就是为什么我相信如果我可以停止屏幕一段时间我将能够从布局中看到另一行......

这是我的代码:

public void get() {
    Bundle bundle = getIntent().getExtras();
    String count = bundle.getString("x");
    //Toast.makeText(getApplicationContext(), count, Toast.LENGTH_SHORT).show();
    db = new DBAdapter(this);
    db.open();
    Cursor z = db.getAllList();
        if (z.moveToFirst())
        {
            do {
                DisplayList(z,count);
            } while (z.moveToNext());
        }
        db.close();
}

public void DisplayList(Cursor z, String count) {
    String b = z.getString(1);
    if (count.equals(b)) {
        /*Toast.makeText(this,
                "Id      : " + z.getString(0) + "\n" +
                "Product : " + z.getString(1) + "\n" +
                "Brand   : " + z.getString(2) + "\n" +
                "Place   : " + z.getString(3) + "\n" +
                "Date    : " + z.getString(4) + "\n" +
                "Price   : Rp. " + z.getString(5),
                Toast.LENGTH_LONG).show();*/
        TextView X = (TextView) findViewById(R.id.a); 
        TextView Y = (TextView) findViewById(R.id.b); 
        TextView Z = (TextView) findViewById(R.id.c); 
        TextView A = (TextView) findViewById(R.id.d); 
        TextView B = (TextView) findViewById(R.id.e);  
        String a = z.getString(1);
        String f = z.getString(2);
        String c = z.getString(3);
        String d = z.getString(4);
        String e = z.getString(5);
        X.setText("Product     : " + a);
        Y.setText("Brand        : " + f);
        Z.setText("Bought at  : " + c);
        A.setText("Date          : " + d);
        B.setText("Price         : Rp. " + e);
    }
}

我的计划是在显示列表之后暂停:

do {
DisplayList(z,count);
    //here
} while (z.moveToNext());

有任何想法吗 ???我试过thread.sleep但没用......

像这样 :

do {
DisplayList(z,count);
    try {Thread.sleep(1000);
            } catch (InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
} while (z.moveToNext());
4

1 回答 1

1

尝试这个。它可能会起作用。

do {
        Thread myThread = new Thread() 
        @Override
        public void run() {
            try {
                    super.run();
                    sleep(3000)  //Delay of 3 seconds
                } catch (Exception e) {
                    System.out.println(e.getLocalizedMessage();
                } finally {
                      DisplayList(z,count);
                }
            }
        };
        myThread.start();
   } while (z.moveToNext());
于 2013-08-02T04:55:01.517 回答