【问题标题】:Master/Detail flow ListView in Detail text Color is invisible详细文本中的主/从流ListView 颜色不可见
【发布时间】:2017-09-17 03:23:38
【问题描述】:

我有一个由 ADT 2.3.3 生成的 Master/Detail View Activity,我在 Detail Fragment onCreateView 上添加了一个 ListView,如下所示:

ListView myListView = (ListView)rootView.findViewById(R.id.customer_type_list);

final ArrayList<String> myFamily = new ArrayList<String>();
myFamily.add("Rob");
myFamily.add("Kirsten");
myFamily.add("Tommy");
myFamily.add("Ralphie");

ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(getContext(),
                android.R.layout.simple_list_item_1, 
                myFamily);

myListView.setAdapter(arrayAdapter);

列表视图显示在详细视图上,但所有项目的文本都不可见:

Result

我在thread 中发现,如果在适配器上发送了不正确的上下文但找不到正确的上下文,则可能会发生这种情况。

这是我的详细布局,以备不时之需:

<android.support.design.widget.CoordinatorLayout 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="mx.com.megcloud.placacentro.Home">

<android.support.constraint.ConstraintLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ListView
        android:id="@+id/customer_type_list"
        android:layout_width="1008dp"
        android:layout_height="wrap_content"
        android:layout_marginLeft="8dp"
        android:layout_marginRight="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/linearLayout" />

    <LinearLayout
        android:id="@+id/linearLayout"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="8dp"
        android:layout_marginTop="8dp"
        android:orientation="horizontal"
        android:paddingBottom="@dimen/activity_vertical_margin"
        android:paddingLeft="@dimen/activity_horizontal_margin"
        android:paddingRight="@dimen/activity_horizontal_margin"
        android:paddingTop="@dimen/activity_vertical_margin"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        tools:context="mx.com.megcloud.placacentro.Login"
        android:layout_marginStart="8dp">

        <EditText
            android:id="@+id/customer_type_te"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:ems="10"
            android:hint="Tipo de cliente"
            android:inputType="textPersonName" />

        <EditText
            android:id="@+id/percentage_te"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:ems="10"
            android:hint="% de comision"
            android:inputType="number" />

        <TextView
            android:id="@+id/textView2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="%"
            android:textSize="30sp" />

        <Button
            android:id="@+id/button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:onClick="addCustomerType"
            android:text="Agregar" />
    </LinearLayout>

</android.support.constraint.ConstraintLayout>

希望你能帮助我。

我正在使用 API 25

【问题讨论】:

  • 你设置了适配器吗?
  • @ZeekHuge 谢谢,我做到了。我刚刚将 setAdapter 部分添加到我的帖子中,所以它是完整的。
  • 你的意思是解决了问题?
  • @ZeekHuge 不幸的是,没有,我已经在我的代码中找到了它,但忘记在此处的帖子上复制它。
  • 尝试getActivity() 而不是getContext()

标签: android listview master-detail


【解决方案1】:

我刚刚找到答案,它与上下文无关。我意识到 ListView 上的线条继续向左移动,它们应该在到达侧面菜单之前结束几个像素。

我的 ListView 位于侧边菜单下方,因此文本似乎不可见,而实际上它一直都在那里。

我改变了我的 ListView 布局如下:

<ListView
        android:id="@+id/customer_type_list"
        android:layout_width="1008dp"
        android:layout_height="wrap_content"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"
        app:layout_constraintTop_toBottomOf="@+id/linearLayout"
        android:layout_marginLeft="8dp"
        app:layout_constraintLeft_toLeftOf="parent" />

现在与侧边菜单正确对齐。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-23
    • 2018-10-13
    • 1970-01-01
    • 1970-01-01
    • 2011-05-30
    相关资源
    最近更新 更多