我已經嘗試了幾種方法教程,沒有人能夠解決我的可能yet.I嘗試它正弦2天。我的問題是當我運行我的自定義列表視圖程序它顯示錯誤。它是 ErrorAndroid自定義列表視圖
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);
}
}
而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;
}
}
你能告訴我們的日誌嗎? –
更改** appeliano.png **,我認爲這張圖片是不對的.png圖片 – Furqan
@MD。 Saiful伊斯蘭教:你能用其他圖像替換'appliano.png'並再試一次嗎? – AndiGeeky