您的位置:首页 > 移动开发 > Android开发

android改写XML之后,调试注意事项

2013-12-09 18:54 399 查看

首先声明一下哈,刚接触android一个月左右,对整个架构有了初步的了解,实际的编程水平和调试如LogCat,breakpoint等调试信息,还是不太熟练,仅以今天遇到的一个小问题跟大家一起分享一下。

引用
protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.plan);// 设置布局文件

txtMoney = (EditText) findViewById(R.id.txtMoney);// 获取金额文本框

txtMark = (EditText) findViewById(R.id.txtMark);// 获取备注文本框

planType=(Spinner) findViewById(R.id.spPlanType);//获取月计划和周计划选项

spType = (Spinner) findViewById(R.id.spOutType);// 获取类别下拉列表

btnSaveButton = (Button) findViewById(R.id.btnSave);// 获取保存按钮

btnCancelButton = (Button) findViewById(R.id.btnCancel);// 获取取消按钮

btnSaveButton.setOnClickListener(new OnClickListener() {// 为保存按钮设置监听事件

@Override

public void onClick(View view) {
这是以前的一段代码,.java的,由于只是修改了XML文件,所以对SRC里面的东西还是没敢动呵呵,下面是plan.xml文件
引用
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="fill_parent"

android:layout_height="fill_parent" >

<Button

android:id="@+id/btnSave"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignParentBottom="true"

android:layout_toRightOf="@+id/tvMark"

android:text="保存" />

< TextView

android:id="@+id/tvTitle"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignParentTop="true"

android:layout_centerHorizontal="true"

android:layout_marginTop="17dp"

android:text="计划录入"

android:textColor="#ff0"

android:textSize="30sp" />
由于代码较长,我挑重点给大家说哈,以上是还未改写的代码。引用
<RelativeLayout

android:layout_width="fill_parent"

android:layout_height="fill_parent"

xmlns:android="http://schemas.android.com/apk/res/android">

<TextView

android:id="@+id/tvTitle"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignParentTop="true"

android:layout_centerHorizontal="true"

android:layout_marginTop="18dp"

android:text="计划录入"

android:textColor="#ff0"

android:textSize="30sp" />

<TextView

android:id="@+id/tvPlan"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignParentLeft="true"

android:layout_below="@+id/tvTitle"

android:layout_marginLeft="31dp"

android:layout_marginTop="25dp"

android:text="周期:" />
以上是改写之后的代码。

起初我以为ID属性对应上之后,不管我怎么布局,都不会影响程序的正常运行,但是当我真正运行的时候发现并不是这样,第一,你有可能遇到id变量名的改变,就会耽误你连接到plan.java也就是findViewByid这个属性要报错啦!!!所以,你如果要想大改的话,一定要事先做好备份,以免~~~你懂得。第二,你的editView等属性必须要仔仔细细的对应好,别明明是textView你弄成别的,是吧?其实以上只要你细心的话,我想都不会出错,问题一般出现在第三上,我都对应好之后,我就开始调试了,可是无论怎么检查,怎么baidu,goole都无济于事,后来clean了一下,之后下狠心,就把之前在手机上的apk数据信息清理干净,一起运行,后来,意外性的pass调试了,很意外吧?之前其实我遇到过这样的问题,毕竟初学嘛,我在数据模型跟数据操作增删改查上,就经常遇到在数据模型中定义的方法啊,还是在values上面的定义上的错误,乱!不言而喻,改之后就要重新清理的干干净净才,继续调试了。

上面已经够多的了,总结一句话吧,如果你在修改完程序之后,你感觉不可能有错了,那么你就直接把在你调试器上面的之前的数据清理干净,如果还是不行的话,那证明就是你程序的问题了。——初学者,勿喷~~~
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: