Необходимо из xml по ссылку вывести данные в listview.
Все корректно выгружается в ArrayList list,
проблема именно в ListAdapter.
Код прилагаю
import android.app.ProgressDialog;
import android.os.AsyncTask;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.*;
import java.util.ArrayList;
import java.util.List;
public class MainActivity extends AppCompatActivity {
ProgressDialog progressDialog;
ArrayList<Valute> list = new ArrayList<>();
private ListView lv;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
lv = (ListView)findViewById(R.id.lv);
progressDialog = new ProgressDialog(this);
progressDialog.setMessage("Загрузка...");
progressDialog.setCancelable(false);
new Async().execute();
}
private List<String> name(){
List<String>list =new ArrayList<>();
return list;
}
private class Async extends AsyncTask<String, String, String>
{
@Override
protected void onPreExecute() {
super.onPreExecute();
progressDialog.show();
}
@Override
protected String doInBackground(String... strings){
try {
Document document = Jsoup.connect("https://www.cbr-xml-daily.ru/daily_utf8.xml")
.timeout(3000).followRedirects(true).ignoreContentType(true).userAgent("Mozilla")
.get();
Elements elements = document.select("Valute");
for(Element element: elements)
{
Valute valute = new Valute();
valute.setName(element.select("Name").text());
valute.setValue(element.select("Value").text());
list.add(valute);
}
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(String s) {
progressDialog.dismiss();
ListAdapter listAdapter = new ListAdapter(MainActivity.this,list);
lv.setAdapter(listAdapter);
}
}
}
ListAdapter.java
import android.content.Context;
import android.database.DataSetObserver;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import java.util.ArrayList;
public class ListAdapter extends BaseAdapter {
Context context;
ArrayList<Valute> list;
LayoutInflater layoutInflater;
ListAdapter(Context context,ArrayList<Valute> list){
this.context=context;
this.list =list;
// layoutInflater = LayoutInflater.from(context);
layoutInflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
@Override
public boolean areAllItemsEnabled() {
return false;
}
@Override
public boolean isEnabled(int i) {
return false;
}
@Override
public void registerDataSetObserver(DataSetObserver dataSetObserver) {
}
@Override
public void unregisterDataSetObserver(DataSetObserver dataSetObserver) {
}
@Override
public int getCount() {
return 0;
}
@Override
public Object getItem(int i) {
return null;
}
@Override
public long getItemId(int i) {
return 0;
}
@Override
public boolean hasStableIds() {
return false;
}
@Override
public View getView(int i, View view, ViewGroup viewGroup) {
return null;
}
@Override
public int getItemViewType(int i) {
return 0;
}
@Override
public int getViewTypeCount() {
return 0;
}
@Override
public boolean isEmpty() {
return false;
}
}