[英]thread asynctask and listview
Hi guys i have a problem with my code... i have moved myTask into Splashscreen.java.. this is arrivi.java 嗨,大家好,我的代码有问题...我已将myTask移至Splashscreen.java ..这是arrivi.java
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View arrivi = inflater.inflate(R.layout.arrivi, container, false);
return arrivi;
}
public void CheckRow(){
ListView list;
rowItems = new ArrayList<RowItem>();
for (int i = 1; i <= thread; i++) {
RowItem item = new RowItem(Compagnia[i], CodiceVolo[i], Citta[i],OraPrevista[i], OraStimata[i], StatoVolo[i]);
rowItems.add(item);
System.out.println(CodiceVolo[i]);
}
list=(ListView)arrivi.findViewById(R.id.listView1);
CustomBaseAdapter adapter = new CustomBaseAdapter(getActivity(), rowItems);
list.setAdapter(adapter);
line 103 is 103行是
list=(ListView)getActivity().findViewById(R.id.listView1);
SplashScreen.java SplashScreen.java
public class SplashScreen extends Activity {
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.splashscreen);
Instead of using getActivity(), you should be getting the layout from the Fragment.getView(). 而不是使用getActivity(),应该从Fragment.getView()获取布局。
Update 更新
So, you're launching your AsyncTask in the onCreate of your Activity. 因此,您将在Activity的onCreate中启动AsyncTask。 The AsyncTask's onPostExecute can get called before your Fragment's onCreateView gets called, which is what I suspect is happening here;
可以在调用您的Fragment的onCreateView之前调用AsyncTask的onPostExecute,这是我怀疑在这里发生的情况; hence the null pointer.
因此为空指针。 In general, these are some of the nuances of using AsyncTasks.
通常,这些是使用AsyncTasks的一些细微差别。
You have several options: 您有几种选择:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.