我在資源文件夾中有200個圖像,我將它們命名爲name_1.png
,name_2.png
。我有一個數組,我有幾個數字,如2, 4 , 6 ,30 , 40 ... and so on
。如何從資源文件夾加載圖像到Android列表視圖
我想將圖像和文本視圖加載到android並根據資源文件夾中的數字顯示圖像。
爲此我創建了一個activity class
和image adapter class
爲custom list view
。
我可以根據陣列數據編號顯示text view
數據,但不顯示圖像。
任何人都可以告訴我該怎麼做。我在想,我必須編寫代碼getview
方法來更改圖像。
這是getview
方法,我試圖
@Override
public View getView(int position, View convertView, ViewGroup parent) {
convertView = mInflater.inflate(mViewResourceId, null);
TextView tv1 = (TextView)convertView.findViewById(R.id.tvtype);
TextView tv2 = (TextView)convertView.findViewById(R.id.tvnumber);
ImageView i1= (ImageView)convertView.findViewById(R.id.ivlfirst);
//int i = Integer.parseInt("normal_"+mStrings.get(position)+".png");
i1.setBackgroundResource("normal_"+mStrings.get(position)+".png");
tv1.setText(mStrings1.get(position));
tv2.setText(mStrings.get(position));
return convertView;
}
資源文件夾中的'res/drawable /'對嗎? –
是的,它是在res/drawable/ – MADDY
請make image數組。 –