2013-04-13 100 views
1

我有一個網格視圖onCreate我正在創建一個網格視圖從本地數據庫獲取圖像URL但是當該活動加載它顯示一個白色的屏幕。網格視圖花費時間加載

如何刪除白色屏幕我不知道在哪裏移動此gredview.A附加完整的代碼請告訴我該怎麼做。嘗試點擊同步按鈕,同步按鈕將首先清除本地數據庫那麼它會從服務器獲取所有xml值,並將其放到本地數據庫中,然後該活動將重新啓動,然後調用此onCreat方法並顯示空白屏幕。

CODE URL http://www.fileconvoy.com/dfl.php?id=g2561f0a6e7dcc50b9992656609078e5c6d63c814c

我的代碼如下

@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 

    gridview = (GridView) findViewById(R.id.gridview); 
    gridview.setOnItemClickListener(new OnItemClickListener() { 

     public void onItemClick(AdapterView<?> parent, View v, int position, long id) 
     { 
      String pdfPath = Environment.getExternalStorageDirectory().toString() + "/ICA Faculty/"; 
      Toast.makeText(getApplicationContext(),pdfPath+((TextView) v.findViewById(R.id.hiddenPdfUrl)).getText(), Toast.LENGTH_SHORT).show(); 

      try { 
       File file = new File(pdfPath+((TextView) v.findViewById(R.id.hiddenPdfUrl)).getText()); 
       Uri path = Uri.fromFile(file); 
       Intent intent = new Intent(Intent.ACTION_VIEW); 
       intent.setDataAndType(path, "application/pdf"); 
       intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 
       startActivity(intent); 
      } catch (Exception e) { 
       Toast.makeText(getApplicationContext(),"Sorry no PDF reader found.", Toast.LENGTH_SHORT).show(); 
      } 
     } 
    }); 

    File folder = new File(Environment.getExternalStorageDirectory() + "/ICA Faculty"); 

    db.open(); 
    c = db.getAllRecords(); 

    //If data exist in local database AND "ICA Faculty" folder exist 
    //Getting the sd card file name from local database 
    if (c.moveToFirst() && folder.exists() && folder.listFiles() != null) 
    { 
     //This array list will help to create image 
     imgUrl = new ArrayList<String>(); 
     pdfUrl = new ArrayList<String>(); 
       do 

        imgUrl.add(c.getString(3)); 
        pdfUrl.add(c.getString(2)); 

       } while (c.moveToNext()); 

       ImageAdapter adapter = new ImageAdapter(MainActivity.this); 
       gridview.setAdapter(adapter); 
    } 
    else 
    { 
     Toast.makeText(getApplicationContext(), "You need to sync to create your library.", Toast.LENGTH_LONG).show(); 
    } 
    db.close(); 
} 

回答

1

GridView,作爲AdapterView亞類中,可以使用一個空視圖顯示當存在由setEmptyView()方法沒有數據。

對於實例看這個問題Correct use of setEmtpyView in AdapterView

+0

什麼都要伊賽特內setEmptyView(?????) – Anirban

+0

要顯示當沒有數據 – gipi

+0

仍然沒有工作 – Anirban

相關問題