【问题标题】:Android List View Data not Showing up In Production Mode APKAndroid 列表视图数据未在生产模式下显示 APK
【发布时间】:2017-07-05 02:56:14
【问题描述】:

我正在显示带有虚拟数据的课程列表。我正在使用自定义 布局以显示课程。从服务器获取对象列表。 在调试模式或运行应用程序时一切正常 在设备上。

现在当我为生产模式构建签名 APK 列表中的数据 没有出现。数据来自服务器,也是 成功映射到列表中。但它没有显示出来。

这是我的自定义布局文件的代码。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/tvCourseName"
    android:gravity="center"
    android:textSize="22sp"
    android:layout_marginStart="15dp"
    android:layout_marginEnd="15dp"
    android:layout_marginTop="5dp"
    android:layout_marginBottom="5dp"
    android:textColor="@color/main"
    android:background="@drawable/background_course_name"
    android:text="@string/english"/>
</RelativeLayout>

这是适配器的代码。

public View getView(int position, View convertView, ViewGroup parent) {

    LayoutInflater inflater = LayoutInflater.from(getContext());
    View view = inflater.inflate(R.layout.course_row_layout,parent,false);

    response = getItem(position);

    tvCourseName = (TextView)view.findViewById(R.id.tvCourseName);
    tvCourseName.setText(response.getTitle());

    return view;
}

【问题讨论】:

  • 也发布您的 logcat 和 gradle 文件以及颜色文件
  • 编辑您的问题并提供所需文件
  • 忘掉 getColor() 方法吧。我已经在布局文件中设置了它。我只是忘记在粘贴时评论它..这与颜色无关。运行或调试应用程序时一切正常。
  • 发布您的服务器数据,即您用于列表视图的数据

标签: android listview android-custom-view


【解决方案1】:

确保您的模型类使用了 Serializable 的实现,并且类中的每个属性都有 @SerializedName,例如:

data class ParcelCategory(
        @SerializedName("created_at")
        val createdAt: String,
        @SerializedName("created_at_jalali")
        val createdAtJalali: String,
        @SerializedName("description")
        val description: String,
        @SerializedName("id")
        val id: Int,
        @SerializedName("inside_pic")
        val insidePic: String,
        @SerializedName("inside_pic_app")
        val insidePicApp: String,
        @SerializedName("is_active")
        val isActive: Int,
        @SerializedName("logo")
        val logo: String,
        @SerializedName("logo_app")
        val logoApp: String,
        @SerializedName("title")
        val title: String,
        @SerializedName("updated_at")
        val updatedAt: String
) : Serializable

【讨论】:

    【解决方案2】:

    设置值为假

     release {
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            }
    

    【讨论】:

      【解决方案3】:

      如果您认为您没有更改源代码中的任何内容,并且仅在发布版本中发生,请检查您的 progaurd 文件。 在发布版本中尝试禁用 progaurd

      将 minifyEnabled false 放在 gradle 文件中,然后看看会发生什么。

      如果它是由 progaurd 引起的,请尽量避免混淆您的实体类或自定义视图

      【讨论】:

        猜你喜欢
        • 2018-03-05
        • 1970-01-01
        • 2016-10-05
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-12-20
        相关资源
        最近更新 更多