我在列表视图中有一个列表项。如果我单击第一项,我将启动活动并显示一些图像。如果我单击第二个列表项,我将开始另一个活动并显示一些图像。这里是列表查看代码。包 com.example.per.app;
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 个活动。在每个活动中我想显示不同的图像集。