首页 \ 问答 \ AirPlane ToggleButton?(AirPlane ToggleButton?)

AirPlane ToggleButton?(AirPlane ToggleButton?)

我正在尝试使用ToggleButton来打开和关闭AirPlane模式。 我不知道该怎么做。

我的权限是:

<uses-permission android:name="android.permission.WRITE_SETTINGS"/>
<uses-permission android:name="android.permission.WRITE_SECURE_SETTINGS"/>

我的.XML文件如下所示:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView  
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:text="@string/hello"
/>
<ToggleButton  
android:id="@+id/Toggle" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content"
android:textOn="On"
android:textOff="Off">
</ToggleButton>
</LinearLayout>

我的Java有这个用于切换按钮:

AirToggle = (ToggleButton) findViewById(R.id.Toggle);
    AirToggle.setOnClickListener(new OnClickListener(){
        public void onClick(View v){

        if (((ToggleButton)v).isChecked()){
            boolean isEnabled = Settings.System.getInt(context.getContentResolver(),Settings.System.AIRPLANE_MODE_ON, 0) == 1;
            if(isEnabled == false)
            {
            Settings.System.putInt(context.getContentResolver(),Settings.System.AIRPLANE_MODE_ON,1);                                Intent intent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED);
            intent.putExtra("state", 1);
            context.sendBroadcast(intent);
            }

            IntentFilter intentFilter = new IntentFilter("android.intent.action.SERVICE_STATE");

            BroadcastReceiver receiver = new BroadcastReceiver() {
                  @Override
                  public void onReceive(Context context, Intent intent) {
                        Log.d("AirplaneMode", "Service state changed");
                  }
            };

            context.registerReceiver(receiver, intentFilter);


            }

    };
});

}

更新:这是我的日志cat错误,如果这有帮助。

04-19 18:43:24.264: ERROR/AndroidRuntime(233): ERROR: thread attach failed

04-19 18:43:25.933: ERROR/AndroidRuntime(241): ERROR: thread attach failed

04-19 18:43:31.543: ERROR/AndroidRuntime(248): Uncaught handler: thread main exiting due         to uncaught exception

04-19 18:43:31.553: ERROR/AndroidRuntime(248): java.lang.NullPointerException

04-19 18:43:31.553: ERROR/AndroidRuntime(248):     at      com.simple.armor.SimpleArmor$1.onClick(SimpleArmor.java:30)

04-19 18:43:31.553: ERROR/AndroidRuntime(248):     at android.view.View.performClick(View.java:2364)

04-19 18:43:31.553: ERROR/AndroidRuntime(248):     at android.widget.CompoundButton.performClick(CompoundButton.java:98)

04-19 18:43:31.553: ERROR/AndroidRuntime(248):     at android.view.View.onTouchEvent(View.java:4179)

04-19 18:43:31.553: ERROR/AndroidRuntime(248):     at android.widget.TextView.onTouchEvent(TextView.java:6541)

04-19 18:43:31.553: ERROR/AndroidRuntime(248):     at android.view.View.dispatchTouchEvent(View.java:3709)

04-19 18:43:31.553: ERROR/AndroidRuntime(248):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)

04-19 18:43:31.553: ERROR/AndroidRuntime(248):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)

04-19 18:43:31.553: ERROR/AndroidRuntime(248):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)

04-19 18:43:31.553: ERROR/AndroidRuntime(248):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)

04-19 18:43:31.553: ERROR/AndroidRuntime(248):     at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1659)

04-19 18:43:31.553: ERROR/AndroidRuntime(248):     at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1107)

04-19 18:43:31.553: ERROR/AndroidRuntime(248):     at android.app.Activity.dispatchTouchEvent(Activity.java:2061)

04-19 18:43:31.553: ERROR/AndroidRuntime(248):     at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1643)

04-19 18:43:31.553: ERROR/AndroidRuntime(248):     at android.view.ViewRoot.handleMessage(ViewRoot.java:1691)

04-19 18:43:31.553: ERROR/AndroidRuntime(248):     at android.os.Handler.dispatchMessage(Handler.java:99)

04-19 18:43:31.553: ERROR/AndroidRuntime(248):     at android.os.Looper.loop(Looper.java:123)

04-19 18:43:31.553: ERROR/AndroidRuntime(248):     at android.app.ActivityThread.main(ActivityThread.java:4363)

04-19 18:43:31.553: ERROR/AndroidRuntime(248):     at java.lang.reflect.Method.invokeNative(Native Method)

04-19 18:43:31.553: ERROR/AndroidRuntime(248):     at java.lang.reflect.Method.invoke(Method.java:521)

04-19 18:43:31.553: ERROR/AndroidRuntime(248):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)

04-19 18:43:31.553: ERROR/AndroidRuntime(248):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)

04-19 18:43:31.553: ERROR/AndroidRuntime(248):     at dalvik.system.NativeStart.main(Native Method)

04-19 18:43:31.573: ERROR/dalvikvm(248): Unable to open stack trace file '/data/anr/traces.txt': Permission denied

请帮忙。

-谢谢。


