轉載請註明出處: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();
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即可。