私はアンドロイド開発が初めてです。私のアンドロイドactivity
にはGridView
と がありButton
ます。GridView adapter
クラスは に一連のアイコンを表示していますGridView
。私が望むのは、Button
アクティビティ内の がクリックされた場合、内のアイコンのGridView
セットを別のアイコンのセットに置き換える必要があるということです。また、アクティビティでクリックするたびButton
に、 の 2 つのアイコン セットが切り替わりますGridView
。それで、これを使用してこれを行う方法はnotifyDatasetChanged()
?助けてください。
GridView Adapter
クラス:
public class CustomAdapter extends BaseAdapter{
boolean imageSetChange = false;
// set 1
public Integer[] mThumbPics = {
R.drawable.pic1, R.drawable.pic2,
R.drawable.pic3, R.drawable.pic4,
R.drawable.pic5, R.drawable.pic6,
R.drawable.pic7, R.drawable.pic8,
R.drawable.pic9, R.drawable.pic10,
R.drawable.pic11, R.drawable.pic12,
R.drawable.pic13, R.drawable.pic14,
R.drawable.pic15, R.drawable.pic16,
R.drawable.pic17, R.drawable.pic18,
R.drawable.pic19, R.drawable.pic20,
R.drawable.pic21
};
//set 2
public Integer[] mThumbEng = {
R.drawable.eng_pic1, R.drawable.eng_pic2,
R.drawable.eng_pic3, R.drawable.eng_pic4,
R.drawable.eng_pic5, R.drawable.eng_pic6,
R.drawable.eng_pic7, R.drawable.eng_pic8,
R.drawable.eng_pic9, R.drawable.eng_pic10,
R.drawable.eng_pic11, R.drawable.eng_pic12,
R.drawable.eng_pic13, R.drawable.eng_pic14,
R.drawable.eng_pic15, R.drawable.eng_pic16,
R.drawable.eng_pic17, R.drawable.eng_pic18,
R.drawable.eng_pic19, R.drawable.eng_pic20,
R.drawable.eng_pic21
};
private Context mContext;
View MyView;
ImageView imageView;
public CustomAdapter(Context c){
mContext = c;
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return mThumbEng.length;
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return mThumbEng[position];
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return 0;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
if(imageSetChange==false)
{if(convertView == null){
LayoutInflater li=((Activity) mContext).getLayoutInflater();
MyView=li.inflate(R.layout.menuitem, null);
}
else{
MyView=(View)convertView;
}
imageView =(ImageView)MyView.findViewById(R.id.image);
imageView.setImageResource(mThumbEng[position]);
return MyView;
}
else{
if(convertView == null){
LayoutInflater li=((Activity) mContext).getLayoutInflater();
MyView=li.inflate(R.layout.menuitem, null);
}
else{
MyView=(View)convertView;
}
imageView =(ImageView)MyView.findViewById(R.id.image);
imageView.setImageResource(mThumbUrdu[position]);
return MyView;
}
}
/** public void changeImages(boolean change){
this.imageSetChange = change;
cda.notifyDataSetChanged();
}
**/
}
ボタンの onclick リスナー:
Button lang_change_btn = (Button) findViewById(R.id.button1);
lang_change_btn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
// TODO Auto-generated method stub
//cda.changeImages(true);
}
});