当我得到偏好时,有什么区别:
PreferenceManager.getDefaultSharedPreferences(getBaseContext());
Run Code Online (Sandbox Code Playgroud)
和
getPreferences(Context.MODE_PRIVATE);
Run Code Online (Sandbox Code Playgroud) 为什么费率不适用于USPS?我正在使用ratev4,我收到一个错误:
错误:
API Authorization failure. RateV4 is not a valid API name for this protocol.
UspsCom::DoAuth
Run Code Online (Sandbox Code Playgroud)
这是我的代码:
<?php
$devurl = "testing.shippingapis.com/ShippingAPITest.dll";
$puburl = "https://secure.shippingapis.com/ShippingAPITest.dll";
$service = "RateV4";
$userid = "690DEVBL1739";
$xml = rawurlencode('<RateV4Request USERID="xxxxx">
<Revision/>
<Package ID="1ST">
<Service>FIRST CLASS</Service>
<FirstClassMailType>LETTER</FirstClassMailType>
<ZipOrigination>44106</ZipOrigination>
<ZipDestination>20770</ZipDestination>
<Pounds>1</Pounds>
<Ounces>0.0</Ounces>
<Container/>
<Size>REGULAR</Size>
<Machinable>true</Machinable>
</Package>
</RateV4Request>');
$request = $devurl . "?API=" . $service . "&xml=" . $xml;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $request);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_HTTPGET, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
echo …Run Code Online (Sandbox Code Playgroud) 我写了一个程序,可以总结如下:
def loadHugeData():
#load it
return data
def processHugeData(data, res_queue):
for item in data:
#process it
res_queue.put(result)
res_queue.put("END")
def writeOutput(outFile, res_queue):
with open(outFile, 'w') as f
res=res_queue.get()
while res!='END':
f.write(res)
res=res_queue.get()
res_queue = multiprocessing.Queue()
if __name__ == '__main__':
data=loadHugeData()
p = multiprocessing.Process(target=writeOutput, args=(outFile, res_queue))
p.start()
processHugeData(data, res_queue)
p.join()
Run Code Online (Sandbox Code Playgroud)
真正的代码(特别是writeOutput())要复杂得多.writeOutput()仅使用它作为参数的这些值(意味着它不引用data)
基本上它将一个巨大的数据集加载到内存中并对其进行处理.输出的写入被委托给一个子进程(它实际写入多个文件,这需要花费很多时间).因此,每次处理一个数据项时,它都会通过res_queue发送到子进程,res_queue会根据需要将结果写入文件.
子进程不需要以loadHugeData()任何方式访问,读取或修改加载的数据.子流程只需要使用主流程发送它的内容res_queue.这引出了我的问题和疑问.
在我看来,子流程将它放在庞大数据集的副本上(当检查内存使用情况时top).这是真的?如果是这样,我怎么能避免id(基本上使用双内存)?
我使用的是Python 2.6,程序在linux上运行.
我在Groovy中制作一个Text Adventure游戏作为一种练习,我遇到了一个奇怪的错误.
现在,我有enum一个玩家能够前往的方向,目前包含北,南,东,西,上和下.
我有一个Room课程,其中包含Map其他连通房间及其方向.当我在某个时候添加Room到另一个Room时Direction,我希望能够在相反的方向上将电流添加Room到另一个.Room
例如:如果我将房间1到房间2的连接添加到北方,我希望能够同时从房间2到房间1添加连接.
目前,我正在尝试使用带有附加实例变量(类型)的enum命名来实现它.这是不允许的?我没有得到编译器错误或任何东西,但我似乎无法让它工作.DirectionoppositeDirection
这是完整的enum声明:
public enum Direction {
North(South), South(North), East(West), West(East), Up(Down), Down(Up)
private Direction opposite
Direction(Direction d){
opposite = d
}
public opposite(){
return opposite
}
}
Run Code Online (Sandbox Code Playgroud)
这是我从以下方法调用它的方法:
public void addConnection(Direction d, Spot spot){
connections[d] = spot
spot.connections[d.opposite()] = this
}
Run Code Online (Sandbox Code Playgroud)
这里connections是一个public Map<Direction, Spot>.
在这种情况下,会添加一个条目 …
我正在使用我们的代码库来解决一些依赖性问题.
但是每当我点击任何包中的build.xml文件时,我都会得到
"Target XXX does not exist in the project" error.
Run Code Online (Sandbox Code Playgroud)
有趣的是build.xml文件显示没有任何错误,如果我保持其中的任何一个不触动,但如果我点击打开其中任何一个,我会遇到这些错误.以下是一些示例:
<target name="javadoc" depends="compile-jar">
<target name="release" depends="standard-release" description="PackageBuilder entry point"/>
Run Code Online (Sandbox Code Playgroud)
我得到了所有目标的错误.不幸的是,我不能在论坛上发布很多代码,但我希望有任何建议可以带我走向正确的方向.如果有什么我没有提到的请告诉我,我可以添加它.
另外,我不太清楚整个build.xml和其他ANT的工作原理.我知道在http://ant.apache.org上有很好的帮助但我需要一些博客/书籍/图表/流程图来解释这是如何工作的,以及在文档开始有意义之前如何更容易地用Java解决构建依赖性.有帮助吗?
谢谢.
我需要从设备及其电话号码中获取所有联系人的明确列表.但是等等......我们知道某些联系人可能分配了多个号码,这完全取决于每个用户如何存储他的联系人.这是我做的:
ContentResolver cr = context.getContentResolver();
Uri uri = ContactsContract.Contacts.CONTENT_URI;
String[] projection = new String[] { ContactsContract.Contacts._ID, ContactsContract.Contacts.DISPLAY_NAME };
String selection = ContactsContract.Contacts.HAS_PHONE_NUMBER + " = '1'";
String sortOrder = ContactsContract.Contacts.DISPLAY_NAME + " COLLATE LOCALIZED ASC";
ArrayList<user> contacts = new ArrayList<user>();
Cursor users = a.managedQuery(uri, projection, selection, null, sortOrder);
while (users.moveToNext()) {
user u = new user();
u.PhoneId = users.getInt(users.getColumnIndex(ContactsContract.Contacts._ID));
u.Name = users.getString(users.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
String homePhone = "", cellPhone = "", workPhone = "", otherPhone = "";
Cursor contactPhones = cr.query(Phone.CONTENT_URI, null, …Run Code Online (Sandbox Code Playgroud) 我正在尝试做类似Android平板电脑中的设置首选项.
当我单击"更多"时,右侧片段上显示"无线和网络"首选项屏幕,而如果我触摸"VPN",则在同一片段中打开"VPN"首选项屏幕.
我怎样才能做到这一点 ?
这是我的偏好xml
<PreferenceScreen android:title="Title A">
<PreferenceScreen android:title="TITLE B">
<PreferenceCategory
android:title="category">
<ListPreference android:key="list"
android:title="list" android:entries="@array/list_vals"
android:entryValues="@array/list_vals1"
android:defaultValue="1" android:dialogTitle="list title"
android:negativeButtonText="cancel" />
</PreferenceCategory>
</PreferenceScreen>
</PreferenceScreen>
Run Code Online (Sandbox Code Playgroud)
问题是我不希望在整个屏幕上加载带有标题B的嵌套首选项屏幕我只想加载到正确的片段...
注意:到目前为止,我使用此文档创建了我的示例http://developer.android.com/guide/topics/ui/settings.html#PreferenceHeaders


编辑*
这是我的活动
public class SettingsActivity extends PreferenceActivity {
@Override
public void onBuildHeaders(List<Header> target) {
loadHeadersFromResource(R.xml.preference_headers, target);
}
}
Run Code Online (Sandbox Code Playgroud)
我没有布局,所以我怎么知道我的主片段ID是什么,我的细节片段ID是什么?
android preferenceactivity android-preferences android-fragments
我正在尝试构建一个实现Queue和的类Map.两个接口都定义了remove(Object)方法,但具有不同的返回类型:
public interface Collection<E> { //Queue extends Collection, which has the problem method
public boolean remove(Object e);
//...
}
public interface Map<K,V> {
public V remove(K key);
//...
}
public class QueuedMap<K,V> extends AbstractMap implements Queue {
public V remove(K key) {/* ... */}
//ERROR: V is not compatible with boolean
//...
}
Run Code Online (Sandbox Code Playgroud)
K的类型擦除导致这两个方法签名发生冲突.我不能拥有其中一个,因为它是一个无效的覆盖,我不能同时拥有它们,因为它们具有相同的签名.有什么办法可以让这两个接口共存吗?
我见过这样的事情:
<PreferenceCategory xmlns:android="http://schemas.android.com/apk/res/android"
android:key="vegi_category" android:title="Vegetables"
android:summary="Preferences related to vegetable"> <!-- Why is this here? -->
<CheckBoxPreference android:key="tomato_selection_pref"
android:title="Tomato " android:summary="It's actually a fruit" />
<CheckBoxPreference android:key="potato_selection_pref"
android:title="Potato" android:summary="My favorite vegetable" />
</PreferenceCategory>
Run Code Online (Sandbox Code Playgroud)
但我不明白为什么pref类别有一个汇总字段:
(android:summary="Preferences related to vegetable")?
当我使用pref屏幕时,摘要会显示在视图中,但这不是pref类别的情况.在pref类别中存在摘要只是它的一个约定可以用某种方式看出来吗?
pref类别元素中摘要的实际用法是什么?
为什么我们this在Android中使用关键字和方法名称来从同一个类中的另一个方法调用方法.在Java或C#中,我们可以直接调用其他方法而不使用this关键字,如下面的代码所示.
public final String getElementValue( Node elem )
{
Node child;
if( elem != null)
{
if (elem.hasChildNodes())
{
for( child = elem.getFirstChild(); child != null; child = child.getNextSibling() )
{
if( child.getNodeType() == Node.TEXT_NODE )
{
return child.getNodeValue();
}
}
}
}
return "";
}
/**
* Getting node value
* @param Element node
* @param key string
* */
public String getValue(Element item, String str)
{
NodeList n = item.getElementsByTagName(str);
return this.getElementValue(n.item(0));
}
Run Code Online (Sandbox Code Playgroud)