I want to refresh the listView after an insert or delete in the database.. I search and i found notifyDataSetChanged () but i don't know how to use it..
I used AsyncTask to get the data from the server and insert it into the SQLite database. The problem is, the AsyncTask class is in a another file. So how can i access the adapter or the listview from the AsyncTask class?
Someone can explain how to do this? Even by a different way..
Here is my code...
public class devicesController extends SherlockFragment {
devicesDataSource deviceDS;
static devicesAdapter adapter;
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){
View view = inflater.inflate(R.layout.devices, container, false);
/// Set device's datasource
deviceDS = new devicesDataSource(getActivity());
/// Assign the listview from the xml layout
ListView lv1 = (ListView) view.findViewById(R.id.devicesList);
/// Getting all devices from the SQLite database
deviceDS.open();
ListallDevices = null;
try {
allDevices = deviceDS.getAll();
} catch (ParseException e) {
e.printStackTrace();
Log.i("QUTAYBA", "ERROR showing data");
}
/// Set the results rows in a list adapter
adapter = new devicesAdapter(getActivity(), R.layout.devices_list, allDevices);
lv1.setAdapter(adapter);
return view;
}
.
stackoverflow.comm
No comments:
Post a Comment