如何刷新GridView?下面是我的代碼。掃描完成後,應用程序將更新到sqlite數據庫中,並在最後kill Activity。應用程序返回到使用沒有更新的舊版GridView的片段。任何幫助?Sqlite更新後Android GridView刷新
掃描類:
@Override
public void handleResult(Result rawResult) {
// Do something with the result here
Employee employee_One = new Employee(BitmapFactory.decodeResource(
getResources(), R.drawable.test1), "abc", 1);
Log.v("TAG", rawResult.getText()); // Prints scan results
Log.v("TAG", rawResult.getBarcodeFormat().toString()); // Prints the scan format (qrcode, pdf417 etc.)
String message = rawResult.toString();
if(rawResult.toString().equals("8005603001555")) {
DbHelper = new DBhelper(this);
DbHelper.open();
DbHelper.insertEmpDetails(employee_One);
DbHelper.close();
finish();
} else {
mScannerView.startCamera();
Toast.makeText(getBaseContext(), "Fail" , Toast.LENGTH_LONG).show();
}
片段類:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_community, container, false);
button = (Button) rootView.findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
Intent i = new Intent(getActivity(), Scanning.class);
startActivity(i);
}
});
DbHelper = new DBhelper(getActivity());
DbHelper.open();
employeeList = DbHelper.retriveallEmpDetails();
DbHelper.close();
final GridView gridView = (GridView) rootView.findViewById(R.id.grid_view);
gridView.setAdapter(new ImageAdapter(getActivity(), employeeList));
return rootView;
}
}
有益它在哪裏(invalidateViews())應該正確地完成? – waclaw
您可以嘗試在操作結束的掃描類中使用。 – sanjeeb
它不起作用 – waclaw