I have tried several methods tutorial and no one is able to solve my prob yet.I am trying it sine 2 days. My problem is when i run my custom list view program it shows error. and it is Error
MainActivity:
public class MainActivity extends Activity {
ListView list;
String[]name={
"Al Fresco",
"Appeliano",
"BFC",
"Mr. Burger",
"Grind House",
"Comic Cafe",
"cafe 5Six7",
"Cafe Cheeze Panic"
};
Integer[]imgid={
R.drawable.alfresco,
R.drawable.appeliano,
R.drawable.bfc,
R.drawable.burger,
R.drawable.tbk,
R.drawable.comiccafe,
R.drawable.cafefivesixseven,
R.drawable.cafecheezepanic
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
CustomAdapter adapter=new CustomAdapter(MainActivity.this,name,imgid);
list=(ListView)findViewById(R.id.list);
list.setAdapter(adapter);
}
}
And customadapter:
public class CustomAdapter extends ArrayAdapter<String> {
private final Activity context;
private final String[] name;
private final Integer[]imgid;
public CustomAdapter(Activity context,String[] name, Integer[] imgid) {
super(context,R.layout.mylist, name);
this.context = context;
this.name = name;
this.imgid = imgid;
}
@Override
public View getView(int position, View view, ViewGroup parent) {
LayoutInflater inflater=context.getLayoutInflater();
View rowView=inflater.inflate(R.layout.mylist,null,true);
TextView txtTitle= (TextView) rowView.findViewById(R.id.item_name);
ImageView imageView= (ImageView) rowView.findViewById(R.id.list_item);
txtTitle.setText(name[position]);
imageView.setImageResource(imgid[position]);
return rowView;
}
}