Java 在CreateView之后运行方法

Java 在CreateView之后运行方法,java,android,multithreading,android-fragments,Java,Android,Multithreading,Android Fragments,嗨,伙计们,我的碎片有问题。 我有一个splashscreen,在这里我用AsyncTask设置数组的字符串!没关系 Splashscreen.java @Override protected String doInBackground(String... params) { try { org.jsoup.nodes.Document doc = Jsoup.connect("http://s.eu").ti

嗨,伙计们,我的碎片有问题。 我有一个splashscreen,在这里我用AsyncTask设置数组的字符串!没关系

Splashscreen.java

        @Override
    protected String doInBackground(String... params) {
        try {           
            org.jsoup.nodes.Document doc = Jsoup.connect("http://s.eu").timeout(7*1000).get();

            org.jsoup.nodes.Element tabella = doc.getElementsByClass("tabella-voli").first();
            Iterator<org.jsoup.nodes.Element> iterator = tabella.select("td").iterator();

            while(iterator.hasNext()){
                thread++;

                Compagnia[thread] = iterator.next().text();
                CodiceVolo[thread] = iterator.next().text();
                Citta[thread] = iterator.next().text();
                OraPrevista[thread] = iterator.next().text();
                OraStimata[thread] = iterator.next().text();
                StatoVolo[thread] = iterator.next().text();

                System.out.println("THREAD: "+CodiceVolo[thread]);
            }
        }catch (IOException e) {
            e.printStackTrace();
        }return info;
    }

    @Override
    protected void onPostExecute(String result) { 
        super.onPostExecute(result);
        prog.dismiss();

        finish();
        Intent intent = new Intent(SplashScreen.this, MainActivity.class);
        SplashScreen.this.startActivity(intent);

    //  new Partenze().execute("");

    }
}
    public class arrivi extends Fragment {

    ListView list;
    List<RowItem> rowItems;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
       View arrivi = inflater.inflate(R.layout.arrivi, container, false); 
       return arrivi;
    }

    public void CheckRow(){

        System.out.println("EDEGUITO CHECKROW");

        SplashScreen x = new SplashScreen();
        rowItems = new ArrayList<RowItem>();
        for (int i = 1; i <= x.thread; i++) {

            RowItem item = new RowItem(x.Compagnia[i], x.CodiceVolo[i], x.Citta[i],x.OraPrevista[i],  x.OraStimata[i], x.StatoVolo[i]);
            rowItems.add(item);
            System.out.println("EDEGUITO CHECKROW");

            System.out.println(x.CodiceVolo[i]);
        } 
        list=(ListView)getActivity().findViewById(R.id.listView1);
        CustomBaseAdapter adapter = new CustomBaseAdapter(getActivity(), rowItems);
        list.setAdapter(adapter);
    }
}  
@覆盖
受保护的字符串doInBackground(字符串…参数){
试试{
org.jsoup.nodes.Document doc=jsoup.connect(“http://s.eu)超时(7*1000).get();
org.jsoup.nodes.Element tabella=doc.getElementsByClass(“tabella voli”).first();
迭代器迭代器=tabella.select(“td”).Iterator();
while(iterator.hasNext()){
线程++;
Compagnia[thread]=迭代器.next().text();
CodiceVolo[thread]=迭代器.next().text();
Citta[thread]=迭代器.next().text();
OraPrevista[thread]=迭代器.next().text();
OraStimata[thread]=迭代器.next().text();
StatoVolo[thread]=迭代器.next().text();
System.out.println(“线程:“+CodiceVolo[THREAD]);
}
}捕获(IOE异常){
e、 printStackTrace();
}退货信息;
}
@凌驾
受保护的void onPostExecute(字符串结果){
super.onPostExecute(结果);
程序解除();
完成();
意向意向=新意向(SplashScreen.this,MainActivity.class);
SplashScreen.this.StartTactivity(意图);
//新建Partenze()。执行(“”);
}
}
在控制台中,我可以看到数组的内容,但我有一个片段: arrivi.java

        @Override
    protected String doInBackground(String... params) {
        try {           
            org.jsoup.nodes.Document doc = Jsoup.connect("http://s.eu").timeout(7*1000).get();

            org.jsoup.nodes.Element tabella = doc.getElementsByClass("tabella-voli").first();
            Iterator<org.jsoup.nodes.Element> iterator = tabella.select("td").iterator();

            while(iterator.hasNext()){
                thread++;

                Compagnia[thread] = iterator.next().text();
                CodiceVolo[thread] = iterator.next().text();
                Citta[thread] = iterator.next().text();
                OraPrevista[thread] = iterator.next().text();
                OraStimata[thread] = iterator.next().text();
                StatoVolo[thread] = iterator.next().text();

                System.out.println("THREAD: "+CodiceVolo[thread]);
            }
        }catch (IOException e) {
            e.printStackTrace();
        }return info;
    }

    @Override
    protected void onPostExecute(String result) { 
        super.onPostExecute(result);
        prog.dismiss();

        finish();
        Intent intent = new Intent(SplashScreen.this, MainActivity.class);
        SplashScreen.this.startActivity(intent);

    //  new Partenze().execute("");

    }
}
    public class arrivi extends Fragment {

    ListView list;
    List<RowItem> rowItems;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
       View arrivi = inflater.inflate(R.layout.arrivi, container, false); 
       return arrivi;
    }

    public void CheckRow(){

        System.out.println("EDEGUITO CHECKROW");

        SplashScreen x = new SplashScreen();
        rowItems = new ArrayList<RowItem>();
        for (int i = 1; i <= x.thread; i++) {

            RowItem item = new RowItem(x.Compagnia[i], x.CodiceVolo[i], x.Citta[i],x.OraPrevista[i],  x.OraStimata[i], x.StatoVolo[i]);
            rowItems.add(item);
            System.out.println("EDEGUITO CHECKROW");

            System.out.println(x.CodiceVolo[i]);
        } 
        list=(ListView)getActivity().findViewById(R.id.listView1);
        CustomBaseAdapter adapter = new CustomBaseAdapter(getActivity(), rowItems);
        list.setAdapter(adapter);
    }
}  
公共类arrivi扩展片段{
列表视图列表;
列出项目;
@凌驾
CreateView上的公共视图(布局、充气机、视图组容器、捆绑包保存状态){
视图arrivi=充气机。充气(R.layout.arrivi,容器,假);
返回阿里维;
}
公共无效检查行(){
System.out.println(“EDEGUITO CHECKROW”);
SplashScreen x=新SplashScreen();
rowItems=新的ArrayList();

对于(int i=1;i您应该在onActivityCreated()中调用它,因为它是在onCreateView()之后调用的

例如:

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    checkRow();
}
这里是片段的生命周期

为您的类创建一个布尔值,并在onCreateView中将其设置为true,然后在checkRow中执行类似于if(view created)的操作。这不是最好的方法,而是一个拼凑在一起的方法嗨,谢谢……您能用我的代码为我举个例子吗?谢谢!!!!