我创建了一种方法来检查键盘是否在带有editText:searchfield的activity(tab)中使用。每当我离开活动(选项卡)并切换到另一个活动时,我都想关闭键盘。因此,我在onStop()中调用该方法。但是什么也没发生,为什么这不起作用,对onStop()在Android中如何工作有更多见解的人呢?我该如何运作?/非常感谢!
@Override
protected void onStop()
{
super.onStop();
this.hideKeyboard(); <----------------------
if(this.data != null)
{
this.data.destroy();
}
}
private void hideKeyboard()
{
if (this.searchField != null)
{
InputMethodManager imm = (InputMethodManager) getSystemService(Activity.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(this.searchField.getWindowToken(), 0);
}
}
Run Code Online (Sandbox Code Playgroud) 我尝试在listView中为书签功能创建一个带有3个标签,名称,书籍和章节的自定义UIView.现在我希望标签在tableView的单元格中位于不同的行中.如果您查看下面的代码,哪种方法最好,或者如何在自己的行上制作标签?我是Objective C和Iphone开发的新手.
结果在每个单元格的列表中应如下所示:
--------
name
book
chapter
--------
Run Code Online (Sandbox Code Playgroud)
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"BookmarkCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
Bookmark *item = [self.items objectAtIndex:indexPath.row];
NSArray *chunks = [item.name componentsSeparatedByString: @","];
NSString *name;
NSString *book;
NSString *chapter;
if ([chunks count] > 0)
{
name = [chunks objectAtIndex:0];
if ([chunks count] > 1)
{
book = [chunks objectAtIndex:1];
if ([chunks count] > 2)
{ …Run Code Online (Sandbox Code Playgroud)