Java 在显示表单后添加视图

Java 在显示表单后添加视图,java,android,Java,Android,我正在开发一个应用程序,在这个应用程序中,我通过Internet加载并显示表单中的数据。加载所有数据需要一些时间,所以我希望这样做。加载静态数据并将其显示给用户,但不显示来自internet的动态部分,当它显示该表单时,会触发类似OnLoadActaivity not sure的事件,然后动态添加视图 gamestatistics.xml GameStatistics.java public class GameStatistics extends Actavity{ /** Called w

我正在开发一个应用程序,在这个应用程序中,我通过Internet加载并显示表单中的数据。加载所有数据需要一些时间,所以我希望这样做。加载静态数据并将其显示给用户,但不显示来自internet的动态部分,当它显示该表单时,会触发类似OnLoadActaivity not sure的事件,然后动态添加视图

gamestatistics.xml

GameStatistics.java

public class GameStatistics extends Actavity{
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.gamestatistics);

    Bundle game = getIntent().getExtras();
    String gameName = game.getString("gameName");
    List playersData = game.getStringArrayList("playersData");

    TextView gameNameHeader = (TextView)findViewById(R.id.statisticsGameName);
    gameNameHeader.setText(gameName);       
}

@Override
protected void onResume() {
    super.onResume();
    Bundle game = getIntent().getExtras();
    List playersData = game.getStringArrayList("playersData");

    LinearLayout playerContainer = (LinearLayout) findViewById(R.id.playerContainer);

    LayoutInflater vi = (LayoutInflater) getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    for (int i=0; i<playersData.size(); i++)
    {
        View v = vi.inflate(R.layout.profiletemplate, null);

        TextView playerName = (TextView) v.findViewById(R.id.playerName);
        playerName.setText(((String[])playersData.get(i))[0]);

        TextView playerPosition = (TextView) v.findViewById(R.id.playerScore);
        playerPosition.setText(((String[])playersData.get(i))[1]);

        ImageView playerImage = (ImageView) v.findViewById(R.id.playerImage);

        try
        {
           URL url = new URL(((String[])playersData.get(i))[2]);
           InputStream content = (InputStream)url.getContent();
           Drawable d = Drawable.createFromStream(content,"src");
           playerImage.setImageDrawable(d);
        }
        catch(Exception e)
        {
           e.printStackTrace();
        }             

        playerContainer.addView(v);         
    }
}

}您不应该在UI线程上执行长进程。这是一种不好的做法,在3.0+设备上是不允许的。改用一个字母。AsyncTasks允许您在另一个线程上启动进程,并在进程完成时在UI线程上收到通知。你应该特别关注

onPreExecute() //Done on the UI Thread before the execution begins
doInBackground() //This is the execution thread
onPostExecute() //Done on the UI Thread after the executing is finished

到目前为止你都试了些什么?这不是一个事后代码网站。谢谢回复。我以为这个方法可以解决我在简历上的问题,但我仍然在等待从internet加载数据,然后它显示表单,所以是否有一个方法在加载和显示表单后调用,以便我以后可以更新它?
onPreExecute() //Done on the UI Thread before the execution begins
doInBackground() //This is the execution thread
onPostExecute() //Done on the UI Thread after the executing is finished