
我有一个由CursorAdapter生成的按钮的网格视图.当CursorAdapter传递给GrIDvIEw时,视图会正确呈现,但网格中的第一项不会触发OnClickListener事件.
如果我在网格中选择另一个按钮,则事件会正确触发,但是如果我选择了第一个按钮然后是另一个按钮,则会加载第一个按钮 *** 作,然后是部分按钮 *** 作.
在测试时,它似乎只是在我的模拟器上的Android 2.2中的问题,我的1.5手机按预期工作.我已经擦除了模拟器,但这似乎没有什么区别.
public class AdapterMedia extends CursorAdapter { Context context; Cursor cursor; public AdapterMedia(Context context, Cursor dataset) { super(context, dataset); this.context = context; this.cursor = dataset; } @OverrIDe public VIEw newVIEw(Context context, Cursor cursor, VIEwGroup arg2) { button imageVIEw; imageVIEw = new button(context); imageVIEw.setLayoutParams(new GrIDVIEw.LayoutParams(85, 85)); imageVIEw.setpadding(8, 8, 8, 8); imageVIEw.setID(cursor.getInt(0)); imageVIEw.setText(cursor.getString(1)); imageVIEw.setonClickListener(buttonClickListener); return imageVIEw; } @OverrIDe public voID bindVIEw(VIEw arg0, Context arg1, Cursor arg2) { button imageVIEw = (button) arg0; imageVIEw.setLayoutParams(new GrIDVIEw.LayoutParams(85, 85)); imageVIEw.setpadding(8, 8, 8, 8); imageVIEw.setID(cursor.getInt(0)); imageVIEw.setText(cursor.getString(1)); imageVIEw.setonClickListener(buttonClickListener); } public OnClickListener buttonClickListener = new OnClickListener() { public voID onClick(VIEw vIEw) { Bundle dataset = new Bundle(); dataset.putInt("media_ID", vIEw.getID()); Intent showMedia = new Intent(context.getApplicationContext(), MediaActivity.class); showMedia.putExtras(dataset); context.startActivity(showMedia); } };}@H_419_11@解决方法:
在GrIDVIEw对象上设置onItemClickListener,而不是在每个图像上设置onClickListener.
总结以上是内存溢出为你收集整理的Android OnClickListener未在GridView中触发(仅限2.2)全部内容,希望文章能够帮你解决Android OnClickListener未在GridView中触发(仅限2.2)所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)