For some reason, the actual data from the JSON file that I pull from the RBC site is not displayed. Created a class in MainActivity:
private class GetRbcExchangeRates extends AsyncTask<String, String, String> { public ArrayList<CurrencyRateModel> listOfCurrency = new ArrayList<>(); private final String httpAddress = "https://www.cbr-xml-daily.ru/daily_json.js"; @Override protected String doInBackground(String... params) { HttpURLConnection connection = null; BufferedReader bufferedReader = null; StringBuilder jSonResult = new StringBuilder(); //listOfCurrency = new ArrayList<>(); try { URL url = new URL(httpAddress); connection = (HttpURLConnection)url.openConnection(); connection.connect(); bufferedReader = new BufferedReader(new InputStreamReader(connection.getInputStream())); String line = ""; while((line = bufferedReader.readLine()) != null) { jSonResult.append(line); } } catch(Exception e) { e.printStackTrace(); publishProgress("MESSAGE", "ΠΡΡΡΡΡΡΠ²ΡΠ΅Ρ ΠΏΠΎΠ΄ΠΊΠ»ΡΡΠ΅Π½ΠΈΠ΅ ΠΊ ΠΈΠ½ΡΠ΅ΡΠ½Π΅Ρ!"); } finally { if(connection != null) connection.disconnect(); try { if(bufferedReader !=null) bufferedReader.close(); } catch(IOException e) { e.printStackTrace(); } } try { JSONObject rbcGETRates = new JSONObject(jSonResult.toString()); JSONObject jSonValute = rbcGETRates.getJSONObject("Valute"); Iterator<String> arrayKey = jSonValute.keys(); while(arrayKey.hasNext()) { String key = arrayKey.next(); JSONObject jSonItem = jSonValute.getJSONObject(key); CurrencyRateModel currencyitems = new CurrencyRateModel(); currencyitems.id = jSonItem.getString("ID"); currencyitems.nameCode = jSonItem.getString("NumCode"); currencyitems.charCode = jSonItem.getString("CharCode"); currencyitems.nominal = jSonItem.getInt("Nominal"); currencyitems.name = jSonItem.getString("Name"); currencyitems.value = jSonItem.getDouble("Value"); currencyitems.previous = jSonItem.getDouble("Previous"); listOfCurrency.add(currencyitems); } } catch (JSONException e) { e.printStackTrace(); } return null; } @Override protected void onPreExecute() { super.onPreExecute(); ListView lsView = (ListView)findViewById(R.id.currencyView); MyAdapter myAdapter = new MyAdapter(MainActivity.this, listOfCurrency); lsView.setAdapter(myAdapter); } @Override protected void onProgressUpdate(String... values) { super.onProgressUpdate(values); if(values[0].equals("MESSAGE")) { Toast.makeText(MainActivity.this, values[1], Toast.LENGTH_LONG).show(); } } @Override protected void onPostExecute(String s) { super.onPostExecute(s); } } Class - Model with fields:
public class CurrencyRateModel { public String id; public String nameCode; public String charCode; public int nominal; public String name; double value; double previous; }
And adapter:
public class MyAdapter extends BaseAdapter { private Context ctx; private ArrayList<CurrencyRateModel> arrayList; private LayoutInflater inflater; public MyAdapter(Context ctx, ArrayList<CurrencyRateModel> arrayList) { this.ctx = ctx; this.arrayList = arrayList; inflater = ((Activity)ctx).getLayoutInflater(); } @Override public int getCount() { return arrayList.size(); } @Override public Object getItem(int position) { return null; } @Override public long getItemId(int position) { return position; } @Override public View getView(int position, View convertView, ViewGroup parent) { ViewHolder vh; if(convertView == null) { vh = new ViewHolder(); convertView = inflater.inflate(R.layout.itemcurrency, null); vh.tvTitle = (TextView)convertView.findViewById(R.id.title); vh.tvDescription = (TextView)convertView.findViewById(R.id.description); convertView.setTag(vh); } else { vh = (ViewHolder) convertView.getTag(); vh.tvTitle.setText("1"); vh.tvDescription.setText("2"); } return convertView; } static class ViewHolder { TextView tvTitle, tvDescription; } }
In the onCreate method, I do this:
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // async TASK Run GetRbcExchangeRates async = new GetRbcExchangeRates(); async.execute(); } Also created a separate resource file c 2 TextView:
<TextView android:id="@+id/title" android:layout_width="match_parent" android:layout_height="wrap_content" android:textSize="22sp"/> <TextView android:id="@+id/description" android:layout_width="match_parent" android:layout_height="wrap_content" android:textSize="18sp" android:textColor="#555"/> I make debugging on a tablet with Lollipop 5.1. When you start the void, if you turn the application, and then deploy it again, the numbers 1 and 2 are written in the ListView (which is in the adapter in the else block); When debugging, you can see that valid parsed data from the site is written to the data structure, which is a problem in displaying the data. I brought to the log:
What am I doing wrong. I would be grateful for any help, as I have been feeling this platform for only a couple of weeks.

onPreExecutetoonPostExecuteand add the fourth line:myAdapter.notifyDataSetChanged(). - post_zeewconvertView = inflater.inflate(R.layout.itemcurrency, null); vh.tvTitle = (TextView)convertView.findViewById(R.id.title); vh.tvDescription = (TextView)convertView.findViewById(R.id.description); convertView.setTag(vh);convertView = inflater.inflate(R.layout.itemcurrency, null); vh.tvTitle = (TextView)convertView.findViewById(R.id.title); vh.tvDescription = (TextView)convertView.findViewById(R.id.description); convertView.setTag(vh);- JDosetText()method), nothing happens in the first block except caching, no data is output there and not even present, why do you think something is pulling from JSON? - pavlofff