2

我正在尝试遵循本教程http://www.androidhive.info/2012/02/android-custom-listview-with-image-and-text/并且我创建了一个名为 my_coupons_row 的新 layout-xml 文件,但是项目似乎没有找到它。我收到my_coupons_row cannot be resolved or is not a field错误,但它就在那里。

这是我的适配器代码:

package com.xxx.xxx.util;

import java.util.ArrayList;
import java.util.HashMap;

import android.R;
import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class MyCouponsAdapter extends BaseAdapter {

    private Activity activity;
    private ArrayList<HashMap<String, String>> data;
    private static LayoutInflater inflater=null;   

    public MyCouponsAdapter(Activity a, ArrayList<HashMap<String, String>> d) {
        activity = a;
        data=d;
        inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);        
    }

    public int getCount() {
        return data.size();
    }

    public Object getItem(int position) {
        return position;
    }

    public long getItemId(int position) {
        return position;
    }

    public View getView(int position, View convertView, ViewGroup parent) {
        View vi=convertView;
        if(convertView==null)
            vi = inflater.inflate(R.layout.my_coupons_row , null); //The error is HERE

        TextView title = (TextView)vi.findViewById(R.id.title); // title
       // TextView artist = (TextView)vi.findViewById(R.id.artist); // artist name
       // TextView duration = (TextView)vi.findViewById(R.id.duration); // duration
       // ImageView thumb_image=(ImageView)vi.findViewById(R.id.list_image); // thumb image

        HashMap<String, String> song = new  HashMap<String, String>();
        song = data.get(position);

        // Setting all values in listview
      //  title.setText(song.get(CustomizedListView.KEY_TITLE));
       // artist.setText(song.get(CustomizedListView.KEY_ARTIST));
        //duration.setText(song.get(CustomizedListView.KEY_DURATION));

        return vi;
    }
}

我确定这很简单,但我无法弄清楚。感谢您的任何回复!

4

1 回答 1

7
import android.R;

你必须R从你的包中导入

例如:

import com.xxx.xxx.R;
于 2013-06-12T12:30:13.813 回答