Android的后退按钮功能

Android的后退按钮功能

本文介绍了Android的后退按钮功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我有点厌倦了与设备后退按钮功能。

我有两个活动。从3月1我去第二和显示一个项目,通过阵列中的的ListView ,当我presses后退按钮我回来第一个活动。

当我再次去第二次活动,再次显示该项目它显示我在第二排在第一排的previous项目,然后在同一项目也是如此。

意味着它是不删除previous项目时我presses后退按钮。

我用:

 公共无效onBack pressed()
  {
      的for(int i = 0; I< sub_categories.length;我++)
      {
           - 行业标准[I] =;
      }
      Log.d(this.getClass()的getName(),********后退按钮pressed。);  }


解决方案

我不完全知道你正在尝试做的,因为你没有说明,你真正删除您的项目。

如果你真的一直想删除已在离开活性没有2突出显示的项目,你可以在的onStop删除()。

如果你不想离开活动,您应该设置机器人时要记住状态:saveEnabled =假,在您的布局清单

I'm little bit fed up with the device back button functionality.

I have two activities. From 1st I go to 2nd and display one item through array in ListView and when I presses the back button i came back to 1st activity.

when I again go to 2nd activity to display the item once again it showing me the previous items at 1st row and then the same item in the second row as well.

Means it is not removing the previous item when i presses the back button.

I have used:

 public void onBackPressed ()
  {
      for(int i=0; i<sub_categories.length;i++)
      {
          sub_categories[i]="";
      }
      Log.d(this.getClass().getName(), "*****************back button pressed");

  }
解决方案

I'm not entirely sure what you are trying to do, since you are not describing where you actually delete your item.

If you really always want to delete the item you have highlighted upon leaving activity no 2, you could delete it in onStop().

If you don't want to remember the state when leaving the activity you should set android:saveEnabled="false" in your layout manifest.

这篇关于Android的后退按钮功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 20:44