【问题标题】:android error in listview列表视图中的android错误
【发布时间】:2014-12-05 22:42:26
【问题描述】:

    <?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:background="@drawable/list_row_selector"
    android:padding="8dp" >
 
    <!-- Thumbnail Image -->
    <com.android.volley.toolbox.NetworkImageView
        android:id="@+id/thumbnail"
        android:layout_width="80dp"
        android:layout_height="80dp"
        android:layout_alignParentLeft="true"
        android:layout_marginRight="8dp" />
 
    <!-- Movie Title -->
    <TextView
        android:id="@+id/title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignTop="@+id/thumbnail"
        android:layout_toRightOf="@+id/thumbnail"
        android:textSize="@dimen/title"
        android:textStyle="bold" />
 
    <!-- Rating -->
    <TextView
        android:id="@+id/rating"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/title"
        android:layout_marginTop="1dip"
        android:layout_toRightOf="@+id/thumbnail"
        android:textSize="@dimen/rating" />
     
    <!-- Genre -->
    <TextView
        android:id="@+id/genre"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/rating"
        android:layout_marginTop="5dp"
        android:layout_toRightOf="@+id/thumbnail"
        android:textColor="@color/genre"
        android:textSize="@dimen/genre" />
 
    <!-- Release Year -->
    <TextView
        android:id="@+id/releaseYear"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:textColor="@color/year"
        android:textSize="@dimen/year" />
 
</RelativeLayout>  

  public View getView(int position, View convertView, ViewGroup parent) {
 
        if (inflater == null)
            inflater = (LayoutInflater) activity
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        if (convertView == null)
            convertView = inflater.inflate(R.layout.list_row, null);
}
请告诉我该怎么做?每当我尝试膨胀 list_row 时,它表明 list_row 无法解析或不是字段。请告诉我该怎么做?每当我尝试膨胀 list_row 时,它表明 list_row 无法解析或不是字段。

【问题讨论】:

  • 这是整个 getView 方法吗? list_row.xml 是您发布的第一个代码 sn-p 吗?它是否位于 res/layout 文件夹中?
  • 对不起...是的,第一个 sn-p 是 list_row.xml,它位于 res/layout 文件夹中。
  • 您是否导入了正确的 R 文件。也许你已经导入了 android.R 而不是你自己的项目 R 文件?

标签: android xml android-layout listview


【解决方案1】:

我重新编辑我的答案 尝试改变你的上下文;

将 inflater 中的上下文更改为“上下文”而不是活动,这两种方法可以获取 LayoutInflater:

getActivity().getLayoutInflater();

getContext().getSystemService(LAYOUT_INFLATER_SERVICE);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-10-03
    • 2012-07-24
    • 2016-02-10
    • 2018-10-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多