暂停屏幕

时间:2013-08-02 04:34:12

标签: android database sqlite screen

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

这是我的代码:

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());

1 个答案:

答案 0 :(得分: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());