Recyclerview içerisinde apiden gelen verileri listelemekte sorun yaşıyorum.
11.07.2021 - 05:42
Recyclerview içerisinde apiden gelen verileri listelemekte sorun yaşıyorum. Yardımcı olabilir misiniz?
Kodlarım aşağodaki gibidir;
public class MainActivity extends AppCompatActivity { public static String apikey = "123456789"; public static String lan = "55.5"; public static String lon="37.5"; public static String cnt="10"; private List<CountryData> list; SearchView searchView; RecyclerView countries; TextView countryName, temperature; ImageView image; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); searchView = (SearchView) findViewById(R.id.searchView); countries = (RecyclerView) findViewById(R.id.countries); countryName = (TextView) findViewById(R.id.countryName); temperature = (TextView) findViewById(R.id.temperature); image = (ImageView) findViewById(R.id.image); list = new ArrayList<>(); countries = findViewById(R.id.countries); countries.setLayoutManager(new LinearLayoutManager(this)); countries.setHasFixedSize(true); Adapter adapter = new Adapter(this, list); countries.setAdapter(adapter); ApiUtilities.getApiInterface().getCountryData(lan,lon,cnt,apikey).enqueue(new Callback<List<CountryData>>(){ @Override public void onResponse(Call<List<CountryData>> call, Response<List<CountryData>> response) { if (response.code() == 200) { RetrofitModel retrofitModel = (RetrofitModel) response.body(); assert retrofitModel != null; double temp = retrofitModel.main.temp - 273.15; int tempToInt = (int) temp; String country = retrofitModel.sys.country; for(int i=0; i<list.size(); i++){ countryName.setText(country); } String temperatures = tempToInt + "°C"; temperature.setText(temperatures); } } @Override public void onFailure(Call<List<CountryData>> call, Throwable t) { } }); } }
56
Görüntülenme
0 Beğeni