我有一个带有自动完成框的活动.每当文本更改时,我想调用Web服务并使用返回的新String []填充ArrayAdapter.这部分一切都很好,除了在String []学校中有所有新值时UI中的列表没有被刷新.我的onCreate中填充的原始列表始终保留.
我在某个地方读到了我需要在运行UI的同一个线程上更新它,所以我尝试了下面代码中列出的Runnable.但是,只是更新我的类变量学校并不与notifyOnDataSetChange()一起工作
我哪里错了?
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
schools = SchoolProxy.search("Co");
autoCompleteAdapter = new ArrayAdapter(this,android.R.layout.simple_dropdown_item_1line, schools);
autoComplete = (AutoCompleteTextView) findViewById(R.id.edit);
autoComplete.addTextChangedListener(textChecker);
autoComplete.setAdapter(autoCompleteAdapter);
}
...
....
...
final TextWatcher textChecker = new TextWatcher() {
public void afterTextChanged(Editable s) {}
public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
public void onTextChanged(CharSequence s, int start, int before, int count)
{
schools = SchoolProxy.search(s.toString());
runOnUiThread(updateAdapter);
}
};
private Runnable updateAdapter = new Runnable() {
public void …Run Code Online (Sandbox Code Playgroud) 据我所知,为字典添加值的方法如下.
Dictionary<string, string> myDict = new Dictionary<string, string>();
myDict.Add("a", "1");
Run Code Online (Sandbox Code Playgroud)
如果我将"myDictDict"声明为下面的样式.
IDictionary<string, Dictionary<string, string>> myDictDict = new Dictionary<string, Dictionary<string, string>>();
myDictDict .Add("hello", "tom","cat"); ?// How to add value here.
Run Code Online (Sandbox Code Playgroud)
谢谢.
到目前为止,我一直在尝试使用php更新twitter配置文件bg图像,并且没有成功
网上有很多例子,包括这一个:
通过API更新Twitter背景,
以及这个
带有API和多表格数据的Twitter背景上传
根本不起作用,大多数人在没有实际测试代码的情况下抛出答案.
我发现直接将图像提交到twitter.com的thr html表单,它会起作用:
<form action="http://twitter.com/account/update_profile_background_image.xml" enctype="multipart/form-data" method="post">
File: <input type="file" name="image" /><br/>
<input type="submit" value="upload bg">
</form>
Run Code Online (Sandbox Code Playgroud)
(虽然浏览器会提示您输入Twitter帐户的用户名和密码)
但是,如果我想用php进行相同的处理,它就会失败
<?php
if( isset($_POST["submit"]) ) {
$target_path = "";
$target_path = $target_path . basename( $_FILES['myfile']['name']);
if(move_uploaded_file($_FILES['myfile']['tmp_name'], $target_path)) {
// "The file ". basename( $_FILES['myfile']['name']). " has been uploaded<br/>";
} else{
// "There was an error uploading the file, please try again!<br/>";
}
$ch = curl_init('http://twitter.com/account/update_profile_background_image.xml');
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($ch, CURLOPT_USERPWD, $_POST['name'] . ':' . $_POST['pass']);
curl_setopt($ch, CURLOPT_HTTPHEADER, …Run Code Online (Sandbox Code Playgroud) 如何在css中以不同的方式给出前两个段落的相同样式.
<html>
<head>
<style type="text/css" media="screen">
p+p {color:red}
</style>
</head>
<body>
<p>first paragraph</p>
<p>second paragraph</p>
<p>third paragraph</p>
<p>fourth paragraph</p>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
我已经尝试了这个,但是它会留下第一段和其他所有样式.
而这种风格第一款不是别人的
<html>
<head>
<style type="text/css" media="screen">
p:first-child { color: blue; }
</style>
</head>
<body>
<p>first paragraph</p>
<p>second paragraph</p>
<p>third paragraph</p>
<p>fourth paragraph</p>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
记得我想在前2段给出相同的风格.
我想调用一个函数,当我有一个文本域聚焦,然后不聚焦它(无论我按TAB或用鼠标点击其他地方)我使用此代码:
$("#settings_view #my_profile_div input").focus(function() {
$(this).blur(function() {
change_my_profile();
});
});
Run Code Online (Sandbox Code Playgroud)
当我第一次运行它(有一个聚焦的场然后不聚焦它)它按预期运行一次.但是,它第二次调用函数change_my_profile两次.它第三次运行3次,依此类推.
这是什么问题,如何解决?(我在change_my_profile之后尝试'throw',然后它只运行了一次,但我想找到问题所在.)
昨天关于双重检查锁定的一个问题引发了一连串的想法,让我不确定一个简单的情况.在下面的代码中,是否可以达到printf"不再同步"?在这个简单的例子中,值可能在同一个缓存行上,所以我认为它不太可能(假设开始时可能性> 0%).
如果答案是"不,这是不可能的.",那么我的后续问题是,相当可预见的:为什么不呢?直到昨天我的想法纠结并缠绕在多线程轴上,我认为代码是安全的.但现在我想知道是什么阻止从缓存中读取其中一个变量pa或的变量pb.如果pa, pb指向简单的全局整数变量而不是malloc内存,那会有关系吗?WaitForSingleObject调用是否提供内存屏障?或者指针是否应声明为volatile?这么多问题,句子很少.
更新:我最终找到的信息明确指出,信号同步对象的函数确实使用了内存屏障.应该是显而易见的,但我找不到明确的答案.所以我可以再次欺骗自己相信我理解这一切.
int i1 = 0;
int i2 = 0;
int reads = 0;
int done = 0;
int *pa = NULL;
int *pb = NULL;
HANDLE hSync = NULL;
DWORD WriteThread( LPVOID pvParam )
{
while( !done )
{
WaitForSingleObject( hSync, INFINITE );
(*pa)++;
(*pb)++;
ReleaseSemaphore( hSync, 1, NULL );
}
return 0;
}
DWORD ReadThread( LPVOID pvParam )
{
while( !done )
{
WaitForSingleObject( …Run Code Online (Sandbox Code Playgroud) 我在线查看,无法找到PopupWindow类的工作示例.我在网上找到的代码示例要么编译但是不起作用,要么使用已被删除的方法(例如Activity.getViewInflate()).
是否有一个显示PopupWindow 的简单工作示例?
在提交表单时,我在确定如何禁用rails中的提交按钮时遇到了一些麻烦.它在禁用javascript和'remote_form_for#submit'函数中的':disable_with'符号时工作正常,但在通过ajax提交时无法弄明白.有什么想法吗?使用rails 2.3.5和ruby 1.8.7.