我有两个几乎相同的 ListFragment A & B,除了它们从各自的 Asynctasker 中提取数据。
onListItemClick 在A将导致 Fragment A被B替换。但是,我的应用程序总是卡在B中的 CustomAdapter 的构造函数中。
private class CustomAdapter_B extends ArrayAdapter<MatchType> {
// Stuck Here
CustomAdapter_B() {
super(getActivity(), R.layout.color_match_type_s2, matches_type_s2);
}
片段 A
public class Fragment A extends ListFragment implements AsyncTaskCompleteListener<ArrayList<MatchType>>{
ArrayList<MatchType> matches_type = new ArrayList<MatchType>();
private ProgressDialog dialog;
private static FirstPageFragmentListener main_caller;
@Override
public void onListItemClick(ListView l, View v, int position, long id) {
//Interface, triggering Fragment Replace in my Fragment Adapter
main_caller.onMySignalWithNum(1, (matches_type.get(position).getLink()));
}
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
this.dialog.show();
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// AsyncTasker to draw data for ArrayAdapter
LoadMatchType lmt = new LoadMatchType(this);
lmt.execute();
}
@Override
public void onTaskComplete(ArrayList<MatchType> result) {
dialog.dismiss();
//result.remove(result.size()-1);
matches_type = result;
setListAdapter(new CustomAdapter());
}
}
//Custom Adapter
private class CustomAdapter extends ArrayAdapter<MatchType> {
CustomAdapter() {
super(getActivity(), R.layout.color_match_type, matches_type);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
View row = convertView;
if (row == null) {
LayoutInflater inflater = getActivity().getLayoutInflater();
row = inflater.inflate(R.layout.color_match_type, parent, false);
}
TextView tv_type = (TextView) row.findViewById(R.id.textView_type);
tv_type.setText(matches_type.get(position).getType());
TextView tv_tweet = (TextView) row.findViewById(R.id.textView_tweet);
tv_tweet.setText(matches_type.get(position).getTweet());
TextView tv_tph = (TextView) row.findViewById(R.id.textView_tph);
tv_tph.setText(matches_type.get(position).getTph());
return row;
}
}
public static Fragment newInstance(
FirstPageFragmentListener pageFragmentListener) {
// TODO Auto-generated method stub
footOddsFragment frag = new footOddsFragment();
main_caller = pageFragmentListener;
return frag;
}
}
//INTERFACE
interface AsyncTaskCompleteListener<T> {
public void onTaskComplete(ArrayList<MatchType> result);
}
片段B大致相同。
该应用程序将卡在 Fragment B 的 CustomAdapter 构造函数中,并且屏幕将是空白的。
哦,如果我放弃 Fragment B并在 Fragment A的 onListItemClick 中调用 Asynctasker_B ,一切都会正常工作。只是我不能按返回查看以前的列表。