【发布时间】:2017-01-23 17:27:38
【问题描述】:
我收到以下错误:
android.content.res.Resources$NotFoundException: String resource ID #0x0
我只是使用RecyclerView 创建一个号码列表:
import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
public class SongRVAdapter extends RecyclerView.Adapter<SongViewHolder> {
private Context context;
public SongRVAdapter(Context context) {
this.context = context;
}
@Override
public SongViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = inflater.inflate(R.layout.song_info_row, parent, false);
return new SongViewHolder(view);
}
@Override
public void onBindViewHolder(SongViewHolder holder, int position) {
Log.d("CodeKamp", "onBindViewHolder called for position " + position);
holder.titleTextView.setText(position);
holder.durationTextView.setText("00:" + position);
}
@Override
public int getItemCount() {
return 10;
}
}
【问题讨论】:
-
以 int 作为参数询问了无数次
TextView.setText需要现有的字符串资源 id ...您传递的 0 不是有效的字符串资源 id ...
标签: android android-recyclerview