だから私は単純なボードゲームを作成する必要があります。これは、フラグメント内のGridview(10x10)に基づいています。アクティビティは、コントロール付きの別のフラグメントも表示します(左下)。 コントロールフラグメントのボタンが押されたときに、GridViewの内部でイメージを移動する必要があります。これまでのところ、私はGridViewにデータを取り込むことができましたが、イメージを内部に移動する方法を理解することはできません。GridViewの内部でImageViewを動的に置き換える方法(Android)?
このグリッドフラグメント
public class Grid extends Fragment{
GridView gridView;
private View rootView;
public PhotoImageAdapter mAdapter;
Integer[] image = {
R.drawable.pucman, R.drawable.ground, R.drawable.ground, R.drawable.ground, R.drawable.ground, R.drawable.ground, R.drawable.ground, R.drawable.ground, R.drawable.ground, R.drawable.ground,
R.drawable.ground, R.drawable.ground, R.drawable.ground, R.drawable.ground, R.drawable.ground, R.drawable.ground, R.drawable.ground, R.drawable.ground, R.drawable.ground, R.drawable.ground,
R.drawable.ground, R.drawable.ground, R.drawable.ground, R.drawable.ground, R.drawable.ground, R.drawable.ground, R.drawable.ground, R.drawable.ground, R.drawable.ground, R.drawable.ground,
R.drawable.ground, R.drawable.ground, R.drawable.ground, R.drawable.ground, R.drawable.ground, R.drawable.ground, R.drawable.ground, R.drawable.ground, R.drawable.ground, R.drawable.ground,
R.drawable.ground, R.drawable.ground, R.drawable.ground, R.drawable.ground, R.drawable.ground, R.drawable.ground, R.drawable.ground, R.drawable.ground, R.drawable.ground, R.drawable.ground,
R.drawable.ground, R.drawable.ground, R.drawable.ground, R.drawable.ground, R.drawable.ground, R.drawable.ground, R.drawable.ground, R.drawable.ground, R.drawable.ground, R.drawable.ground,
R.drawable.ground, R.drawable.ground, R.drawable.ground, R.drawable.ground, R.drawable.ground, R.drawable.ground, R.drawable.ground, R.drawable.ground, R.drawable.ground, R.drawable.ground,
R.drawable.ground, R.drawable.ground, R.drawable.ground, R.drawable.ground, R.drawable.ground, R.drawable.ground, R.drawable.ground, R.drawable.ground, R.drawable.ground, R.drawable.ground,
R.drawable.ground, R.drawable.ground, R.drawable.ground, R.drawable.ground, R.drawable.ground, R.drawable.ground, R.drawable.ground, R.drawable.ground, R.drawable.ground, R.drawable.ground,
R.drawable.ground, R.drawable.ground, R.drawable.ground, R.drawable.ground, R.drawable.ground, R.drawable.ground, R.drawable.ground, R.drawable.ground, R.drawable.ground, R.drawable.ground,
};
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
rootView = inflater.inflate(R.layout.fragment_grid, container, false);
gridView = rootView.findViewById(R.id.GridView);
gridView.setAdapter(new PhotoImageAdapter(this.getActivity(), image));
return rootView;
}
public void goRight()// this function is called by the control fragment.
{
// here is my not so fructuous attempt to replace the image in the
//second cell with the image of my character
image[1]=R.drawable.pucman;
image[0]=R.drawable.ground;
}
が、これは私のアダプタです。
public class PhotoImageAdapter extends BaseAdapter {
private Context mContext;
public Integer[] mThumbIds;
public PhotoImageAdapter(Context c, Integer[] image) {
mContext = c;
mThumbIds = image;
}
public int getCount() {
return mThumbIds.length;
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return 0;
}
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.setLayoutParams(new GridView.LayoutParams(80, 80));
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
imageView.setPadding(8, 8, 8, 8);
} else {
imageView = (ImageView) convertView;
}
imageView.setImageResource(mThumbIds[position]);
return imageView;
}
}
すべてのヘルプは大歓迎されます!ありがとう:)
パズルゲームをしたいですか? –
実際には、それを越えて動くことができるキャラクターを持ったボードゲームです。 – Eric