我试图从一个片段绑定一个服务,就像我在一个活动中成功完成一样,但是当我尝试在服务上调用一个方法时,我得到一个NullPointerException - 显然是因为该服务为null.现在在onStart中绑定到服务有一些问题,或者我只是做错了?
@Override
public void onStart() {
super.onStart();
Intent intent = new Intent(getActivity(), LiteTrickService.class);
getActivity().registerReceiver(receiver, new IntentFilter(LiteTrickService.BROADCAST_ACTION));
getActivity().registerReceiver(receiver, new IntentFilter(LiteTrickService.BROADCAST_FAIL));
getActivity().bindService(intent, mConnection, Context.BIND_AUTO_CREATE);
}
@Override
public void onStop() {
super.onStop();
getActivity().unbindService(mConnection);
getActivity().unregisterReceiver(receiver);
mBound = false;
}
Run Code Online (Sandbox Code Playgroud)
编辑:抱歉.这是我没有充分考虑这个问题的错误.mConnection是一个ServiceConnection,如下所示:
private ServiceConnection mConnection = new ServiceConnection()
{
@Override
public void onServiceConnected(ComponentName className,
IBinder service) {
// We've bound to LocalService, cast the IBinder and get LocalService instance
LocalBinder binder = (LocalBinder) service;
mService = binder.getService();
mBound = true;
}
@Override
public …Run Code Online (Sandbox Code Playgroud) 是否可以在(基于窗口的)iPhone应用程序中创建多个视图或窗口?
我有一个PreferenceActivity,其中包括一个包含呼叫前转选项的类别.我想要的是偏好:
它可能没有任何用处,但这里有一个特殊偏好类别的片段:
<PreferenceCategory
android:title="@string/category_callforward">
<EditTextPreference
android:key="call_forward_always"
android:title="@string/call_forward_always"
android:summary="@string/call_forward_forwardto" />
</PreferenceCategory>
Run Code Online (Sandbox Code Playgroud)
编辑
如果可能的话,我想在这个方法中实现它:
// Locates the correct data from saved preferences and sets input type to numerics only
private void setCallForwardType()
{
ep1 = (EditTextPreference) findPreference("call_forward_always");
EditText et = (EditText) ep1.getEditText();
et.setKeyListener(DigitsKeyListener.getInstance());
}
Run Code Online (Sandbox Code Playgroud)
EDIT2
如果有人还在想 - 这就是我想要的偏好:

EDIT3
我现在已经搜索了几个小时,并提出了一个单词:'PreferenceGroupAdapter'.但是,我没有找到示例或教程向我展示如何使用它.建议?这甚至是正确的道路吗?
EDIT4
如果这真的不可能,我非常希望我可以实现的替代(用户友好)解决方案的建议,而不是组合的Edit-和Checkbox偏好.
我在Expression Blend中定义了以下两种状态.我一直在努力遵循这个指南,但是当我需要有关如何以及何时改变状态的信息时,我觉得这让我感到不知所措.

根据指南,我要附加一个行为(我假设"GotoState")给我UserControl- 不幸的是我不认为我实际上有User Control- 而且即使我这样做,我是否必须对我PortraitState和我的行为都附加行为LandscapeState?
看来我可以附加一个GotoState我的LayoutRoot元素.那么我是否将这种行为与两种状态中的行为联系起来?任何帮助将不胜感激.
*编辑:我正在我的xaml.cs文件中玩,并认为这可能是以编程方式执行此操作的方法.调试和更改方向时,我进入开关盒并找到正确的方向.然而,国家从未切换过.我究竟做错了什么?
protected override void OnOrientationChanged(OrientationChangedEventArgs e)
{
switch (e.Orientation)
{
case PageOrientation.Landscape:
ExtendedVisualStateManager.GoToElementState(root:this.LayoutRoot, stateName: "LandscapeState", useTransitions: true);
break;
case PageOrientation.LandscapeRight:
ExtendedVisualStateManager.GoToElementState(root:this.LayoutRoot, stateName: "LandscapeState", useTransitions: true);
break;
case PageOrientation.LandscapeLeft:
ExtendedVisualStateManager.GoToElementState(root:LayoutRoot, stateName: "LandscapeState", useTransitions: true);
break;
case PageOrientation.Portrait:
ExtendedVisualStateManager.GoToElementState(root:this.LayoutRoot, stateName: "PortraitState", useTransitions: true);
break;
case PageOrientation.PortraitUp:
ExtendedVisualStateManager.GoToElementState(root:this.LayoutRoot, stateName: "PortraitState", useTransitions: true);
break;
case PageOrientation.PortraitDown:
ExtendedVisualStateManager.GoToElementState(root:this.LayoutRoot, stateName: "PortraitState", useTransitions: true);
break;
default: …Run Code Online (Sandbox Code Playgroud) 我在第三天和Protractor一起工作时,我经常会在等待页面加载和元素出现方面碰到金砖墙.特别是这个测试案例变得丑陋,我想解决问题而不必依赖睡眠.
我目前"在AngularJS之外"
it('it should reflect in both the field and the title when the personnel name is changed', function() {
var inputField, personnelHeader, personnelName;
personnelName = element(By.css(".overlay.editnameoverlay")).click();
personnelHeader = element(By.id("personnel_name_header"));
inputField = element(By.css("input[name='newvalue']"));
inputField.clear();
inputField.sendKeys("Test 123");
element(By.css("input[name='ok_button']")).click();
// browser.driver.sleep(2000); This test only works with this sleep added
browser.wait(function() {
console.log("Waiting for header to change...");
return personnelHeader.getText().then(function(text) {
return text === "Test 123";
});
}, 5000);
return expect(personnelHeader.getText()).toBe(personnelName.getText());
});
Run Code Online (Sandbox Code Playgroud)
因此,此处的测试会更改输入字段中的名称.提交它并等待更改反映在模态的标题中.问题是如果没有browser.driver.sleep(2000),我会收到错误消息
Stacktrace:
StaleElementReferenceError: stale element reference: element is not attached to the …Run Code Online (Sandbox Code Playgroud) 编辑:似乎我没有说清楚.我需要的是一种隐藏软键盘的方法,每当我更换我所在的片段时.我该怎么做呢?
让我保持这个简单.我在Tab Fragment 1.2中有一个EditText框,显然在按下时会打开软键盘.更改选项卡时如何隐藏?我在我的onTabSelected()中尝试了以下操作,它似乎没有做任何事情
getWindow().setSoftInputMode(
WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
Run Code Online (Sandbox Code Playgroud)
我现在已经尝试了一切.到目前为止,我所提出的解决方案都没有以任何方式帮助我.
我有一个对象数组,我希望通过一些分组属性数据和一个字符串告诉我要分组的属性(例如:'Organization'或'Organization.Name')
我需要编写一个函数,它接收看起来像beforeData并返回的数据afterData
输入:
beforeData = [
{'name':'John Doe', 'Id':1, 'Organizations':[{'Id':12, 'LongName': 'Group A'},{'Id':13, 'LongName': 'Group B'}]},
{'name':'FooBar', 'Id':2, 'Organizations':[{'Id':13, 'LongName': 'Group B'},{'Id':14, 'LongName': 'Group C'}]},
{'name':'Kristine Bell', 'Id':3, 'Organizations':[{'Id':12, 'LongName': 'Group A'}]},
{'name':'Adrian P', 'Id':4, 'Organizations':[{'Id':12, 'LongName': 'Group A'}]}
]
Run Code Online (Sandbox Code Playgroud)
输出:
afterData = [
{
'Group': 'Group A',
'entities':[
{'name':'Adrian P', 'Id':4, 'Organizations':[{'Id':12, 'LongName': 'Group A'}]},
{'name':'Kristine Bell', 'Id':3, 'Organizations':[{'Id':12, 'LongName': 'Group A'}]},
{'name':'John Doe', 'Id':1, 'Organizations':[{'Id':12, 'LongName': 'Group A'},{'Id':13, 'LongName': 'Group B'}]}]
},
{
'Group': 'Group …Run Code Online (Sandbox Code Playgroud) 我有一个应用程序,我想根据从Web服务检索的值设置特定SeekBar的进度.但是当我使用SetProgress(int)时,只有SeekBar的"seeker"被设置.酒吧没有按预期"填满".
这就是它的样子:

有关如何解决此问题的任何想法?
每当我旋转手机或按主页按钮时,应用程序就会崩溃,并且出现以下异常:
11-25 22:17:23.855: E/AndroidRuntime(5033): FATAL EXCEPTION: main
11-25 22:17:23.855: E/AndroidRuntime(5033): java.lang.RuntimeException: Unable to stop activity {com.liteapps.handin_3/com.liteapps.handin_3.MainActivity}: java.lang.IllegalArgumentException: Service not registered: com.liteapps.handin_3.MainActivity$2@42116cf0
11-25 22:17:23.855: E/AndroidRuntime(5033): at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:3363)
11-25 22:17:23.855: E/AndroidRuntime(5033): at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:3417)
11-25 22:17:23.855: E/AndroidRuntime(5033): at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:3615)
11-25 22:17:23.855: E/AndroidRuntime(5033): at android.app.ActivityThread.access$700(ActivityThread.java:142)
11-25 22:17:23.855: E/AndroidRuntime(5033): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1214)
11-25 22:17:23.855: E/AndroidRuntime(5033): at android.os.Handler.dispatchMessage(Handler.java:99)
11-25 22:17:23.855: E/AndroidRuntime(5033): at android.os.Looper.loop(Looper.java:137)
11-25 22:17:23.855: E/AndroidRuntime(5033): at android.app.ActivityThread.main(ActivityThread.java:4931)
11-25 22:17:23.855: E/AndroidRuntime(5033): at java.lang.reflect.Method.invokeNative(Native Method)
11-25 22:17:23.855: E/AndroidRuntime(5033): at java.lang.reflect.Method.invoke(Method.java:511)
11-25 22:17:23.855: E/AndroidRuntime(5033): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
11-25 22:17:23.855: E/AndroidRuntime(5033): …Run Code Online (Sandbox Code Playgroud) 我有一个片段,我希望从包含这个片段的FragmentActivity中调用一个方法.我在FragmentTabs(扩展FragmentActivity)中定义了一个方法,该方法在片段中的特定事件上设置lastTab片段.由于某种原因,getActivity().SomeUserDefinedActivity()无法解析.
这是解释我的问题的代码:
@Override
public void onActivityCreated(Bundle savedInstanceState)
{
super.onActivityCreated(savedInstanceState);
testButton = (Button)getView().findViewById(R.id.button1);
testButton.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v)
{
Log.i("FragmentTest", "Button1 Clicked");
TestFragment2 f2 = new TestFragment2();
FragmentTransaction ft = getActivity().getSupportFragmentManager().beginTransaction();
ft.replace(R.id.realtabcontent, f2);
ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
ft.addToBackStack(null);
ft.commit();
// This is where I want to call FragmentTabs method SetLastFragment, but I cannot access it.
getActivity().SetLastFragment(f2);
}
});
}
Run Code Online (Sandbox Code Playgroud)
这是我想在FragmentTabs中调用的方法:
public void SetLastFragment(Fragment f)
{
mTabManager.SetLastTabFragment(f);
}
Run Code Online (Sandbox Code Playgroud) 虽然我很清楚我无法在onClick方法中引用非final变量,但我很想知道如何解决我目前面临的问题.
我有一个ArrayAdapter.如果用户按下AsyncTask复选框,则用户可以订阅或取消订阅队列,具体取决于是否选中该复选框.
我希望此状态反映在我的txtStatus TextView文本中的每个项目中.如何根据复选框的状态设置TextView的文本?
以下是我的getView方法代码的一部分:
@Override
public View getView(int position, View convertView, ViewGroup parent)
{
View row = convertView;
final CheckBox queueCBox;
userControl = new UserController(context);
final String queueName = data[position].label;
if(row == null)
{
LayoutInflater inflater = ((Activity)context).getLayoutInflater();
row = inflater.inflate(layoutResourceId, parent, false);
final QueueHolder holder = new QueueHolder();
holder.queuecbox = (CheckBox)row.findViewById(R.id.queues_item_checkbox);
queueCBox = (CheckBox)row.findViewById(R.id.queues_item_checkbox);
holder.txtLabel = (TextView)row.findViewById(R.id.queues_item_label);
holder.txtStatus = (TextView)row.findViewById(R.id.queues_item_status);
holder.queuecbox.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v)
{
final String[] param = new String[1];
param[0] = queueName; …Run Code Online (Sandbox Code Playgroud) android ×7
javascript ×2
angularjs ×1
c# ×1
cocoa-touch ×1
ios ×1
iphone ×1
objective-c ×1
protractor ×1
seekbar ×1
sorting ×1