获得成功请求android后如何更改视图?

时间:2015-07-08 02:30:21

标签: android android-fragments request android-view

我有这段代码: public View onCreateView(LayoutInflater inflater,ViewGroup容器,Bundle savedInstanceState){

        tableView = inflater.inflate(R.layout.fragment_table, container, false);
        View layout = inflater.inflate(R.layout.fragment_1, container, false);


        if (roomArray == null || roomArray.isEmpty()) {
            roomArray = getTablesList(new VolleyCallback() {

                @Override
                public void onSuccess(ArrayList<RoomsClass> result) {

                    Toast.makeText(getActivity(), "onSuccess", Toast.LENGTH_LONG).show();
                }
            });
        } else {
            ArrayList<View> tableList = new ArrayList<>();

            ArrayList<Tables> tables;
            Toast.makeText(getActivity(), "IsNotNull", Toast.LENGTH_LONG).show();

            tables = roomArray.get(0).getTables();
            GridLayout gridLayout = (GridLayout) layout.findViewById(R.id.grid_layout);
            for (int i = 0; i < 1; i++) {
                tableView = inflater.inflate(R.layout.fragment_table, container, false);
                TextView textView = (TextView) tableView.findViewById(R.id.table_number);
                textView.setText(tables.get(i).getTableNumber());
                GridLayout.Spec row = GridLayout.spec(i / 5);
                GridLayout.Spec col = GridLayout.spec(i);
                GridLayout.LayoutParams params = new GridLayout.LayoutParams(row, col);
                gridLayout.addView(tableList.get(i), i, params);
            }
        }
        return layout;
    }

所以我有onSecces,但我无法为我的片段添加视图。我需要以某种方式在onSuccess之后调用所有方法,但是它的内部类使我无法处理任何内容。那么这样做的正确方法是什么?

2 个答案:

答案 0 :(得分:0)

你在createView中膨胀两个片段吗?

tableView = inflater.inflate(R.layout.fragment_table, container, false);
View layout = inflater.inflate(R.layout.fragment_1, container, false);

答案 1 :(得分:0)

你尝试使用handler来解决这个问题,使用handler可以避免在内部类中做某事。

Handler myHandler = new Handler() {  
          public void handleMessage(Message msg) {   
               switch (msg.what) {   
                    case a:   
                        //do somthing 
                        break;   
               }   
               super.handleMessage(msg);   
          }   
     };