登录
首页 » Android » Android OnClickListener监听接口用法范例

Android OnClickListener监听接口用法范例

于 2023-05-27 发布 文件大小:36.43 kB
0 31
下载积分: 2 下载次数: 1

代码说明:

Android OnClickListener监听接口用法范例,基础级的例子,   Button button = (Button) findViewById(R.id.Button01);//获取屏幕中的按钮控件对象   button.setOnClickListener(//为按钮对象添加OnClickListener接口实现    //OnClickListener为View的内部接口,其实现者负责监听鼠标点击事件   new View.OnClickListener(){   public void onClick(View v){   LinearLayout ll=(LinearLayout)findViewById(R.id.lla);//获取线性布局对象   String msg=LinearActivity.this.getResources().getString(R.string.button);   Button tempbutton=new Button(LinearActivity.this);//创建一个Button对象   tempbutton.setText(msg+(++count));//设置Button控件显示的内容   tempbutton.setWidth(80);//设置Button的宽度   ll.addView(tempbutton);//向线性布局中添加View   System.out.println("========= count"+count);

下载说明:请别用迅雷下载,失败请重下,重下不扣分!

发表评论

0 个回复

  • 用BPA计算连续潮流程序
    【实例简介】
    2021-06-25 00:30:59下载
    积分:1
  • bms(终版)
    实现WIFI环境下的以太网通信,在手机上监控BMS的运行参数(Realize the Ethernet communication in WIFI environment, monitor the operation parameters of BMS on the mobile phone)
    2017-11-23 13:17:13下载
    积分:1
  • android-pulltorefresh-master
    android上拉下拉刷新 PullToRefresh Android-PullToRefresh-master 注释掉PullToRefreshViewPager 里面的viewPager.setId(R.id.viewpager) 就可以了 androidpull..fresh(pull-down refresh on android PullToRefresh Android-PullToRefresh-master commented PullToRefreshViewPager inside viewPager.setId (R.id.viewpager) on it androidpull..fresh)
    2014-11-02 21:48:05下载
    积分:1
  • Android
    2022-03-03 21:22:03下载
    积分:1
  • android 自定义单选、多选对话框及popwindow窗口实例源码
    android 自定义单选、多选对话框及popwindow窗口实例源码
    2014-08-21下载
    积分:1
  • android联系人带字母检索源码
    android联系人带字母检索源码/** * 联系人列表适配器。 * * @author guolin */public class ContactAdapter extends ArrayAdapter { /** * 需要渲染的item布局文件 */ private int resource; /** * 字母表分组工具 */ private SectionIndexer mIndexer; public ContactAdapter(Context context, int textViewResourceId, List objects) { super(context, textViewResourceId, objects); resource = textViewResourceId; } @Override public View getView(int position, View convertView, ViewGroup parent) { Contact contact = getItem(position); LinearLayout layout = null; if (convertView == null) { layout = (LinearLayout) LayoutInflater.from(getContext()).inflate(resource, null); } else { layout = (LinearLayout) convertView; } TextView name = (TextView) layout.findViewById(R.id.name); LinearLayout sortKeyLayout = (LinearLayout) layout.findViewById(R.id.sort_key_layout); TextView sortKey = (TextView) layout.findViewById(R.id.sort_key); name.setText(contact.getName()); int section = mIndexer.getSectionForPosition(position); if (position == mIndexer.getPositionForSection(section)) { sortKey.setText(contact.getSortKey()); sortKeyLayout.setVisibility(View.VISIBLE); } else { sortKeyLayout.setVisibility(View.GONE); } return layout; } /** * 给当前适配器传入一个分组工具。 * * @param indexer */ public void setIndexer(SectionIndexer indexer) { mIndexer = indexer; }}
    2014-04-13下载
    积分:1
  • Android 简单播放歌曲功能演示
    Android 简单播放歌曲功能演示,播放本地音乐,非网络播放,可播放、暂停,运行效果如截图所示,在编写时,要注意以下代码:   int status = 1;//当前的状态,1没有声音播放 ,2 正在播放声音,3暂停   ImageButton start;//播放、暂停按钮   ImageButton stop;//停止按钮   ActivityReceiver activityReceiver;   int status = 1;//当前的状态,1没有声音播放 ,2 正在播放声音,3暂停   public void onCreate(Bundle savedInstanceState) {//重写的onCreate方法    super.onCreate(savedInstanceState);    setContentView(R.layout.main);//设置当前的用户界面    start = (ImageButton) this.findViewById(R.id.start);//得到start的引用    stop = (ImageButton) this.findViewById(R.id.stop);//得到stop按钮的引用    start.setOnClickListener(this);//为按钮添加监听    stop.setOnClickListener(this);//为按钮添加监听    activityReceiver = new ActivityReceiver();//创建BroadcastReceiver    IntentFilter filter = new IntentFilter();//创建IntentFilter过滤器    filter.addAction("wyf.ytl.update");//添加Action    registerReceiver(activityReceiver, filter);//注册监听    Intent intent = new Intent(this, MyService.class);//创建Intent    startService(intent);//启动后台Service   }
    2023-08-23 12:30:03下载
    积分:1
  • Layout_01
    Android布局详解介绍linerlayout(android Layout)
    2011-10-01 00:47:03下载
    积分:1
  • spydroid10.0开源摄像头项目
    资源描述spydroid10.0开源摄像头项目,解决在5.0以上崩溃问题,测试发现MediaCodec编码效率低下,建议使用MediaRecorder录制。延迟在1-2秒之内,效率极高。我的是在此版本之上改的,借鉴此项目中一些代码,用于双向视频通话。
    2022-09-10 20:30:07下载
    积分:1
  • SensorTag android
    根据工程师所给的视屏一级代码做的一个读取SensorTag的代码,但是该SensorTag的ble协议栈是1.3的不是1.4的,即是旧defirmware,新的不知道为什么就是连不上
    2022-08-09 12:02:15下载
    积分:1
  • 696524资源总数
  • 103945会员总数
  • 46今日下载