Android Studio中解析符號 'GET' 在onBindViewHolder
我得到錯誤不能在Recyclerview
「不能解析符號 '得到'
,也是getHead
和getDesc
不工作,雖然我在Listitem
類中創建了公共字符串。
我的Android Studio版本2.3.3是,
API級別爲22的是Android 5.1,
構建工具的版本是25.0.3。
package com.example.kanase.recyclerviewapp;
import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import java.util.List;
public class MyAdapter extends RecyclerView.Adapter<MyAdapter.ViewHolder> {
private List<Listitem> listItems;
private Context context;
public MyAdapter(List<Listitem> listItems, Context context) {
this.listItems = listItems;
this.context = context;
}
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View v = LayoutInflater.from(parent.getContext())
.inflate(R.layout.list_item , parent ,false);
return new ViewHolder(v);
}
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
Listitem listitem =new listItems.get(position);
holder.textViewHead.setText(listItems.getHead());
holder.textViewDesc.setText(listItems.getDesc());
}
@Override
public int getItemCount() {
return listItems.size();
}
public class ViewHolder extends RecyclerView.ViewHolder{
public TextView textViewHead;
public TextView textViewDesc;
public ViewHolder(View itemView) {
super(itemView);
textViewHead =(TextView) itemView.findViewById(R.id.textViewHead);
textViewDesc =(TextView) itemView.findViewById(R.id.textViewDesc);
}
}
這是列表項類:
package com.example.kanase.recyclerviewapp;
public class Listitem {
private String head;
private String desc;
public Listitem(String head, String desc) {
this.head = head;
this.desc = desc;
}
public String getHead() {
return head;
}
public String getDesc() {
return desc;
}
}
'new listItems.get' why'new'? 'listItems.getHead()'你爲什麼想從你的listItem ** s **中獲得'getHead'? –