我已经创建了一个自定义ListView适配器/项目.该项包含CheckedTextView和TextView.
在适配器的getView()方法中,创建自定义项并在返回之前调用其setTask(Task)方法.
setTask(Task)方法从作为参数传入的Task对象获取2个字符串和一个布尔值.(我确实认识到它的地址实际上是传递的.)
其中一个字符串被分配给自定义项的TextView的文本属性,如果该字符串包含文本.否则,TextView的visible属性设置为"已消失".
为了做出这个决定,我检查字符串的长度是否小于或等于0 ......它会产生意外的行为 - 它总是评估为真.
如果我更改它以检查String是否等于"",它总是返回false.
这让我相信我正在检查的String是null.那为什么会这样?
protected void onFinishInflate() {
super.onFinishInflate();
checkbox = (CheckedTextView)findViewById(android.R.id.text1);
description = (TextView)findViewById(R.id.description);
}
public void setTask(Task t) {
task = t;
checkbox.setText(t.getName());
checkbox.setChecked(t.isComplete());
if (t.getDescription().length() <= 0)
description.setVisibility(GONE);
else
description.setText(t.getDescription());
}
Run Code Online (Sandbox Code Playgroud)
这是适配器中的getView()方法:
public View getView(int position, View convertView, ViewGroup parent) {
TaskListItem tli;
if (convertView == null)
tli = (TaskListItem)View.inflate(context, R.layout.task_list_item, null);
else
tli = (TaskListItem)convertView;
tli.setTask(currentTasks.get(position));
return tli;
}
Run Code Online (Sandbox Code Playgroud) 我正在用Java创建一个客户端/服务器对,目前只支持通过PrintWriters和BufferedReaders包围服务器和客户端IO流的隔行文本通信.
我想实现一个函数,它使用Image [Input/Output] Stream以一定的时间间隔从服务器向客户端发送BufferedImage.
问题是我希望在单独的线程中发送/接收BufferedImages,以便客户端/服务器仍然可以发送/接收文本命令.
我可以创建多个流或套接字吗?如果是这样,那是最好的方法吗?