I am trying to use a ToggleButton to switch AirPlane mode on and off. I am not sure how to go about this.

My permissions are:

<uses-permission android:name="android.permission.WRITE_SETTINGS"/>
<uses-permission android:name="android.permission.WRITE_SECURE_SETTINGS"/>

My .XML file looks like this:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView  
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:text="@string/hello"
/>
<ToggleButton  
android:id="@+id/Toggle" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content"
android:textOn="On"
android:textOff="Off">
</ToggleButton>
</LinearLayout>

My Java has this for the toggle button:

AirToggle = (ToggleButton) findViewById(R.id.Toggle);
    AirToggle.setOnClickListener(new OnClickListener(){
        public void onClick(View v){

        if (((ToggleButton)v).isChecked()){
            boolean isEnabled = Settings.System.getInt(context.getContentResolver(),Settings.System.AIRPLANE_MODE_ON, 0) == 1;
            if(isEnabled == false)
            {
            Settings.System.putInt(context.getContentResolver(),Settings.System.AIRPLANE_MODE_ON,1);                                Intent intent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED);
            intent.putExtra("state", 1);
            context.sendBroadcast(intent);
            }

            IntentFilter intentFilter = new IntentFilter("android.intent.action.SERVICE_STATE");

            BroadcastReceiver receiver = new BroadcastReceiver() {
                  @Override
                  public void onReceive(Context context, Intent intent) {
                        Log.d("AirplaneMode", "Service state changed");
                  }
            };

            context.registerReceiver(receiver, intentFilter);


            }

    };
});

}

UPDATE: This is my log cat errors if that helps.

04-19 18:43:24.264: ERROR/AndroidRuntime(233): ERROR: thread attach failed

04-19 18:43:25.933: ERROR/AndroidRuntime(241): ERROR: thread attach failed

04-19 18:43:31.543: ERROR/AndroidRuntime(248): Uncaught handler: thread main exiting due         to uncaught exception

04-19 18:43:31.553: ERROR/AndroidRuntime(248): java.lang.NullPointerException

04-19 18:43:31.553: ERROR/AndroidRuntime(248):     at      com.simple.armor.SimpleArmor$1.onClick(SimpleArmor.java:30)

04-19 18:43:31.553: ERROR/AndroidRuntime(248):     at android.view.View.performClick(View.java:2364)

04-19 18:43:31.553: ERROR/AndroidRuntime(248):     at android.widget.CompoundButton.performClick(CompoundButton.java:98)

04-19 18:43:31.553: ERROR/AndroidRuntime(248):     at android.view.View.onTouchEvent(View.java:4179)

04-19 18:43:31.553: ERROR/AndroidRuntime(248):     at android.widget.TextView.onTouchEvent(TextView.java:6541)

04-19 18:43:31.553: ERROR/AndroidRuntime(248):     at android.view.View.dispatchTouchEvent(View.java:3709)

04-19 18:43:31.553: ERROR/AndroidRuntime(248):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)

04-19 18:43:31.553: ERROR/AndroidRuntime(248):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)

04-19 18:43:31.553: ERROR/AndroidRuntime(248):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)

04-19 18:43:31.553: ERROR/AndroidRuntime(248):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)

04-19 18:43:31.553: ERROR/AndroidRuntime(248):     at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1659)

04-19 18:43:31.553: ERROR/AndroidRuntime(248):     at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1107)

04-19 18:43:31.553: ERROR/AndroidRuntime(248):     at android.app.Activity.dispatchTouchEvent(Activity.java:2061)

04-19 18:43:31.553: ERROR/AndroidRuntime(248):     at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1643)

04-19 18:43:31.553: ERROR/AndroidRuntime(248):     at android.view.ViewRoot.handleMessage(ViewRoot.java:1691)

04-19 18:43:31.553: ERROR/AndroidRuntime(248):     at android.os.Handler.dispatchMessage(Handler.java:99)

04-19 18:43:31.553: ERROR/AndroidRuntime(248):     at android.os.Looper.loop(Looper.java:123)

04-19 18:43:31.553: ERROR/AndroidRuntime(248):     at android.app.ActivityThread.main(ActivityThread.java:4363)

04-19 18:43:31.553: ERROR/AndroidRuntime(248):     at java.lang.reflect.Method.invokeNative(Native Method)

04-19 18:43:31.553: ERROR/AndroidRuntime(248):     at java.lang.reflect.Method.invoke(Method.java:521)

04-19 18:43:31.553: ERROR/AndroidRuntime(248):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)

04-19 18:43:31.553: ERROR/AndroidRuntime(248):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)

04-19 18:43:31.553: ERROR/AndroidRuntime(248):     at dalvik.system.NativeStart.main(Native Method)

04-19 18:43:31.573: ERROR/dalvikvm(248): Unable to open stack trace file '/data/anr/traces.txt': Permission denied

Please help.

-Thanks.


原文:https://stackoverflow.com/questions/5718844
更新时间:2023-10-31 14:10

最满意答案

而不是使用ab ... f ,我会使用CUserstd::vector (BTW,我不喜欢CUser作为类名):

std::vector<CUser> users;

