我在列表視圖中有一個列表項目,如果我點擊第一個項目,我將開始活動,並會顯示一些圖像。如果我點擊第二個列表項目,我將開始另一個活動,並會顯示一些一組圖像。這裏是列表視圖代碼。 package com.example.per.app;帶圖像適配器的ListView
public class AlbumListActivity extends Activity {
public String[] mListInfo = { "1st Month", "2nd Month", "3rd Month",
"4th Month", "5th Month", "6th Month", "7th Month", "8th Month",
"9th Month", "10th Month", "11th Month", "12th Month" };
public ListView mList = null;
public Intent mLaunch = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.list_album);
mList = (ListView) findViewById(R.id.list_view);
ArrayAdapter<String> mAdapter = new ArrayAdapter<String>(
getApplicationContext(), android.R.layout.simple_list_item_1,
mListInfo);
mList.setAdapter(mAdapter);
mList.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
switch (arg2) {
case 0:
mLaunch = new Intent(getApplicationContext(),FirstMonthActivity.class);
startActivity(mLaunch);
}
}
});
}
public class ImageAdapter extends BaseAdapter {
private Context mContext;
public ImageAdapter(Context c) {
mContext = c;
}
public int getCount() {
return mThumbIds.length;
}
public Object getItem(int position) {
return null;
}
public long getItemId(int position) {
return 0;
}
// create a new ImageView for each item referenced by the Adapter
public View getView(int arg0, View arg1, ViewGroup arg2) {
ImageView imageView;
if (arg1 == null) { // if it's not recycled, initialize some
// attributes
imageView = new ImageView(mContext);
imageView.setLayoutParams(new GridView.LayoutParams(363, 363));
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
imageView.setPadding(0, 0, 0, 0);
} else {
imageView = (ImageView) arg1;
}
imageView.setImageResource(mThumbIds[arg0]);
return imageView;
} // references to our images
Integer[] mThumbIds = { R.drawable.sample0, R.drawable.sample1,
R.drawable.sample2, R.drawable.sample3, R.drawable.sample4,
R.drawable.sample5, R.drawable.sample6, R.drawable.sample7,
R.drawable.sample8, R.drawable.sample9 };
}
}
我需要保持在視圖列表項ImageAdapater類?由於每個列表項我想顯示不同的圖像集。
目前我只添加案例0,我會添加案例1案例2案例3 ...案例12.所以我必須推出12個activities.in每個活動中我想顯示不同的圖像集。
我在List.I中有12個項目,在res文件夾中有120個圖像。對於每個List項目,我想顯示10個圖像。如何做到這一點? – chait
看到我編輯的答案,並讓我知道你是否有任何問題。 – ayon
所以在我的代碼中,我使用ImageAdaper類來加載圖像。所以這個類是不需要的?請參閱上面的代碼。 – chait