注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

沉默蜂B4A安卓编程

国内资料最全的B4A资料库

 
 
 

日志

 
 

[滑动开关库]Switch  

2014-04-13 13:31:50|  分类: 官网类库 |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |
http://www.basic4ppc.com/android/forum/threads/java-custom-view-with-designer-support-java-library.28980/page-2


类模块][滑动开关控件]Switch view (一) - 沉默蜂QQ793136625 - 沉默蜂
控件效果图



类 Switch  结构如下
  属性 Checked、Left、Top
  方法 AddToParent、DesignerCreateView、Initialize
  事件 CheckedChange 


java文件内容如下

package anywheresoftware.b4a.objects;

import android.view.ViewGroup;
import android.widget.CompoundButton;
import android.widget.Switch;
import android.widget.CompoundButton.OnCheckedChangeListener;
import anywheresoftware.b4a.BA;
import anywheresoftware.b4a.BA.Events;
import anywheresoftware.b4a.BA.Hide;
import anywheresoftware.b4a.BA.Pixel;
import anywheresoftware.b4a.BA.ShortName;
import anywheresoftware.b4a.BALayout;
import anywheresoftware.b4a.keywords.Common.DesignerCustomView;

@ShortName("Switch")
@Events(values={"CheckedChange (Value As Boolean)"})
public class SwitchWrapper implements DesignerCustomView {
private BA ba;
private String eventName;
private Switch switchView;

public void Initialize(BA ba, String EventName, int InitProperty1, boolean InitProperty2) {
_initialize(ba, null, EventName);
}

@Hide
public void _initialize(BA ba, Object activityClass, String EventName) {
this.eventName = EventName.toLowerCase(BA.cul);
this.ba = ba;
}

//programmatically add view
public void AddToParent(ViewGroup Parent, @Pixel int left, @Pixel int top, @Pixel int width, @Pixel int height) {
switchView = new Switch(ba.context);
switchView.setOnCheckedChangeListener(new OnCheckedChangeListener() {

@Override
public void onCheckedChanged(CompoundButton arg0, boolean arg1) {
ba.raiseEvent(this, eventName + "_checkedchange", arg1);
}

});
Parent.addView(switchView, new BALayout.LayoutParams(left, top, width, height));
}
//this method cannot be hidden.
public void DesignerCreateView(PanelWrapper base, LabelWrapper lw, anywheresoftware.b4a.objects.collections.Map props) {
ViewGroup vg = (ViewGroup) base.getObject().getParent();
AddToParent(vg, base.getLeft(), base.getTop(), base.getWidth(), base.getHeight());
base.RemoveView();
//set text properties
switchView.setText(lw.getText());
switchView.setTypeface(lw.getTypeface());
switchView.setTextSize(lw.getTextSize());
switchView.setTextColor(lw.getTextColor());

}
public void setChecked(boolean value) {
switchView.setChecked(value);
}
public boolean getChecked() {
return switchView.isChecked();
}

public void setLeft(int left)
{
BALayout.LayoutParams lp = (BALayout.LayoutParams)switchView.getLayoutParams();
lp.left = left;
switchView.getParent().requestLayout();
}
public int getLeft()
{
BALayout.LayoutParams lp = (BALayout.LayoutParams)switchView.getLayoutParams();
return lp.left;
}
public void setTop(int top)
{
BALayout.LayoutParams lp = (BALayout.LayoutParams)switchView.getLayoutParams();
lp.top = top;
switchView.getParent().requestLayout();
}
public int getTop()
{
BALayout.LayoutParams lp = (BALayout.LayoutParams)switchView.getLayoutParams();
return lp.top;
}

}
  评论这张
 
阅读(275)| 评论(0)
推荐 转载

历史上的今天

在LOFTER的更多文章

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2017