转载请注明出处:http://write.blog.csdn.net/postedit/24805547
这篇文章记录平时开发过程遇到的小问题,使用的小技巧,
1、启动Activity后,阻止输入法聚焦到Edittext
在Androidmanifest.xml中找到对应Activity,加上
android:windowSoftInputMode="stateHidden"
2、OnTouchListener和OnClickListener冲突
在OnTouchListener中加入v.performClick();,如下
your_txtView.setOnTouchListener(new TextView.OnTouchListener(){ @Override public boolean onTouch(View v, MotionEvent event) { if (MotionEvent.ACTION_DOWN == event.getAction()) { } else if (MotionEvent.ACTION_UP == event.getAction()) { v.performClick(); } return true; } });
3、The connection to adb is down
具体状况如下:
The connection to adb is down, and a severe error has occured. [2013-07-23 17:28:06 - ] You must restart adb and Eclipse. [2013-07-23 17:28:06 - ] Please ensure that adb is correctly located at 'D:\Program Files\Android\android-sdk\platform-tools\adb.exe' and can be executed.
解决方法为:
在命令行下打开你当前使用的SDK 对应的 Android SDK platform-tools 目录 输入 adb kill-server 然后,输入 adb start-server 重启eclipse,OK
4、FrameLayout中的margin不起作用
具体原因,
当在xml文件中不设置layout_gravity时,四个方向的margin都不起作用。而设置layout_gravity = "true"时,只有topmargin会起作用,其他三种,也依此类推。
5、notifyDataSetChanged()不起作用
看以下例子
ArrayList<Person> listData = new ArrayList<Person>; ListView listview = (ListView) view.findViewById(R.id.menulist); MyAdapter adapter = new MyAdapter(this, listData); listview.setAdapter(adapter); final Handler handler = new Handler(){ @Override public void handleMessage(Message msg) { // TODO Auto-generated method stub if(msg.what == 1){ adapter.notifyDataSetChanged(); } } }; new Thread(new Runnable() { @Override public void run() { // TODO Auto-generated method stub //从网络获取数据 App app = (App)(MenuFragment.this.getActivity().getApplication()); listData = app.loadRelative(app.getUID()); Message msg = new Message(); msg.what = 1; handler.sendMessage(msg); } }).start();
上面代码中,notifyDataSetChanged是不会发挥作用的,问题在与,更新数据时,代表adapter数据集的lvRelativeData引用的对象其实发生了变化,原因在于其中这一行代码:
listData = app.loadRelative(app.getUID());
只需将以上代码修改为:
ArrayList<Person> latestData = app.loadRelative(app.getUID()); for(Person person: latestData){ listData.add(person); }
6、at android.widget.AbsListView.obtainView(AbsListView.java:2040)
该错误一般不会提醒错误代码在哪一行,很让人头疼,如下
最后发现问题在于,adapter中的getView方法返回的是return null,只要修改为 return convertView即可。