我正在尝试开发一个Android应用程序,在一段时间之后我们必须在文本框中显示一定时间后的值。到目前为止,我只能显示2个值。我也试图将值放在数组中,但到目前为止一直没有成功 我正在下载我的代码。任何想法都会有所帮助。那么有一个按钮,按下按钮后,文本框中会出现第一个值。这是62.53。我第二次点击buttopn后,我看到另一个值72.5。我连续10次点击按钮后,我愿意显示10个值。我无法这样做。这是我的问题
public void onClick(查看v){
if (recording) {
recorder.stop();
// recorder.release();
recording = false;
Log.d("Test","recorderonclick");
// Stop Thread
MobilityMonitorV2.setRunning(false);
button.setText(R.string.titleStart);
Log.d("Test","recorderclick");
// Upload Files to Server
UploadThread upThread = new UploadThread(
MobilityMonitorV2.TIMESTAMP, handler);
upThread.start();
Log.d("Test","recorderonclick");
initRecorder();
setOutputFile(false);
prepareRecorder();
Log.d("TEst","recordercick");
final TextView textView = (TextView) findViewById(R.id.editText1);
textView.setText("62.53");
String editTextStr = textView.getText().toString();
String string = getString(R.string.hello);
//recorder.reset();
button.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
textView.setText("72.5");
}
});
}
else {
resetRecorder();
initRecorder();
setOutputFile(true);
prepareRecorder();
recording = true;
recorder.start();
Log.d("Test","recorderreset");
// Start Bluetooth data thread
DataStream dataStream = new DataStream();
dataStream.start();
Log.d("Test","bluetoothdataset");
button.setText(R.string.titleStop);
Log.d("Test","buttonsetstop");
//TextView textView1 = (TextView) findViewById(R.id.editText1);
//textView1.setText("62.5");
}
}
}
答案 0 :(得分:0)
未测试!!
private TextView textView1;
private static int mCounter = 0;
private ArrayList<String> values = new ArrayList<String>();
public void onCreate(Bundle savedInstanceState)
{
// Add the values you would like to show
values.add("62.53");
values.add("72.5");
// etc. etc.
// Get a reference to your textview
textView1 = (TextView) findViewById(R.id.editText1);
// Set a click listener
textView1.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
// Get the value from your arraylist
String value = values.get(mCounter);
// Set the value in your textview
textView1.setText(value);
// Increase the counter
mCounter++;
}
});
}