1

我在 onCreate 上有一个网格视图我正在创建一个网格视图,从本地数据库获取图像 url 但是当加载该活动时,它显示一个白屏。

如何删除那个白屏我不知道把这个 gredview 移到哪里。我附上了完整的代码,请告诉我应该怎么做。尝试单击同步按钮,同步按钮将首先清除本地数据库,然后它得到所有从服务器获取 xml 值并将其放入本地数据库之后,此活动将重新启动,然后将调用此 onCreat 方法并显示空白屏幕。

代码网址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();
}
4

1 回答 1

1

作为的GridView子类AdapterView,可以使用空视图来显示该方法没有数据时setEmptyView()

例如看这个问题Correct use of setEmtpyView in AdapterView

于 2013-04-13T08:45:34.283 回答