我正在寻找一个可搜索的动作栏.我遇到了一个问题,即操作栏不会对可搜索的活动做出反应.就是这样,我在动作栏的可搜索文本中输入了一些东西,然后点击了提交但没有发生任何事情.调试跟踪显示我的searchresultactivity中的代码永远不会执行.所以我想知道可搜索的配置是否有问题.那么这一次我认为我已经清楚地解释了这个问题,我不期待任何负面的投票,没有任何言语甚至吐!
我按照开发人员文档的说明开始使用manifest.xml,在searchresult活动中添加了元数据:
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:name=".GermanDictionaryActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".SearchResultsActivity">
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
</intent-filter>
<meta-data android:name="android.app.searchable"
android:resource="@xml/searchable" />
</activity>
</application>
Run Code Online (Sandbox Code Playgroud)
然后我用我的菜单初始化了searchview:
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.srhbar, menu);
// Get the SearchView and set the searchable configuration
SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
mSrhView = (SearchView) menu.findItem(R.id.search).getActionView();
mSrhView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
mSrhView.setSubmitButtonEnabled(true);
return true;
}
Run Code Online (Sandbox Code Playgroud)
菜单中可搜索的项目:
<item android:id="@+id/search"
android:title="@string/srh_title"
android:showAsAction="collapseActionView|ifRoom"
android:actionViewClass="android.widget.SearchView" />
Run Code Online (Sandbox Code Playgroud)
任何相关的答案表示赞赏!
我正在处理APUE的问题,以某种方式编写一个程序,如cp来复制文件(第4章问题4.6).如果文件中包含孔(或稀疏文件),则间隙中的\ 0将永远不会被处理.理想的方法是逐块读写,其大小由lseek(fd,current_off,SEEK_HOLE)决定.我以/ bin/ls为例.但是evertime我lseek这个文件(或其他文件)文件的偏移总是设置为文件的末尾.我查过这篇文章,但似乎没有令人满意的答案.这是我的代码:
#include <stdio.h>
/* and other headers */
int main(void) {
int fd;
off_t off;
fd = open("/bin/ls", O_RDONLY);
if ((off = lseek(fd, 0, SEEK_HOLE) == -1)
exit(-1);
printf("%d\n", off);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我的内核是linux 3.13.0-rc3从最新的稳定树中拉出来的,我的fs是ext4.如果lseek不可用,将任何'\ 0'视为洞的开头是否合适?谢谢你的回答.