我在網頁上有一個網格視圖加載它填充。當我點擊它時,我有一個同步按鈕,它應該重新生成網格視圖。如何做到這一點。清除網格視圖並在android中重新生成
我使用
ImageAdapter adapter = new ImageAdapter(MainActivity.this); gridview.setAdapter(adapter);
代碼詳細
try {
if(stringArrayPdfUrlForLocalDB.length>0)
{
for(int i=0 ; i < stringArrayPdfUrlForLocalDB.length ; i++)
{
String fileName = getOnlyFileName(stringArrayPdfUrlForLocalDB[i]);
String imageName = getImageName(stringArrayPdfUrlForLocalDB[i]);
String BookId = stringArrayBookId[i];
//Toast.makeText(getApplicationContext(), "File Name: "+fileName+"\nBookId: "+BookId, Toast.LENGTH_LONG).show();
db.open();
long id = db.insertRecord(BookId, fileName + ".pdf", imageName);
db.close();
}
}
else
{
Toast.makeText(getApplicationContext(), "Not getting any book form server.", Toast.LENGTH_SHORT).show();
}
//populate grid view
ImageAdapter adapter = new ImageAdapter(MainActivity.this);
gridview.setAdapter(adapter);
} catch (Throwable e) {
Toast.makeText(getApplicationContext(), ""+e, Toast.LENGTH_SHORT).show();
}
在適配器上調用notifyDataSetChanged()。 – Raghunandan 2013-04-08 12:58:00
如何補充一點,在我的代碼示例 – Anirban 2013-04-08 13:01:16
您的適配器上添加notifyDataSetChanged()當你點擊同步按鈕 – Raghunandan 2013-04-08 13:05:44