gpt4 book ai didi

java - 如果从父类(super class)继承,为什么我会在 list_item 中收到错误

转载 作者:太空宇宙 更新时间:2023-11-04 11:54:58 24 4
gpt4 key购买 nike

为什么我收到错误“无法解析 list_item” 我正在扩展父类(super class),但无法访问 list_item。为什么我失踪了?这是 udacity 类(class)构建 miwok 应用程序的一部分。在 Android Studio 中。谢谢

    package com.example.android.miwok;

import android.app.Activity;
import android.support.annotation.NonNull;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import java.util.ArrayList;

/**
* Created by george on 1/3/17.
*/

public class WordAdapter extends ArrayAdapter<Word> {

/**
* This is our own custom constructor (it doesn't mirror a superclass constructor).
* The context is used to inflate the layout file, and the list is the data we want
* to populate into the lists.
*
* @param context The current context. Used to inflate the layout file.
* @param WordAdapter A List of AndroidFlavor objects to display in a list
*/
public WordAdapter(Activity context, ArrayList<Word> Word) {
// Here, we initialize the ArrayAdapter's internal storage for the context and the list.
// the second argument is used when the ArrayAdapter is populating a single TextView.
// Because this is a custom adapter for two TextViews and an ImageView, the adapter is not
// going to use this second argument, so it can be any value. Here, we used 0.
super(context, 0, Word);
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
// Check if the existing view is being reused, otherwise inflate the view
View listItemView = convertView;
if(listItemView == null) {
listItemView = LayoutInflater.from(getContext()).inflate(R.layout.list_item, parent, false);
}

// Get the {@link AndroidFlavor} object located at this position in the list
Word currentWord = getItem(position);

// Find the TextView in the list_item.xml layout with the ID version_name
TextView miwokTextView = (TextView) listItemView.findViewById(R.id.list_items);
// Get the version name from the current AndroidFlavor object and
// set this text on the name TextView
miwokTextView.setText(currentWord.getMiwokTranslation());

// Find the TextView in the list_item.xml layout with the ID version_number
TextView defaultTextView = (TextView) listItemView.findViewById(R.id.miwok_text_view);
// Get the version number from the current AndroidFlavor object and
// set this text on the number TextView
defaultTextView.setText(currentWord.getmDefaultTranslation());

// Return the whole list item layout (containing 2 TextViews and an ImageView)
// so that it can be shown in the ListView
return listItemView;
}
}

最佳答案

我认为您有与 this one 类似的问题.

您应该做的是在布局文件夹中创建 list_item.xml。

list_item.xml:

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/miwok_text_view"
android:layout_width="match_parent"
android:layout_height="55dp"
android:textSize="15sp"
android:paddingTop="3dp"
android:paddingBottom="3dp"
android:textColor="#000000"/>

关于java - 如果从父类(super class)继承,为什么我会在 list_item 中收到错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41452007/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com