0

我有两个几乎相同的 ListFragment A & B,除了它们从各自的 Asynctasker 中提取数据。

onListItemClick 在A将导致 Fragment AB替换。但是,我的应用程序总是卡在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 ,一切都会正常工作。只是我不能按返回查看以前的列表。

4

1 回答 1

0

忘记 Fragment B。覆盖您的后按,if在其中放置一个以确定列表 B 是否处于活动状态,如果是,则将其改回,否则执行正常的后退功能。

public void onBackPressed() {
    //  Code here to change list or go back.
    return;
}
于 2012-06-27T15:40:51.340 回答