我在onCreate上有一个网格视图我正在创建一个网格视图,从本地数据库获取图像URL但当该活动加载时显示白屏。
如何删除那个白色屏幕我不知道在哪里移动这个gredview.A是附件的完整代码请告诉我该怎么办。尝试点击同步按钮,同步按钮将首先清除本地数据库然后它从服务器获取所有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();
}
答案 0 :(得分:1)
GridView
作为AdapterView
的子类,可以使用空视图来显示setEmptyView()
方法何时没有数据。