当前位置:  编程技术>移动开发
本页文章导读:
    ▪举例说小弟我想要做的一个事情是,在一个主界面(主Activity)上能连接往许多不同子功能模块(子Activity上去),当子模块的事情做完之后就回到主界面,或许还        举例说我想要做的一个事情是,在一个主界面(主Activity)上能连接往许多不同子功能模块(子Activity上去),当子模块的事情做完之后就回到主界面,或许还 举例说我想要做的一个事情是,在一.........
    ▪ 风格为Theme.Dialog的Activity纯代码手写布局里scrollview的有关问题        风格为Theme.Dialog的Activity纯代码手写布局里scrollview的问题 风格为Theme.Dialog的Activity,即manifest里对Activity加上属性android:theme="@android:style/Theme.Dialog",   如果Activity里的所有布局是纯代码所写,.........
    ▪ 起步两个模拟器打电话 和短信       启动两个模拟器打电话 和短信 具体步骤:首先,我们要启动两个android模拟器。只有这样,才能模拟效果。1.第一个模拟器,我们通过eclipse启动。具体方法是:打开你的eclipse,随便运行一.........

[1]举例说小弟我想要做的一个事情是,在一个主界面(主Activity)上能连接往许多不同子功能模块(子Activity上去),当子模块的事情做完之后就回到主界面,或许还
    来源: 互联网  发布时间: 2014-02-18
举例说我想要做的一个事情是,在一个主界面(主Activity)上能连接往许多不同子功能模块(子Activity上去),当子模块的事情做完之后就回到主界面,或许还

举例说我想要做的一个事情是,在一个主界面(主Activity)上能连接往许多不同子功能模块(子Activity上去),当子模块的事情做完之后就回到主界面,或许还同时返回一些子模块完成的数据交给主Activity处理。这个时候就要用到回调函数onActivityResult()。 

 

现在贴上一个关于onActivityResult的用法的小例子的代码:

onActivityResult.java

主要的Activity,一会会先执行此Activity,然后调用B Activity,并向其发送数据,通过回调函数来获取B传回来的值。

 

 

public class onActivityResult extends Activity {

   /** Called when the activity is first created. */

 

   @Override

   public void onCreate(Bundle savedInstanceState) {

       super.onCreate(savedInstanceState);

       setContentView(R.layout.main);

       StartA();

   }

   public void StartA()

   {

         Button buttonA = (Button)findViewById(R.id.button1);

         buttonA.setOnClickListener(new View.OnClickListener() {

                public void onClick(View v) {

                           // TODO Auto-generated method stub

//                     onActivityResult.this.setContentView(R.layout.second);

//                     onActivityResult.this.StartB();

 

                              Intent intent = new Intent(onActivityResult.this,ClassB.class);

                                  String passString = "Hello,this is A";

                                 intent.putExtra("ToB", passString);

                                  startActivityForResult(intent, 0);

                           

 

                    }

             });

   }

   protected void onActivityResult(int requestCode, int resultCode, Intent data) {

         switch (resultCode) { //resultCode为回传的标记,我在B中回传的是RESULT_OK

                case RESULT_OK:

         Bundle b=data.getExtras(); //data为B中回传的Intent

         String str=b.getString("FromB");//str即为回传的值

         TextView view = (TextView)findViewById(R.id.textA);

         view.setText(str);

                 break;

                default:

                   break;

         }

         }

   

   

   /*public void StartB()

   {

         Button buttonB = (Button)findViewById(R.id.button2);

         buttonB.setOnClickListener(new View.OnClickListener() {

                public void onClick(View v) {

                           // TODO Auto-generated method stub

                       onActivityResult.this.setContentView(R.layout.main);

                       onActivityResult.this.StartA();

 

                    }

             });

   }*/

}

 

----------------------------------------------

ClassB.java

 

public class ClassB extends Activity{

      private Intent intent;

   public void onCreate(Bundle savedInstanceState) {

       super.onCreate(savedInstanceState);

       setContentView(R.layout.second);

       

       intent = getIntent();

             String result = intent.getStringExtra("ToB");

       

       

         Button button = (Button)findViewById(R.id.button2);

       button.setOnClickListener(new View.OnClickListener() {

                    

                    @Override

                    public void onClick(View v) {

                           // TODO Auto-generated method stub

                           Intent intent = new Intent(ClassB.this,onActivityResult.class);

                           String passString = "Hello,this is B";

                           intent.putExtra("FromB", passString);

                           setResult(RESULT_OK, intent);

                           finish();

                    }

             });

      TextView textView = (TextView)findViewById(R.id.textB);

       textView.setText(result);

   }

 

}

-------------------------------------


    
[2] 风格为Theme.Dialog的Activity纯代码手写布局里scrollview的有关问题
    来源: 互联网  发布时间: 2014-02-18
风格为Theme.Dialog的Activity纯代码手写布局里scrollview的问题

风格为Theme.Dialog的Activity,即manifest里对Activity加上属性android:theme="@android:style/Theme.Dialog",

 

如果Activity里的所有布局是纯代码所写,不是从layout xml里生成,布局包含一个ScrollView,ScrollView里有很多TextView, EditText这类的小widget, 当用户点击其中一个EditText时,软键盘弹出来盖住了Activity的UI,Activity的UI没有自动缩小显示出scrollview的滚动条, 这是为什么呢?

 

这跟Activity的一个属性有关,即android:windowSoftInputMode:

 

这里设置其为 android:windowSoftInputMode=“stateHidden|adjustResize”即可解决上述我们的问题!

 

具体是什么原因,看以下SDK文档解释就明白了:

 

