在我的应用程序中,我在 TextView 中显示了一些压力值,我也想将这些值写入 xml 文件中。当任何 MotionEvent 生成时,我的意思是每次值发生变化时我都在触摸屏幕,并且我想在每次更改发生后写入它们。并且该 xml 文件将保存到 sdcard(任何位置)中。这是我的代码片段 public class MainActivity extends Activity implements View.OnTouchListener {
/** Called when the activity is first created. */
private TextView tvConsole;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
findViewById(R.id.linearLayout1).setOnTouchListener(this);
tvConsole = (TextView)findViewById(R.id.txtConsole2);
}
@Override
public boolean onTouch(View view, MotionEvent mEvent) {
tvConsole.setText( ""+mEvent.getPressure() );
// System.out.println("Hardware X " + mEvent.getXPrecision()
//* mEvent.getX());
// System.out.println("Hardware Y " + mEvent.getYPrecision()
// * mEvent.getY());
System.out.println("Pressure " + mEvent.getPressure());
System.out.println("Size " + mEvent.getSize());
return super.onTouchEvent(mEvent);
}
}