我有一个自定义视图:
class CustomerView(context: Context, attrs: AttributeSet) : LinearLayout(context, attrs) {
private var txtName: TextView
private var txtAge: TextView
init {
View.inflate(context, R.layout.view_customer, null)
txtName = findViewById(R.id.txtTestName)
txtAge = findViewById(R.id.txtTestAge)
txtName.text = "Person"
txtAge.text = "61"
}
}
Run Code Online (Sandbox Code Playgroud)
我的布局view_customer如下所示:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/txtTestName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="name" />
<TextView
android:id="@+id/txtTestAge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="age" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
但是当我在另一个页面调用它时,应用程序崩溃说
引起:java.lang.IllegalStateException: findViewById(R.id.txtTestName) 在 com.helcim.helcimcommercemobile.customviews.CustomerView.(CustomerView.kt:19) 处不能为空
这是我尝试分配的时候 txtName
当我在布局视图中拥有它时,我真的不明白它是如何为空的。它的名字相同。
我是否错误地创建了自定义视图?
让我讲一下我想要完成的事情.
我有一个具有本地IP地址的设备(芯片和引脚终端),它已被编程为接收某些数据并进行处理.
示例:我"05"以十六进制发送字符串,"30 35"终端读取并重启.
我尝试过使用SockJS-Client以及内置的WebSockets.
但是,使用Websockets我注意到浏览器正在发送:
GET / HTTP/1.1
Host: IP:PORT
Connection: Upgrade
Pragma: no-cache
Cache-Control: no-cache
Upgrade: websocket
Origin: MYIP
Sec-WebSocket-Version: 13
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36
Accept-Encoding: gzip, deflate, sdch
Accept-Language: en-US,en;q=0.8
Sec-WebSocket-Key: A1CeTMFnQCZv4GNZbLFnyQ==
Sec-WebSocket-Extensions: permessage-deflate; client_max_window_bits
Run Code Online (Sandbox Code Playgroud)
当我的代码看起来像这样:
var exampleSocket = new WebSocket("ws://IP:PORT");
exampleSocket.send("05");
Run Code Online (Sandbox Code Playgroud)
如果我将代码更改为:
var exampleSocket = new WebSocket("wss://IP:PORT");
exampleSocket.send("05");
Run Code Online (Sandbox Code Playgroud)
我只收到3个发送的标签: SYN(0x0016) ETX(0x0003) SOH(0x0001)
现在我不确定你是否需要一个WebSocket Sever才能解释传入的数据.
SockJS通过发送关于自身和broswer的额外信息来做同样的事情:
GET /info?t=1452272641278 HTTP/1.1
Host: IP:PORT …Run Code Online (Sandbox Code Playgroud) 我对Flutter相当陌生,正在尝试创建一个不遵循材料设计准则(公司希望自己设计)的应用程序。
我似乎只能使用材料设计或Cupertino来创建东西。我不确定如何使用自定义脚手架或在小部件构建功能中使用return new MaterialApp(...,或者AppBar如果它可以是平坦的而不是有阴影的话。
我希望这是有道理的。我只是想找到一种解决方法。
我创建了一个按钮,我想为该按钮添加涟漪效果和渐变!
这是我的按钮代码:
<Button
android:id="@+id/percentageButton"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="@drawable/gradient"
android:gravity="center"
android:text="%"
android:textColor="@android:color/white"
android:textSize="30dp">
</Button>
Run Code Online (Sandbox Code Playgroud)
这是我的gradient.xml文件代码
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >
<corners
android:radius="0dp"/>
<gradient
android:gradientRadius="100"
android:centerX="49%"
android:centerY="50%"
android:centerColor="#434343"
android:startColor="#0F0F0F"
android:endColor="#141414"
android:type="radial"/>
</shape>
Run Code Online (Sandbox Code Playgroud)
我已经尝试了所有的可能性,但没有得到如何实现这一点。
我正在尝试创建一个基于参数动态设置属性的函数,
它看起来像这样
function setPro(sourceId,type,destId){
document.getElementById(destId).style. + type = document.getElementById(sourceId).value;
}
Run Code Online (Sandbox Code Playgroud)
我不确定如何设置类型?
这可能吗?或者我将不得不做一个选择案例并根据它选择?