I want to create an online queue monitoring application which it will show the new data entered to the database.The UI sample is below
I want the Current Serving Ticket to update every second if there is a new data entered(Json
).
Here the MainActivity.java
public class MainActivity extends AppCompatActivity {
public static TextView data;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button input_number = (Button) findViewById(R.id.button2);
Button reminder = (Button) findViewById(R.id.button);
final TextView userinputtext = (TextView) findViewById(R.id.textView6);
data = (TextView)findViewById(R.id.textView10);
Here is the data.java that i created.
public class data extends AsyncTask<Void,Void,Void> {
String data=" ";
String singleParsed = " ";
@Override
protected Void doInBackground(Void... voids) {
try {
URL url = new URL("url/SamplePage.php");
HttpURLConnection httpURLConnection=(HttpURLConnection) url.openConnection();
InputStream inputStream = httpURLConnection.getInputStream();
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
String line ="";
while(line!=null){
line = bufferedReader.readLine();
data = data + line;
}
JSONArray JA = new JSONArray(data);
for (int i =0; i<JA.length();i++){
JSONObject JO = (JSONObject) JA.get(i);
singleParsed = JO.get("ticket_number")+"";
//dataParsed = dataParsed + singleParsed;
}
}catch (MalformedURLException e){
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}catch (JSONException e){
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(Void aVoid) {
super.onPostExecute(aVoid);
MainActivity.data.setText(this.singleParsed);
}
}
If there is any comment or help I would appreciate. Thanks.