Friday, May 3, 2013

[android help] Wat is the best way to refresh a android's listview


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();
List allDevices = 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

Google Voice on T-Mobile? [General]

Google Voice on T-Mobile? So I recently switched from a GNex on Verizon to a Moto X DE on T-Mobile. I had always used Google Voice for my v...