ListView不显示文本

发布于 2024-12-11 13:50:31 字数 2084 浏览 0 评论 0原文

我使用此代码来搜索列表并将它们添加到列表中(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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

柠栀 2024-12-18 13:50:31

s.toString() 更改为 s.getText().toString()

change the s.toString() with s.getText().toString()

迷乱花海 2024-12-18 13:50:31
<?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>

</RelativeLayout>

您已在相对布局标签内给出了文本视图,

现在尝试一下。

<?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>

</RelativeLayout>

you have given the textview inside relative layout tags

try it now.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文