我有这个项目:
我试图不明白问题出在哪里以及如何解决,但这一点我真的不知道问题出在哪里。我有一个按钮和一个 TextView。单击按钮时,将调用此过程:
android:onClick="pulsaboton"
TextView 向我展示了输出。
这是 Main_Activity.java
package com.example.pruebasonidos;
import android.app.Activity;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
public class MainActivity extends Activity {
public String cadena1="", cadena2="";
public TextView tv;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tv = (TextView) findViewById(R.id.textview01);
}
public class generamusica extends AsyncTask<String, Integer, Integer>
{
@Override
protected void onPreExecute(){
tv.setText(tv.getText().toString()+"Pre Execute");
}
@Override
protected Integer doInBackground(String...strings) {
String cadena=strings[0];
tv.setText(tv.getText().toString()+cadena);
return null;
}
@Override
protected void onPostExecute(Integer bytes){
tv.setText(tv.getText().toString()+"Post Execute");
}
}
public void pulsaboton(View v) {
cadena1="123"; cadena2="111";
tv.setText("");
new generamusica().execute(cadena1);
new generamusica().execute(cadena2);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
当点击 pulsaboton 时,textview1 显示:
PreExecutePreExecute123111PostExecutePostExecute
我想要这个输出:
PreExecute123PostExecutePreExecute111PostExecute
错误是什么????