android基础

1.layout布局文件的使用
eg:
a.LayoutInflater inflate = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
RelativeLayout layoutLeft = (RelativeLayout) inflate.inflate(
R.layout.left, null);

b.setContentView(R.layout.activity_frame_layout);

这里的right和activity_frame_layout 是指项目res中layout文件夹里面的right.xml和activity_frame_layout.xml布局文件

2.布局文件中组件定义的调用
eg:
Button button = (Button) findViewById(R.id.btn_open_search);
button.setOnClickListener(button_listener);

这里的btn_open_search 对应的是你的布局文件中
<Button 
android:id="@+id/btn_open_search"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Open Search-Dialog"
/>


这里的android:id


3.intent机制
参考http://student.csdn.net/space.php?uid=106923&do=blog&id=9997

android.content.ActivityNotFoundException: Unable to find explicit activity class {com.tope.samples/com.tope.samples.TestActivity}; have you declared this activity in your AndroidManifest.xml?”


出现这个问题 主要是要在AndroidManifest.xml中声明了这个
com.tope.samples.TestActivity

eg: <application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".ActivityMain"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="TestActivity"></activity>
</application>


4 进入android里面的liunx平台,首先启动模拟器,然后cmd 进入到安装目录
E:\Program Files\android\sdk1.5_r2\tools>adb shell
回车,即可进入linux平台了

5、安装应用到模拟器:
adb install

比较郁闷的是,Android并没有提供一个卸载应用的命令,只能自己手动删除:
adb shell
cd /data/app
rm app.apk


6、进入设备或模拟器的shell:
adb shell

通过上面的命令,就可以进入设备或模拟器的shell环境中,在这个Linux Shell中,你可以执行各种Linux的命令,另外如果只想执行一条shell命令,可以采用以下的方式:
adb shell [command]

如:adb shell dmesg会打印出内核的调试信息。

7、发布端口:
你可以设置任意的端口号,做为主机向模拟器或设备的请求端口。如:
adb forward tcp:5555 tcp:8000


8、复制文件:
你可向一个设备或从一个设备中复制文件,
复制一个文件或目录到设备或模拟器上:
adb push
如:adb push test.txt /tmp/test.txt

从设备或模拟器上复制一个文件或目录:
adb pull
如:adb pull /addroid/lib/libwebcore.so .


9、搜索模拟器/设备的实例:
取得当前运行的模拟器/设备的实例的列表及每个实例的状态:
adb devices


10、查看bug报告:
adb bugreport


11、记录无线通讯日志:
一般来说,无线通讯的日志非常多,在运行时没必要去记录,但我们还是可以通过命令,设置记录:
adb shell
logcat -b radio


12、获取设备的ID和序列号:
adb get-product
adb get-serialno


13、访问数据库SQLite3
adb shell
sqlite3


14、不同的activity对应不同的布局
在Activity中引用setContentView(R.layout.main2);
在/res/layout/中增加main2.xml布局文件


15、android国际化问题
只需要在/res/中增加values-en-rus这样一个文件夹,即可支持Englist(United Kingdom)
其他国家语言同理

16、Intent在绑定数据时要注意数据类型,eg:
Intent data = new Intent();
data.putExtra("age", 23);

这里的age如果你用int类型,那么在另外一个activity中获取这个数据时要用
protected void onActivityResult(int requestCode, int resultCode, Intent data){
data.getIntExtra("age");
}

如果这里用getStringExtra("age")则获取不到age的数据
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值