我编写了一个代码,其目标是将数组列表项设置为回收视图。但是当我运行该项目时,应用程序将崩溃。
d.
我检查依赖关系。他们没事。我检查了代码,我认为它们没有任何问题。
//主活动类
public class MainActivity extends AppCompatActivity {
RecyclerView rcl_cities;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initViews();
Log.e("ApplicationSays:","LayoutManager set");
}
private void initViews(){
rcl_cities = findViewById(R.id.rcl_cities);
rcl_cities.setLayoutManager(new LinearLayoutManager(this,RecyclerView.VERTICAL,false));
CityAdapter cityAdapter = new CityAdapter(this,getCities());
rcl_cities.setAdapter(cityAdapter);
}
private ArrayList<City> getCities()
{
ArrayList<City> cities = new ArrayList<>();
cities.add(new City(1, "mashhad"));
cities.add(new City(2, "Tehran"));
cities.add(new City(3, "Gorgan"));
cities.add(new City(4, "Shiraz"));
cities.add(new City(5, "Rasht"));
return cities;
}
}
哔哔one
相关分类