Android ListView 在滚动时切断列表中字符串的末尾
我使用来自不同地方的一些示例代码编写了一个ListView,尽管适配器的动态设置正在工作,但由于某种原因,当我滚动到不同的位置时,列表中字符串的末尾会神奇地消失。这是为什么呢?适配器的代码是这样的: 另外,列表 xml 只是标准列表视图,没有子级。子项是由该适配器添加的。
package com.vrise.bellarmine;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
class EfficientAdapter extends BaseAdapter {
private LayoutInflater mInflater;
private String[] gradesName;
private String[] gradesVal;
public EfficientAdapter(Context context, String[] gradesname, String[] gradesval) {
mInflater = LayoutInflater.from(context);
gradesName = gradesname;
gradesVal = gradesval;
}
public int getCount() {
return gradesName.length;
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView == null) {
convertView = mInflater.inflate(R.layout.row, null);
holder = new ViewHolder();
holder.text1 = (TextView) convertView
.findViewById(R.id.TextView01);
holder.text2 = (TextView) convertView
.findViewById(R.id.TextView02);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.text1.setText(gradesName[position]);
holder.text2.setText(gradesVal[position]);
return convertView;
}
static class ViewHolder {
TextView text1;
TextView text2;
}
}
另外,由于某种原因,我无法添加图片。 但它看起来是这样的:列表正在滚动,当我向上滚动时,开始的“Calculus AB AP”现在是“Calcu”。
I wrote a ListView using some sample code from different places, and although the dynamic setting of the Adapter is working, for some reason, when I scroll to a different position, the ends of the strings in the list will magically dissappear. Why is this? The code for the adapter is this: Also, the list xml is just standard listview with no children. The children are added by this adapter.
package com.vrise.bellarmine;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
class EfficientAdapter extends BaseAdapter {
private LayoutInflater mInflater;
private String[] gradesName;
private String[] gradesVal;
public EfficientAdapter(Context context, String[] gradesname, String[] gradesval) {
mInflater = LayoutInflater.from(context);
gradesName = gradesname;
gradesVal = gradesval;
}
public int getCount() {
return gradesName.length;
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView == null) {
convertView = mInflater.inflate(R.layout.row, null);
holder = new ViewHolder();
holder.text1 = (TextView) convertView
.findViewById(R.id.TextView01);
holder.text2 = (TextView) convertView
.findViewById(R.id.TextView02);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.text1.setText(gradesName[position]);
holder.text2.setText(gradesVal[position]);
return convertView;
}
static class ViewHolder {
TextView text1;
TextView text2;
}
}
Also I for some reason can't add pics.
But what it looks like is: The list is scrolling, and when I scroll back up, what started out as "Calculus AB AP" is now "Calcu".
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论