安卓代码找茬,代码如图所示。我的目的是点击一个图片按钮弹出一个dialog,dialog里有个gallery。 5
publicclassMainActivityextendsActivity{privateImageButtonimg_bt;int[]img_array={R.dra...
public class MainActivity extends Activity {
private ImageButton img_bt;
int[] img_array = { R.drawable.xh, R.drawable.xh2, R.drawable.xh3,
R.drawable.xh4, R.drawable.xh5, R.drawable.xh6 };
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
img_bt = (ImageButton) findViewById(R.id.img_bt);
img_bt.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
initDialog();
}
});
}
protected void initDialog() {
AlertDialog.Builder bulider = new AlertDialog.Builder(this);
bulider.setTitle("请选择图片");
LayoutInflater inFlater = LayoutInflater.from(this);
View view = inFlater.inflate(R.layout.gallery_swither, null);
bulider.setView(view);
Gallery gallery = (Gallery) findViewById(R.id.gallery);
ImageSwitcher imgSwitcher = (ImageSwitcher) findViewById(R.id.img_switcher);
gallery.setAdapter(new imageAdapter(this));
gallery.setSelection(img_array.length / 2);
bulider.create().show();
}
class imageAdapter extends BaseAdapter {
private Context context;
public imageAdapter(Context context) {
this.context = context;
}
public int getCount() {
return img_array.length;
}
public Object getItem(int position) {
return img_array[position];
}
public long getItemId(int position) {
return position;
} 展开
private ImageButton img_bt;
int[] img_array = { R.drawable.xh, R.drawable.xh2, R.drawable.xh3,
R.drawable.xh4, R.drawable.xh5, R.drawable.xh6 };
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
img_bt = (ImageButton) findViewById(R.id.img_bt);
img_bt.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
initDialog();
}
});
}
protected void initDialog() {
AlertDialog.Builder bulider = new AlertDialog.Builder(this);
bulider.setTitle("请选择图片");
LayoutInflater inFlater = LayoutInflater.from(this);
View view = inFlater.inflate(R.layout.gallery_swither, null);
bulider.setView(view);
Gallery gallery = (Gallery) findViewById(R.id.gallery);
ImageSwitcher imgSwitcher = (ImageSwitcher) findViewById(R.id.img_switcher);
gallery.setAdapter(new imageAdapter(this));
gallery.setSelection(img_array.length / 2);
bulider.create().show();
}
class imageAdapter extends BaseAdapter {
private Context context;
public imageAdapter(Context context) {
this.context = context;
}
public int getCount() {
return img_array.length;
}
public Object getItem(int position) {
return img_array[position];
}
public long getItemId(int position) {
return position;
} 展开
1个回答
2014-04-01
展开全部
GETView呢
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询