如何在 ListView 的项目中显示大字符串?

How to display big string in ListView's items?

我正在将我的数据从 fire-base 获取到列表视图中,但是我获取的字符串相当长并且 android 中的 listView 似乎不支持多行。
这是我的数据库的样子:
布局文件是:

RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".usersMessage">

    <ListView
        android:id="@+id/listView"
        android:layout_width="match_parent"
        android:singleLine="true"
        android:layout_height="match_parent"></ListView>
</RelativeLayout>

这就是我在 .java 文件中获取数据的方式

myRef = FirebaseDatabase.getInstance().getReference().child("AdminMessages");
    mListView=(ListView) findViewById(R.id.listView);
    adapter=new ArrayAdapter<String>(this,android.R.layout.simple_dropdown_item_1line,list);
    mListView.setAdapter(adapter);



    myRef.addChildEventListener(new ChildEventListener() {
        @Override
        public void onChildAdded(DataSnapshot dataSnapshot, String s) {
            String value=dataSnapshot.getValue(String.class);

            list.add(value);
            adapter.notifyDataSetChanged();
        }

这就是数据在 listView 中的显示方式:

您需要将这两行添加到 TextView 中的 item.xml

android:singleLine="true"
android:ellipsize="end"

在您的 layouts folder 中创建一个 .xml 文件。假设文件名为 abc.xml 并且其布局类似于:

    <?xml version="1.0" encoding="utf-8"?>
<Edittext xmlns:android="http://schemas.android.com/apk/res/android"
          android:id="@android:id/text1"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:background="@color/white_color"
          android:drawablePadding="10dp"
          android:gravity="start"
          android:paddingLeft="5dp"
          android:paddingRight="5dp"
          android:paddingTop="2.5dp"
          android:textAppearance="?android:textAppearanceSmall"
          android:textColor="@color/black_color"
          android:textStyle="normal"/>

现在在您的代码中将 android.R.layout.simple_dropdown_item_1line 替换为 abc.xml

将这些行替换为:

adapter=new ArrayAdapter<String>(this,android.R.layout.simple_dropdown_item_1line,list);
mListView.setAdapter(adapter);

这个:

  adapter=new ArrayAdapter<String>(this,R.layout.abc,list);
mListView.setAdapter(adapter);