ListView不显示文本
我使用此代码来搜索列表并将它们添加到列表中(s 是 EditText):
if (s != null && s.toString().length() > 2) {
SearchDialogList.clear();
for (String tmp : mSuraNameList)
if (tmp.startsWith(s.getText().toString()))
SearchDialogList.add(tmp);
if (SearchDialogList.size() != 0) {
mSearchDialogAdapter = new ListView_StartQuranSearchDialog_Adapter(Start_Quran_List2.this, SearchDialogList);
listview.setAdapter(mSearchDialogAdapter);
}
}
适配器 GetView():
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView == null) {
convertView = mInflater.inflate(R.layout.readers_choice_custom_row, null); // line
// 47
holder = new ViewHolder();
holder.tv_ReadersNames = (TextView) convertView.findViewById(R.id.TextView_ReaderChoiceDownload);
convertView.setTag(holder);
} else
holder = (ViewHolder) convertView.getTag();
holder.tv_ReadersNames.setText(SuraList.get(position));
holder.tv_ReadersNames.setGravity(Gravity.RIGHT);
return convertView;
}
class ViewHolder {
TextView tv_ReadersNames;
}
xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="15dip">
<TextView
android:id="@+id/TextView_ReaderChoiceDownload"
android:textAppearance="?android:attr/textAppearanceLarge"
android:layout_height="wrap_content"
android:text="tes"
android:layout_width="wrap_content"
android:layout_alignParentRight="true"
android:padding="15dip"></TextView>
/>
List 不为空,为什么 ListView 不显示 List 中的项目?
I'm using this code to search through a List and add them to a List (s is an EditText):
if (s != null && s.toString().length() > 2) {
SearchDialogList.clear();
for (String tmp : mSuraNameList)
if (tmp.startsWith(s.getText().toString()))
SearchDialogList.add(tmp);
if (SearchDialogList.size() != 0) {
mSearchDialogAdapter = new ListView_StartQuranSearchDialog_Adapter(Start_Quran_List2.this, SearchDialogList);
listview.setAdapter(mSearchDialogAdapter);
}
}
The adapters GetView():
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView == null) {
convertView = mInflater.inflate(R.layout.readers_choice_custom_row, null); // line
// 47
holder = new ViewHolder();
holder.tv_ReadersNames = (TextView) convertView.findViewById(R.id.TextView_ReaderChoiceDownload);
convertView.setTag(holder);
} else
holder = (ViewHolder) convertView.getTag();
holder.tv_ReadersNames.setText(SuraList.get(position));
holder.tv_ReadersNames.setGravity(Gravity.RIGHT);
return convertView;
}
class ViewHolder {
TextView tv_ReadersNames;
}
the xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="15dip">
<TextView
android:id="@+id/TextView_ReaderChoiceDownload"
android:textAppearance="?android:attr/textAppearanceLarge"
android:layout_height="wrap_content"
android:text="tes"
android:layout_width="wrap_content"
android:layout_alignParentRight="true"
android:padding="15dip"></TextView>
/>
The List isnt empty, why does the ListView not show the items that are in the List?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
将
s.toString()
更改为s.getText().toString()
change the
s.toString()
withs.getText().toString()
您已在相对布局标签内给出了文本视图,
现在尝试一下。
you have given the textview inside relative layout tags
try it now.