我对上一期的问题提供了非常有用的提示,我希望这次不会有所不同:)首先,让我解释一下情况.我有一个有2个片段的活动.对于每个片段,我有一个xml菜单布局,第一个有四个菜单项,第二个只有一个.现在首先加载具有四个菜单条目的片段.在我设置的onCreate方法中
this.setHasOptionsMenu(true);
Run Code Online (Sandbox Code Playgroud)
onCreateOptionsMenu方法
@Override
public void onCreateOptionsMenu (Menu menu, MenuInflater inflater) {
super.onCreateOptionsMenu(menu, inflater);
inflater.inflate(R.menu.menu_fragshow, menu);
}
Run Code Online (Sandbox Code Playgroud)
xml文件如下所示:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/menu_refresh"
android:icon="@drawable/ic_action_search"
android:title="Refresh"
android:visible="true"
android:showAsAction="ifRoom|withText" />
<item android:id="@+id/menu_clearall"
android:icon="@drawable/ic_action_search"
android:title="Clear"
android:visible="true"
android:showAsAction="ifRoom|withText" />
<item android:id="@+id/menu_addcontent"
android:icon="@drawable/ic_action_search"
android:title="Add Content"
android:visible="true"
android:showAsAction="ifRoom|withText" />
<item android:id="@+id/menu_newlist"
android:icon="@drawable/ic_action_search"
android:title="New List"
android:visible="true"
android:showAsAction="ifRoom|withText" />
</menu>
Run Code Online (Sandbox Code Playgroud)
这很好用.所有菜单项都在那里,我可以点击它们并回复.现在,当我单击"添加内容"菜单时,将加载另一个片段.我也在那里设定
this.setHasOptionsMenu(true);
Run Code Online (Sandbox Code Playgroud)
onCreateOptionsMenu方法
@Override
public void onCreateOptionsMenu (Menu menu, MenuInflater inflater) {
Log.i("FragCreateList","onCreateOptionsMenu called");
super.onCreateOptionsMenu(menu, inflater);
inflater.inflate(R.menu.menu_fragcreatelist, menu);
}
Run Code Online (Sandbox Code Playgroud)
xml文件
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item …
Run Code Online (Sandbox Code Playgroud) 我有一个带有自定义适配器的ListView,显示来自数据库的信息.当我启动应用程序时,数据将从数据库中读取,并提供给适配器,然后将适配器附加到ListView.在ListView上运行LayoutAnimationController,平滑地显示内容.
this._lvList = (ListView)_v.findViewById(R.id.lvList);
this._lvList.setAdapter(new TableAdapter(getActivity(),R.layout.tablerow,Category.getCategories()));
LayoutAnimationController lac = new LayoutAnimationController(AnimationUtils.loadAnimation(getActivity(), R.anim.slide_in_left));
lac.setDelay(0.2f);
this._lvList.setLayoutAnimation(lac);
this._lvList.startLayoutAnimation();
Run Code Online (Sandbox Code Playgroud)
没问题.
现在,当我单击ListView的任何条目时,未单击的条目将消失,单击的条目将成为列表中唯一的条目,并按预期显示在顶部.
View v;
for(int i = 0;i<_lvList.getChildCount();i++) {
v = this._lvList.getChildAt(i);
if(v!=clickedView) {
Animation animSlideOut = AnimationUtils.loadAnimation(getActivity(), i%2==0?R.anim.slide_out_left:R.anim.slide_out_right);
animSlideOut.setStartOffset(i*50);
// some more stuff
}
v.startAnimation(animSlideOut);
}
Run Code Online (Sandbox Code Playgroud)
这也有效,但现在问题是,如果我再次单击该单个列表条目,我希望列表重新填充,再次显示所有项目.
我认为我可以从一开始就使用代码(第一个代码段),因为它在启动应用程序时工作正常,但是......这次......它没有.没有动画发生.原因是,我的ListView中没有动画视图(除了上一步中的动画).
而不是创建一个新的Tableadapter我已经尝试清除它,填写新的,称为notifyDataSetChanged()...没有用,因为
_lvList.getChildCount();
Run Code Online (Sandbox Code Playgroud)
stills返回1个视图,而适配器包含所有18个条目.我也试过了
requestLayout();
forceLayout();
invalidate();
invalidateViews();
Run Code Online (Sandbox Code Playgroud)
强制ListView在动画之前生成其子视图,但它不起作用.因此,在我调用布局动画之后,ListView会立即出现.
简介:我的ListView在布局动画开始之前不包含子视图,如何强制它生成它们?
Thx提前:)
我有一个为我处理输入的视图,我弹出一个键盘并将视图设置为可聚焦。现在我可以得到某些按键...
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_DEL) {
} else if (keyCode == KeyEvent.KEYCODE_BACK) {
} else if (keyCode == KeyEvent.KEYCODE_ENTER) {
} else {
}
}
Run Code Online (Sandbox Code Playgroud)
等等......我通过使用得到的角色
event.getDisplayLabel()
Run Code Online (Sandbox Code Playgroud)
只要我只想要普通的字母 AZ,就可以工作。在其他语言中,通过长按软键盘上的普通字母可以访问更多字母……但是,onKeyDown/Up 无法检测到这些替代字母。我只能检测正常的字母,软键盘的标签。现在我的应用程序必须处理外国输入和字母,我已将键盘更改为土耳其语,我可以在键盘上找到 í ì ú ù 之类的字母,但是如果我按下它们,则没有任何反应。不是 event.getDisplayLabel 也不是 event.getUnicodeChar(); 我如何检测这些字母?
只需将iOS 5应用程序更新到iOS 6,当然偶然发现了界面问题.我现在已经知道事情发生了变化,我甚至知道发生了什么变化,但我似乎无法自己管理.
我的应用程序包含几个viewcontrollers,它们被推送到一个navigationcontroller.所有的viewcontrollers都应该是横向的,除了一个应该是纵向的.在iOS 5中,一切工作正常,但现在纵向模式下的一个控制器也以横向模式显示,当然也会失真.
我的iOS 5代码看起来像这样:
Viewcontroller在横向模式下:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{
return (interfaceOrientation==UIInterfaceOrientationLandscapeLeft) || (interfaceOrientation==UIInterfaceOrientationLandscapeRight);
}
Run Code Online (Sandbox Code Playgroud)
Viewcontroller处于纵向模式:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{
return (interfaceOrientation==UIInterfaceOrientationPortrait) || (interfaceOrientation==UIInterfaceOrientationPortraitUpsideDown);
}
Run Code Online (Sandbox Code Playgroud)
现在我发现了我实施的iOS 6中的变化
AppDelegate :(允许所有方向,如在plist中)
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window{
return UIInterfaceOrientationMaskLandscapeLeft|UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown;
}
Run Code Online (Sandbox Code Playgroud)
横向模式下的Viewcontroller :(将方向限制为横向模式)
- (NSUInteger) supportedInterfaceOrientations{
return UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight
}
-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
return UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight;
}
- (BOOL)shouldAutorotate{
return YES;
}
Run Code Online (Sandbox Code Playgroud)
纵向模式下的Viewcontroller :(将方向限制为纵向模式)
- (NSUInteger) supportedInterfaceOrientations {
return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown;
}
-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
return UIInterfaceOrientationPortrait | UIInterfaceOrientationPortraitUpsideDown;
}
- …
Run Code Online (Sandbox Code Playgroud)