我在网格视图中链接活动时遇到问题。
我的代码在这里:
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
@SuppressLint("NewApi")
public View getView(int position, View convertView, ViewGroup parent) {
ImageView imageView;
if (convertView == null) { // if it's not recycled, initialize some attributes
imageView = new ImageView(mContext);
imageView.setScaleType(ImageView.ScaleType.FIT_CENTER);
imageView.setPadding(5, 5, 5, 5);
imageView.setBackgroundColor(0);
imageView.setAdjustViewBounds(true);
} else {
imageView = (ImageView) convertView;
}
imageView.setImageResource(mThumbIds[position]);
if(position == 2)
{
Intent nextScreen = new Intent(getApplicationContext(), News.class);
startActivity(nextScreen);
}
if(position == 1)
{
Intent nextScreen = new Intent(getApplicationContext(), Open.class);
startActivity(nextScreen);
}
return imageView;
}
// references to our images
private Integer[] mThumbIds = {
R.drawable.info, R.drawable.open,
R.drawable.news, R.drawable.specials,
R.drawable.maerkte, R.drawable.anfahrt,
R.drawable.artikel, R.drawable.kontakt,
};
}
我认为这只是一个小问题:(我几天以来一直在寻找答案,.. :(我希望你能帮助我,在我得到正确答案之前我会感谢你;)
祝你今天过得愉快