有没有比使用更简单的方法___ in object检查对象的每个级别的存在来检查单个成员的存在?
更简洁:我如何检查someObject.member.member.member.value是否存在?
我在列表视图中显示的复选框中存在样式问题.我的应用使用的主题是Holo,但复选框以旧样式显示.出现在别处的复选框看起来很好.我没有做任何花哨的事情,比如创造我自己的风格.截图:

复选框应该看起来像右图上的复选框.这是在v4.0.3上.复选框看起来应该在我尝试使用v4.4.2的其他设备上.
列表视图行的XML:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<CheckBox android:id="@+id/ListRow_Task_TaskComplete"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="6sp"
android:focusable="false" />
<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="7dip"
android:paddingBottom="7dip"
android:layout_toRightOf="@+id/ListRow_Task_TaskComplete"
android:layout_centerVertical="true" >
<TextView android:id="@+id/ListRow_Task_Name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="16sp" />
// next two textviews are programmatically hidden right now
<TextView android:id="@+id/ListRow_Task_Deadline"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textSize="12sp" />
<TextView android:id="@+id/ListRow_Task_Tags"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableLeft="@drawable/icon_tag"
android:drawablePadding="4dip"
android:textSize="12sp" />
</LinearLayout>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
如何使左侧的复选框看起来像它们应该的那样?
我有一些关于JavaScript的问题,我需要确定.为了帮助,我有一个简单的类定义我正在写:
var dataSource = function (src, extension) {
return {
exists: function () {
// function to check if the source exists (src *should* be an object
// and extension should be a string in the format ".property.property.theSource".
// this function will return true if src.property.property.theSource exists)
},
get: function () {
// function will return the source (ex: return src.property.property.theSource)
}
}
}();
Run Code Online (Sandbox Code Playgroud)
问题:
1)在我目前对JavaScript的理解中,调用dataSource()将创建一个具有自己的exists()和get()方法副本的新对象.我对么?
2)有没有办法写这个,这样如果我创建1,000,000个dataSource对象,我只需要每个函数的一个副本?
3)我是否应该关注(2)?
我是开发嵌入式系统的新手,并不习惯使用非常少的程序存储器(在这种情况下为16kB).我希望能够创建全局变量,数组和函数,我可以从程序中的任何位置访问,而只存在于内存中的一个位置.我目前的方法是使用静态类成员和方法,我可以通过简单地包含头文件(例如#include "spi.h")来使用.
对于我正在尝试做的事情,最好的方法是什么?
这是一个示例类.根据我的理解,_callback像call().cpp 这样的变量和函数定义只会出现在spi.o中,因此它们只会在内存中出现一次,但我可能会混淆.
spi.h中:
#ifndef SPI_H_
#define SPI_H_
#include "msp430g2553.h"
class SPI {
public:
typedef void (*voidCallback)(void);
static voidCallback _callback;
static char largeArray[1000];
static __interrupt void USCIA0TX_ISR();
static void call();
static void configure();
static void transmitByte(unsigned char byte, voidCallback callback);
};
#endif /* SPI_H_ */
Run Code Online (Sandbox Code Playgroud)
SPI.CPP:
#include "spi.h"
SPI::voidCallback SPI::_callback = 0;
char SPI::largeArray[] = /* data */ ;
void SPI::configure() {
UCA0MCTL = 0;
UCA0CTL1 &= ~UCSWRST; …Run Code Online (Sandbox Code Playgroud) 我试图找到答案,但没有找到任何有效的方法.我正在尝试创建一类静态方法,因此我可以传入一个函数指针,SPI::transmitData()以便稍后调用SPI::call().但是,我收到一个错误:
未解析的符号SPI :: mycallback,首先在./spi.obj中引用
spi.h中:
#ifndef SPI_H_
#define SPI_H_
#include "msp430g2553.h"
class SPI {
public:
typedef void (*foo)(void);
static foo mycallback;
static void transmitData(unsigned char data, foo callback);
static void call();
};
#endif /* SPI_H_ */
Run Code Online (Sandbox Code Playgroud)
SPI.CPP:
#include "spi.h"
void SPI::transmitData(unsigned char data, foo callback) {
mycallback = callback; // causes error
UCA0TXBUF = data;
}
void SPI::call() {
//SPI::mycallback();
}
Run Code Online (Sandbox Code Playgroud)
我一直试图摆弄它,当我评论我标记的线时,错误就消失了.不知道发生了什么事.