所以我试图在我的代码中访问 getResources(),但由于某种原因,它不断收到未解析的引用。我正在另一个类中为我的阵列适配器执行此操作。是因为我没有 main 方法还是因为其他原因?总的来说,我对 android dev 和 kotlin 有点陌生,所以任何帮助都将不胜感激。
class ForecastAdapter(val forecast: Forecast) : RecyclerView.Adapter<ForecastData>(){
override fun getItemCount(): Int {
return forecast.list.count()
}
override fun onCreateViewHolder(p0: ViewGroup, p1: Int): ForecastData {
val layoutInflator = LayoutInflater.from(p0?.context)
val cellForRow = layoutInflator.inflate(R.layout.weather_row, p0, false)
return ForecastData(cellForRow)
}
override fun onBindViewHolder(p0: ForecastData, p1: Int) {
val drawableId: Int = getResources().getIdentifier("my_drawable", "drawable", getPackageName())
val getWeather = forecast.list[p1]
val clouds = getWeather.weather[0]
val getDateTime = forecast.list[p1]
var getIcon = forecast.list[p1]
var icon = getIcon.weather[0]
p0.view.textView_text_clouds.text = …Run Code Online (Sandbox Code Playgroud)所以我有一个listview从基于Room的SQLite数据库中提取数据.它看起来很好地读取数据,但是当页面加载时我会得到前10个条目(显示的大小),当我尝试向下滚动列表视图时,它会重新开始并开始获取条目在列表的开头再次.屏幕截图上的红色圆圈显示了列表的顶部和底部以及存在的重复.
public class NeighborhoodListAdapter
extends ArrayAdapter<LivingCity> {
private List<LivingCity> neighborhood;
Context context;
// View lookup cache
private static class ViewHolder {
TextView cityName;
}
public NeighborhoodListAdapter(List<LivingCity> neighborhood, Context context) {
super(context, R.layout.object_main_citydetailsrow, neighborhood);
this.context = context;
this.neighborhood = neighborhood;
}
@NonNull
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// Get the data item for this position
LivingCity city = getItem(position);
ViewHolder viewHolder;
if (convertView == null) {
viewHolder = new ViewHolder();
LayoutInflater inflater = LayoutInflater.from(getContext());
convertView = …Run Code Online (Sandbox Code Playgroud)