How the main window of the activity interacts with the window containing the on-screen soft keyboard. The setting for this attribute affects two things:

  • The state of the soft keyboard — whether it is hidden or visible — when the activity becomes the focus of user attention.
  • The adjustment made to the activity's main window — whether it is resized smaller to make room for the soft keyboard or whether its contents pan to make the current focus visible when part of the window is covered by the soft keyboard.

The setting must be one of the values listed in the following table, or a combination of one "state... " value plus one "adjust... " value. Setting multiple values in either group — multiple "state... " values, for example — has undefined results. Individual values are separated by a vertical bar (| ). For example:

 

<activity
 
android:windowSoftInputMode
=
"stateVisible|adjustResize"
 . . . 
>

 

Values set here (other than "stateUnspecified " and "adjustUnspecified ") override values set in the theme.

 

Value Description "stateUnspecified " The state of the soft keyboard (whether it is hidden or visible) is not specified. The system will choose an appropriate state or rely on the setting in the theme.

This is the default setting for the behavior of the soft keyboard.

"stateUnchanged " The soft keyboard is kept in whatever state it was last in, whether visible or hidden, when the activity comes to the fore. "stateHidden " The soft keyboard is hidden when the user chooses the activity — that is, when the user affirmatively navigates forward to the activity, rather than backs into it because of leaving another activity. "stateAlwaysHidden " The soft keyboard is always hidden when the activity's main window has input focus. "stateVisible " The soft keyboard is visible when that's normally appropriate (when the user is navigating forward to the activity's main window). "stateAlwaysVisible " The soft keyboard is made visible when the user chooses the activity — that is, when the user affirmatively navigates forward to the activity, rather than backs into it because of leaving another activity. "adjustUnspecified " It is unspecified whether the activity's main window resizes to make room for the soft keyboard, or whether the contents of the window pan to make the currentfocus visible on-screen. The system will automatically select one of these modes depending on whether the content of the window has any layout views that can scroll their contents. If there is such a view, the window will be resized, on the assumption that scrolling can make all of the window's contents visible within a smaller area.

This is the default setting for the behavior of the main window.

"adjustResize " The activity's main window is always resized to make room for the soft keyboard on screen. "adjustPan " The activity's main window is not resized to make room for the soft keyboard. Rather, the contents of the window are automatically panned so that the current focus is never obscured by the keyboard and users can always see what they are typing. This is generally less desirable than resizing, because the user may need to close the soft keyboard to get at and interact with obscured parts of the window.

 

 


    
[3] 起步两个模拟器打电话 和短信
    来源: 互联网  发布时间: 2014-02-18
启动两个模拟器打电话 和短信
具体步骤:

首先,我们要启动两个android模拟器。只有这样,才能模拟效果。
1.第一个模拟器,我们通过eclipse启动。

具体方法是:打开你的eclipse,随便运行一个项目。Eclipse会帮你启动我们的第一个android模拟器。ID为5554.

2.第二个模拟器,我们通过DOS命令启动。具体方法:“开始”-“运行”-“CMD打开一个命令行窗口。然后cd 命令到你的android SDK目录的tools文件夹下面,输入“emulator -data foo”,回车。稍等片刻,系统即可帮你启动又一个新的android模拟器。ID为5556.这2个模拟器的ID 就是对应的模拟器的电话号码

3.于是两个就有了2个模拟器的ID了,这里的ID号相当于真机上的手机号码。收发短信和接打电话全靠他们。
好了,两个全新的模拟器我们已经启动完毕。

现在来测试接打电话和收发短信。

怎么测试呢。通过id号,进行和手机打电话和发短信同样的操作,即可。





注意 : 如果发现打不通 或者发不了短信 查看一下 你当前模拟器的那个网络信号状态

如果是飞行模式 是实现不了的哦。

    
最新技术文章:
▪Android开发之登录验证实例教程
▪Android开发之注册登录方法示例
▪Android获取手机SIM卡运营商信息的方法
▪Android实现将已发送的短信写入短信数据库的...
▪Android发送短信功能代码
▪Android根据电话号码获得联系人头像实例代码
▪Android中GPS定位的用法实例
▪Android实现退出时关闭所有Activity的方法
▪Android实现文件的分割和组装
▪Android录音应用实例教程
▪Android双击返回键退出程序的实现方法
▪Android实现侦听电池状态显示、电量及充电动...
▪Android获取当前已连接的wifi信号强度的方法
▪Android实现动态显示或隐藏密码输入框的内容
▪根据USER-AGENT判断手机类型并跳转到相应的app...
▪Android Touch事件分发过程详解
▪Android中实现为TextView添加多个可点击的文本
▪Android程序设计之AIDL实例详解
▪Android显式启动与隐式启动Activity的区别介绍
▪Android按钮单击事件的四种常用写法总结
▪Android消息处理机制Looper和Handler详解
▪Android实现Back功能代码片段总结
▪Android实用的代码片段 常用代码总结
移动开发 iis7站长之家
▪Android中通过view方式获取当前Activity的屏幕截...
▪Android提高之自定义Menu(TabMenu)实现方法
▪Android提高之多方向抽屉实现方法
▪Android提高之MediaPlayer播放网络音频的实现方法...
▪Android提高之MediaPlayer播放网络视频的实现方法...
▪Android提高之手游转电视游戏的模拟操控
 


站内导航:


特别声明:169IT网站部分信息来自互联网,如果侵犯您的权利,请及时告知,本站将立即删除!

©2012-2021,,E-mail:www_#163.com(请将#改为@)

浙ICP备11055608号-3