1
我想要跟隨本教程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
錯誤,但它在那裏。Inflater無法找到佈局 - Android
這裏是我的適配器代碼:
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;
}
}
我敢肯定,這是簡單的東西,但我無法弄清楚。 感謝您的迴應!
超級男人!多數民衆贊成它我不能相信我沒有發現這在谷歌這麼長時間! – PaperThick