123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- package com.example.mytest;
- import android.app.Activity;
- import android.graphics.Color;
- import android.os.Bundle;
- import android.view.View;
- import android.widget.Button;
- import android.widget.LinearLayout;
- import android.widget.TextView;
- import org.json.JSONArray;
- import org.json.JSONObject;
- public class MainActivity extends Activity implements Interface {
- private Interface context;
- @Override
- public void Main(final JSONArray array) {
- runOnUiThread(new Runnable() {
- @Override
- public void run() {
- LinearLayout news = findViewById(R.id.newContainer);
- try {
- for (int i = 0; i < array.length(); i++) {
- JSONObject o = array.getJSONObject(i);
- TextView caption = new TextView(getApplicationContext());
- if (o.has("Caption")) {
- caption.setText(o.getString("Caption"));
- caption.setPadding(0, 20, 0, 20);
- caption.setTextColor(Color.RED);
- news.addView(caption);
- }
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- });
- }
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- context = this;
- Button button = findViewById(R.id.button);
- button.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- API api = new API();
- api.url = "https:/ktk-45.ru/news";
- api.param = "{\"Page\": 0,\"Limit\": 10}";
- api.context = context;
- api.start();
- }
- });
- }
- }
|