个人android遇到的问题总结

来源:互联网 发布:什么是单例模式 java 编辑:程序博客网 时间:2024/04/18 14:06

作者:刘占


       初学android遇到了各种问题,在这里做一个小的总结,希望对大家遇到同样问题时有一些帮助。也希望大家尽量补充。


1, 程序没有错误,运行后却弹出如下

Theapplication has stopped unexpectedly.Please try again

 

这个问题是个人遇到最多的情况,大多数情况下是程序代码出了问题,但是程序又没有报错,所以要找出问题原因,需要查看Logcat提示的错误,打开Window-Open Perspective-DDMS来查找错误。

 

(1)      Devices:可以查看到当前运行的Emulator和其内运行的应用。(PS:Emulator/Device占用两个(一组)端口,一个为偶数的5554,一个奇数的5555。如果还开启其他的Emulator,则使用的另一组端口是5556,5557,一直到5585.

(2)       Emulator control:设置仿真器的硬件

      设置当前注册的网络状态(Home,Roaming,UnRegistered,Searching)
       数据业务的速度设置:有GSM,GPRS,EDGE,UMTS,HSDPA(3.5G?)
       还有载入KML或NMEA文件来模拟GPS数据

(3)       查询Threads,Heap,FileExplorer、重启adb,抓屏等,其他都是在调用adb

(4)       关于logcat

设置打印等级:从Windows->Prereference->android->DDMS->LogginLevel
默认只打印入口线程的信息,射频和Tapi的动作信息要通过adbLogcat -b radio打开,os-events相关的打印通过adb logcat -b events.打开,Log默认被写入到手机的/data/anr/traces.txt文件中。


2,自定义一个listview,想要在同一个Item添加图片、文字和单选按钮比较难,经过上网查找,找到了简单的解决办法

把单选按钮用图片表示即可,然后使用SimpleAdapter放进ListView中,具体代码如下:


simpleAdapter =  new  SimpleAdapter( this , getData(),                  R.layout.picture_info, new  String[] { imageViewIdStr,                          pictureNameIdStr, picturePixelIdStr, radioImageIdStr },                  new   int [] { R.id.imageViewId, R.id.pictureNameId,                          R.id.picturePixelId, R.id.radioImageId });            listView.setOnItemClickListener(new  OnListClickListener());          listView.setAdapter(simpleAdapter);  //////////////////////////////////   private   class  OnListClickListener  implements  OnItemClickListener {            public   void  onItemClick(AdapterView<?> arg0, View arg1,  int  arg2,                  long  arg3) {              // TODO Auto-generated method stub               ChangeRadioImage(selectItemIndex, false );              ChangeRadioImage(arg2, true );              selectItemIndex = arg2;          }  //主要是下面这个函数用来选中和未选中时交换图片的                   private  void ChangeRadioImage( int  position,  boolean  isChangeImage) {              SimpleAdapter tmpSimpleAdapter = simpleAdapter;              HashMap<String, Object> hm = (HashMap<String, Object>) simpleAdapter                      .getItem(position);                if  (isChangeImage) {                  hm.put("radioImageId" , R.drawable.pressed);              } else  {                  hm.put("radioImageId" , R.drawable.press);              }              tmpSimpleAdapter.notifyDataSetChanged();          }  


3,怎么样在后台实现将应用程序卸载:


private void setUninstall(boolean finish, boolean appChanged) {        if(localLOGV) Log.i(TAG, "appChanged="+appChanged);        Intent intent = new Intent();        intent.putExtra(ManageApplications.APP_CHG, appChanged);        setResult(ManageApplications.RESULT_OK, intent);        if(finish) {            finish();         }  


原创粉丝点击