Приложение запускается, но список остаётся пустым
public class MainActivity extends AppCompatActivity {
RecyclerView recyclerView;
private Document doc;
private Thread secThread; // второстепенный поток
private Runnable runnable;
private ListView listView;
private ArrayList<ListItemClass> arrayList;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
init();
}
private void init()
{
runnable = new Runnable() {
@Override
public void run() {
// getWeb();
refresh();
}
};
secThread = new Thread(runnable);
secThread.start();
recyclerView = (RecyclerView) findViewById(R.id.recycler_view);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
// ArrayList<ListItemClass> list = new ArrayList<>();
//list.add(new ListItemClass(arrayList, arrayList, arrayList));
MyAdapter adapter = new MyAdapter(arrayList);
recyclerView.setAdapter(adapter);
}
public void refresh(){
try {
doc = Jsoup.connect("https://yandex.ru/news/quotes/1.html").get();
Elements tables = doc.getElementsByTag("tbody");
Element our_table = tables.get(0);
Elements elements_from_table = our_table.children();
Element dollar = elements_from_table.get(0);
Elements dollar_elements = dollar.children();
Log.d("MyLog","Tbody size : " + our_table.children().get(0).text());
for(int i = 0;i < our_table.childrenSize();i++ )
{
ListItemClass items = new ListItemClass();
items.setData_1(our_table.children().get(i).child(0).text());
items.setData_2(our_table.children().get(i).child(1).text());
items.setData_3(our_table.children().get(i).child(2).text());
arrayList.add(items);
// Log.d("OneLog", list.get(0));
}
} catch (Exception ex){
}
}
}
адаптер:
public class MyAdapter extends RecyclerView.Adapter<MyAdapter.DataViewHolder>
{
ArrayList<ListItemClass> text;
public MyAdapter (ArrayList<ListItemClass> text){
this.text = text;
}
public class DataViewHolder extends RecyclerView.ViewHolder {
TextView mTextView;
TextView mTextView2;
TextView mTextView3;
public DataViewHolder(@NonNull View itemView) {
super(itemView);
mTextView = (TextView) itemView.findViewById(R.id.item);
mTextView2 = (TextView) itemView.findViewById(R.id.item2);
mTextView3 = (TextView) itemView.findViewById(R.id.item3);
}
}
@NonNull
@Override
public DataViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_item, parent, false);
return new DataViewHolder(view);
}
@Override
public void onBindViewHolder(@NonNull DataViewHolder holder, int position) {
holder.mTextView.setText(text.get(position).getData_1());
holder.mTextView2.setText(text.get(position).getData_2());
holder.mTextView3.setText(text.get(position).getData_3());
}
@Override
public int getItemCount() {
return text.size();
}
}
GitHub проекта: https://github.com/Nikolui333/DollarRate