嗨朋友们,我知道关于这个话题有很多问题,但我无法从他们那里得到任何结果。我正在使用我的 ClassIsInternalParser 解析 xml 数据扩展默认处理程序。我在内部类 PostAsync extends AsyncTask 的活动中使用此类
但原因是我无法将我在 PostAsync 类中收集的数据返回给主要活动。它只设置 null
这是我的代码
package com.example.uiexercisesplash;
import android.app.Activity;
import android.app.ProgressDialog;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
public class ClassIsInternalListViewActivity extends Activity implements OnClickListener{
TextView tv, tv2;
Button back;
String[][] array = new String[10][3];
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.classisinternal_listview);
new PostAsync().execute();
tv=(TextView) findViewById(R.id.tatar);
tv2= (TextView) findViewById(R.id.tatar2);
tv2.setText(array[0][0]); //Why this sets null!!
back= (Button) findViewById(R.id.back);
back.setOnClickListener(this);
}
class PostAsync extends AsyncTask<Void, Void,String[][]>{
ProgressDialog pd;
ClassIsInternalParser parser;
@Override
protected void onPreExecute() {
//we can set up variables here
pd = ProgressDialog.show(ClassIsInternalListViewActivity.this,
"Classisinternal","Loading last post...",true,false);
}
protected void onPostExecute(String[][] result) {
//in this way it sets correctly
tv.setText(result[0][0]);
array=result;
pd.dismiss();
pd.cancel();
}
protected String[][] doInBackground(Void... params) {
parser = new ClassIsInternalParser();
parser.get();
return parser.dataArray;
}
}
@Override
public void onClick(View v) {
finish();
}
}