I'm trying to follow this tutorial http://www.androidhive.info/2012/02/android-custom-listview-with-image-and-text/ and I have created a new layout-xml file called my_coupons_row but the project doesn't seem to find it. I'm getting my_coupons_row cannot be resolved or is not a field error but it is there.
Here is my adapter code:
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;
}
}
I'm sure it is something simple but I cannot figure it out. Thanks for any response!
import android.R;
you must import R from your package
for instance:
import com.xxx.xxx.R;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With