ListView不显示文本

时间:2011-10-21 10:55:06

标签: android listview

我正在使用此代码搜索List并将它们添加到List(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>
/>

列表不为空,为什么ListView不显示列表中的项目?

2 个答案:

答案 0 :(得分:0)

使用s.toString()

更改s.getText().toString()

答案 1 :(得分:0)

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

您已在相对布局标记内提供了textview

现在试试。