如果这是您关心用户的唯一订单,我CUser订购定义为CUser类的一部分:

class CUser { 

    // ...
    bool operator<(CUser const &other) const { 
         return m_uEventKills < other.m_uEventKills;
    }
};

然后,当您需要按正确顺序排序的用户时,您可以执行以下操作:

std::sort(users.begin(), users.end());

但是,您可能需要向CUser类添加一个ID号(或类似的东西)以跟踪哪个用户是哪个,而不管它们恰好在此刻排列的顺序。

编辑:

要将...中的int的值按升序获得到nHold ,您可能只想将它们插入现有的顺序,然后排序:

nHold[0] = a;
nHold[1] = b;
//...
nHold[9] = j;

std::sort(nHold, nHold+9);

Instead of using a, b ...f, I'd use a std::vector of CUser (BTW, I don't like CUser as a class name):

std::vector<CUser> users;

If this is the only order you care about with respect to users, I'd define the ordering as part of the CUser class:

class CUser { 

    // ...
    bool operator<(CUser const &other) const { 
         return m_uEventKills < other.m_uEventKills;
    }
};

Then when you need the users sorted into the correct order, you can do:

std::sort(users.begin(), users.end());

You will, however, probably need to add an ID number (or something like that) to the CUser class to keep track of which user is which, regardless of the order in which they happen to be arranged at the moment.

Edit:

To just get the values of ints in a...j into nHold in ascending order, you probably want to just insert them in their existing order, then sort:

nHold[0] = a;
nHold[1] = b;
//...
nHold[9] = j;

std::sort(nHold, nHold+9);

相关问答

更多
  • 您需要为每个玩家创建一个不同的记分板,因为要显示它们单独的值需要创建不同的记分板。 要做的更改是将每个Player映射到他们自己的Scoreboard : HashMap boards = new HashMap<>(); HashMap objProvider = new HashMap() { @Override get(Player player) { i ...
  • 而不是使用a , b ... f ,我会使用CUser的std::vector (BTW,我不喜欢CUser作为类名): std::vector users; 如果这是您关心用户的唯一订单,我CUser订购定义为CUser类的一部分: class CUser { // ... bool operator<(CUser const &other) const { return m_uEventKills < other.m_uEventKills; ...
  • 我该如何在本地保存分数? 您将使用数据库。 有许多库可以简化它,我推荐SugarORM 。 是否可以在TextView中显示它 不会。你几乎总是想要一个不止一个TextView东西。 也就是说,使用什么在很大程度上取决于你想要的布局。 how am I supposed to save the scores locally? You would use a database. There are a number of libraries to simplify it, I recommend SugarO ...
  • 在谈论得分时我无法理解你的意思,但是...看起来好像是$row['vrh'], $row['vrhPoskus'], $row['bonus'], $row['bonusPoskus']是相同的,然后地方必须相同。 如果代码可以像这样,那是真的
  • 在一般术语中, 检查器和记分板可互换使用,并且都将DUT的实际结果与预期结果进行比较。 但是, 检查程序通常特定于您要验证的独立功能,而记分板可能是接口或整个DUT的一个或多个检查程序的集合。 记分板也可能负责确定“测试”何时完成。 我认为验证中使用的术语记分板的起源来自用于存储预期结果的数据库,并且当数据库中的所有条目都已检查完成时,或者数据库为空,因为您已删除每个条目时,认为测试已完成因为实际结果来自DUT。 UVM使用uvm_scoreboard来表示包含此数据库的测试平台中的组件。 SystemVe ...
  • 您正在覆盖参数,而不是实际的游戏分数 def drawScore(...,right_score,left_score): # given here ... if center[0] < ball_radius: right_score = right_score + 1 # updated, but only locally ... if center[0] > size[0] - ball_radius: left_sc ...
  • 从管理员指南 (第9.7节): 第二个输入是一个可扩展样式表语言(XSL)文件,描述了如何转换(处理)XML排名。 比赛管理员负责提供适当的XSL文件; samps \ web \ xsl目录中有许多示例XSL文件。 From the Administrator's guide (section 9.7) : The second input is an eXtensible Stylesheet Language (XSL) file describing how the XML standings sh ...
  • 为了帮助您开始,这里有一些用于在Windows 8应用程序中进行序列化和保存的示例代码。 正如其他人所建议的那样,查看XmlObjectSerialzation的内容非常有用。 string[] names = new string[100]; StorageFolder folder = ApplicationData.Current.RoamingFolder; XmlWriterSettings set = new XmlWriterSettings(); set.Encoding = Encodin ...
  • 我猜你在添加“hole”列之前运行了一次代码,那就是正在读取的数据库。 您需要删除应用程序的数据(设置 - >应用程序 - >您的应用程序),以便创建最新版本的数据库。 如果您没有删除数据的选项,请将其卸载。 I would guess that you ran your code once, before you added the "hole" column, and that is the database that is being read. You need to delete your app ...
  • 我个人会使用GameKit / Game Center,我相信它可以为最终用户提供更好的体验。 I would use GameKit / Game Center as personally I believe it provides a better experience for the end user.

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)