I have 10 graphic needs to display in my ListView
and I create a class like this
public class LayoutAdapterObj {
public String addString;
public ImageView leftImage;
public String backgroundImageName;
public LayoutAdapterObj(String addString,ImageView leftImageName,String backgroundImageName){
this.addString = addString;
this.leftImage = leftImageName;
this.backgroundImageName = backgroundImageName;
}
and when I create a LayoutAdaptor object
I do this
aArray.add(new LayoutAdapterObj("1",new ImageView(null, null, R.drawable.frame1),"R.drawable.layout"));
aArray.add(new LayoutAdapterObj("2",new ImageView(null, null, R.drawable.frame2),"R.drawable.layout"));
LayoutListAdapter m_adapter;
m_adapter = new LayoutListAdapter(this, R.layout.topbarlayout, aArray);
after that…. in my adapter class, i do this
public View getView(int position, View convertView, ViewGroup parent) {
View v = convertView;
if (v == null) {
LayoutInflater vi = (LayoutInflater)getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = vi.inflate(R.layout.layout1, null);
}
LayoutAdapterObj o = items.get(position);
if (o != null) {
TextView addText = (TextView) v.findViewById(R.id.addtext);
ImageView leftImage=(ImageView)v.findViewById(R.id.layoutframe);
if(!o.backgroundImageName.equals(""))
{
}
if(addText!=null)
{
addText.setText(o.addString);
}
the wrong message is like this
java.lang.IllegalStateException: Could not execute method of the activity
if(leftImage != null)
{
leftImage= o.leftImage;
}
see this…example…`
call your adapter like this
UserListAdapter a=new UserListAdapter();
yurlistview.setAdapter(a);