I have a listview that retrieves items from MySQL and displays it, my problem is that I don't know how to refresh this listview every certain time with the new updated values in MySQL tables
Here is my code
public class Hospital_Reply extends Activity implements
DownloadResultReceiver.Receiver {
private DownloadResultReceiver mReceiver;
List<Hos> hoses;
String carNumber;
private GoogleApiClient client;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_hospital__reply);
Bundle bundle = this.getIntent().getExtras();
carNumber = bundle.getString("carNumber");
String url =url = "http://192.168.1.102/final/notification/read.php";
if (true) {
mReceiver = new DownloadResultReceiver(new Handler());
mReceiver.setReceiver(this);
Intent intent = new Intent(Intent.ACTION_SYNC, null, this,
DownloadService.class);
intent.putExtra("url", url);
String data = null;
try {
data = URLEncoder.encode("carNumber", "UTF-8") + "=" + URLEncoder.encode(carNumber, "UTF-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
intent.putExtra("data", data);
intent.putExtra("receiver", mReceiver);
intent.putExtra("requestId", 101);
startService(intent);
} else {
new AlertDialog.Builder(Hospital_Reply.this)
.setTitle("Oops")
.setMessage("No Internet Connection!")
.setPositiveButton("Ok",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
}
}).show();
}
client = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build();
}
@Override
public void onStart() {
super.onStart();
client.connect();
Action viewAction = Action.newAction(
Action.TYPE_VIEW, "Car Page", Uri.parse("http://host/path"),
Uri.parse("android-app://com.example.khloud.qery/http/host/path")
);
AppIndex.AppIndexApi.start(client, viewAction);
}
@Override
public void onStop() {
super.onStop();
Action viewAction = Action.newAction(
Action.TYPE_VIEW, "Car Page", Uri.parse("http://host/path"),
Uri.parse("android-app://com.example.khloud.qery/http/host/path")
);
AppIndex.AppIndexApi.end(client, viewAction);
client.disconnect();
}
@Override
public void onReceiveResult(int resultCode, Bundle resultData) {
switch (resultCode) {
case DownloadService.STATUS_RUNNING:
break;
case DownloadService.STATUS_FINISHED:
String response = resultData.getString("result");
if (response == null)
Log.d("respooo", "null");
intializeProcess(response);
break;
case DownloadService.STATUS_ERROR:
String error = resultData.getString("error");
Log.d("error", error);
break;
}
}
private void intializeProcess(String response) {
Log.d("response", response);
ItemsRetrieval_hos itemRetrieval = new ItemsRetrieval_hos();
if (itemRetrieval.GetMainAPI(response)) {
hoses = itemRetrieval.getItems();
Log.e("Items Size", hoses.size() + "");
doWork();
}
}
private void doWork() {
populateListView();
registerClickCallback();
}
private void populateListView() {
ArrayAdapter<Hos> adapter = new MyListAdapter(this,hoses);
ListView list = (ListView) findViewById(R.id.items);
list.setAdapter(adapter);
}
private void registerClickCallback() {
ListView list = (ListView) findViewById(R.id.items);
list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(final AdapterView<?> parent, View viewClicked,
final int position, long id) {
}
});
}
public class MyListAdapter extends ArrayAdapter<Hos> {
public List<Hos> appInfoList;
private Context ctx;
private LayoutInflater mInflater;
public MyListAdapter(Context context, List<Hos> myList) {
super(context, NO_SELECTION);
this.appInfoList = myList;
this.ctx=context;
mInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
@Override
public int getCount() {
return appInfoList.size();
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) ctx.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.single_row_reply, null);
TextView textView = (TextView) convertView.findViewById(R.id.textView);
final Hos item = hoses.get(position);
textView.setText(item.getName());
return convertView;
}
}
@Override
protected void onResume() {
super.onResume();
this.onCreate(null);
}
}