首先这个实例只能用在4.0以上版本
你想点击任意一点获得坐标不能用onTouchEvent,而只能用dispatchTouchEvent 因为“MapActivity 继承了 the dispatchTouch Event 而不是OnTouchEvent ”
@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
int actionType = ev.getAction();
switch (actionType) {
case MotionEvent.ACTION_UP:
if(!premik) {
Projection proj = mapView.getProjection();
GeoPoint loc = proj.fromPixels((int)arg0.getX(), (int)arg0.getY());
String sirina=Double.toString(loc.getLongitudeE6()/1000000);
String dolzina=Double.toString(loc.getLatitudeE6()/1000000);
Toast toast = Toast.makeText(getApplicationContext(), "Širina: "+sirina+" Dolzina: "+dolzina, Toast.LENGTH_LONG);
toast.show();
}
}
return super.dispatchTouchEvent
android:windowSoftInputMode="stateVisible|adjustResize"
android:theme="@android:style/Theme.NoTitleBar"
android:configChanges="orientation|keyboardHidden"
android:theme="@style/Theme.CustomDialog"
android:theme="@style/Theme.Translucent"
android:theme="@style/Theme.Transparent"
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="1"
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.SAMPLE_CODE" />
</intent-filter>
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("audio/*");
startActivity(Intent.createChooser(intent, "Select music"));
NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
友情提供了另一种方法:(得自峰的真传)
new NullPointerException("No focus window, dropping: ").printStackTrace();
java.util.Map<Thread, StackTraceElement[]> ts = Thread.getAllStackTraces();
StackTraceElement[] ste = ts.get(Thread.currentThread());
for (StackTraceElement s : ste) {
android.util.Log.d("SS ", s.toString());
}
Throwable tr = new Throwable();
tr.fillInStackTrace();
Log.v(TAG,"",tr);
打印JAVA调用栈方法
try {
throw new Exception();
} catch (Exception ex) {
Log.e("pan", "=======sssss======");
ex.printStackTrace();
}
有时候需要了解一段代码调用时的调用栈,方便定位问题,使用上面的方法可以打印调用栈,很方便。
打印结果如下:从下向上是调用逻辑。
01-01 11:47:46.546: ERROR/pan(1049): ========AAAAAAAA======
01-01 11:47:46.546: WARN/System.err(1049): java.lang.Exception
01-01 11:47:46.546: WARN/System.err(1049): at android.widget.PopupWindow.setHeight(PopupWindow.java:619)
01-01 11:47:46.546: WARN/System.err(1049): at android.widget.PopupWindow.update(PopupWindow.java:1160)
01-01 11:47:46.546: WARN/System.err(1049): at android.widget.PopupWindow.update(PopupWindow.java:1136)
01-01 11:47:46.546: WARN/System.err(1049): at android.widget.PopupWindow.update(PopupWindow.java:1275)
01-01 11:47:46.556: WARN/System.err(1049): at android.widget.PopupWindow.update(PopupWindow.java:1238)
01-01 11:47:46.556: WARN/System.err(1049): at android.widget.AutoCompleteTextView.showDropDown(AutoCompleteTextView.java:1170)
01-01 11:47:46.556: WARN/System.err(1049): at android.widget.AutoCompleteTextView$PopupTouchInterceptor.onTouch(AutoCompleteTextView.java:1428)
01-01 11:47:46.556: WARN/System.err(1049): at android.widget.PopupWindow$PopupViewContainer.dispatchTouchEvent(PopupWindow.java:1352)
01-01 11:47:46.556: WARN/System.err(1049): at android.view.ViewRoot.handleMessage(ViewRoot.java:1691)
01-01 11:47:46.556: WARN/System.err(1049): at android.os.Handler.dispatchMessage(Handler.java:99)
01-01 11:47:46.556: WARN/System.err(1049): at android.os.Looper.loop(Looper.java:123)
01-01 11:47:46.556: WARN/System.err(1049): at android.os.HandlerThread.run(HandlerThread.java:60)
想代码实现 将子activity的所用的layout加入到主activty中的layout
public class FormActivity extends ActivityGroup {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.form);
LocalActivityManager m = getLocalActivityManager();
Intent intent = new Intent().setClass(this, ContactFieldActivity.class);
Window w = m.startActivity("tratat", intent);
View v = w.getDecorView();
LinearLayout container = (LinearLayout)findViewById(R.id.fieldsContainer);
container.addView(v);
}
}