How to refresh GridView? Below there is my code. After scanning, application make some updates into sqlite database, and at the end kill Activity. After application back to fragment with GridView, which is old without updates. Any help?
Scanning class:
@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();
}
Fragment class:
@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;
}
}