1
我已經使用BaseAdapter
進行網格視圖,getView
方法BaseAdapter
我正在使用主要活動的上下文開始新活動,但是當我點擊圖標時,我在1秒內未找到消息應用程序,然後開始新活動,在log cat我收到錯誤PakageManager$PakageNotFoundEception
。在此先感謝您的幫助。Android:使用網格視圖開始新活動。
public class ImageAdapter extends BaseAdapter{
private Context mContext;
ArrayList<Integer> imgid;
Uri uri;
public ImageAdapter(Context c, ArrayList<Integer> imgid2) {
super();
mContext = c;
imgid=imgid2;
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return imgid.size();
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return null;
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return 0;
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
ImageView imageView;
if (convertView == null) { // if it's not recycled, initialize some attributes
imageView = new ImageView(mContext);
imageView.setLayoutParams(new GridView.LayoutParams(85, 85));
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
// imageView.setClickable(true);
imageView.setPadding(8, 8, 8, 8);
imageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Log.d("onClick","position ["+position+"]");
try {
final Intent intent= new Intent("settings");
intent.setClass(mContext, listAvtivity.class); //*******
if(imgid.get(position)==R.drawable.setting4){mContext.startActivity(intent);}
if(imgid.get(position)==R.drawable.google){uri = Uri.parse("http://www.google.com");}
if(imgid.get(position)==R.drawable.yahoo){uri = Uri.parse("http://www.yahoo.com");}
if(imgid.get(position)==R.drawable.skype){uri = Uri.parse("http://www.skype.com");}
Intent intent1 = new Intent(Intent.ACTION_VIEW, uri);
mContext.startActivity(intent1);
} catch (Exception e) {
// TODO: handle exception
Log.e("onClick Error: ",e.toString());
}
}
});
} else {
imageView = (ImageView) convertView;
}
imageView.setImageResource(imgid.get(position));
return imageView;
}
}