java, javafx, android and spring programing collection
java standard edition
addObject
arraylist
bufferedreader
colors
comparator
createTable
datatypes
date
enum
generateHTML
hashmap
inheritance
insertSQL
interface
JSONfromWEB
jsoup
list
loop
pointMatrix
queue
readCSV
regex
sqlToObject
stack
static
super
treemap
updateTable
writeCSV
java FX
3DCharacterMoving
3DMaterialList
DroneMotor
FlowPane
Hello
KeyCode
KeyMovement
ObservableList
Pane
RotateImage
rotateSphere
android
APIview
listview
ToastTimer
touchMovement
WriteReadFile
spring framework
HelloWorld
RESTful
TomcatServlet
java objects
Apple
starseite
/
lessons
/
se
fx
android
spring
/
star wars api
touchMovement
2022-06-17 07:51:32
tags:
android
transition
view source
WriteReadFile
2022-06-17 07:51:21
tags:
android
file
view source
ToastTimer
2022-06-17 07:51:17
tags:
android
toast
view source
APIview
2022-06-14 16:45:14
tags:
android
view source
listview
2022-06-14 16:45:06
tags:
android
view source
APIview
screenshot
description
source code
import android.widget.*; import androidx.appcompat.app.AppCompatActivity; import android.os.Bundle; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.net.HttpURLConnection; import java.net.URL; import java.util.LinkedList; import java.util.List; public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); LinearLayout layout = new LinearLayout(this); layout.setOrientation(LinearLayout.VERTICAL); ScrollView scrollView = new ScrollView(this); for (Character item : getObjectList()) { Button buttonName = new Button(this); buttonName.setText(item.getName()); System.out.println(item.getName()); layout.addView(buttonName); } scrollView.addView(layout); setContentView(scrollView); } public List
getObjectList() { List
characterList = new LinkedList
(); new Thread(new Runnable() { public void run() { String json = ""; try { URL url = new URL("https://cybershit.io/api/service.php?info=allcharacter"); HttpURLConnection con = (HttpURLConnection) url.openConnection(); InputStream inputStream = con.getInputStream(); try(BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream))) { json = reader.readLine(); } } catch (IOException e) { e.printStackTrace(); } JSONArray jsonArray = null; try { jsonArray = new JSONArray(json); } catch (JSONException e) { throw new RuntimeException(e); } int i = 0; JSONObject o = null; while (i <= jsonArray.length()-1) { try { o = jsonArray.getJSONObject(i); } catch (JSONException e) { throw new RuntimeException(e); } try { characterList.add(new Character(o.getString("name"))); } catch (JSONException e) {throw new RuntimeException(e); } i++; } } }).start(); try { Thread.sleep(5000); } catch(InterruptedException ex) {} return characterList; } } class Character { String name; Character(String name) { this.name = name; } public String getName() { return name; } }