Advertisement
aunkang

onResponse

May 23rd, 2017
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.95 KB | None | 0 0
  1. public void onResponse(Call<PhotoItemCollectionDao> call, Response<PhotoItemCollectionDao> response) {
  2.                 if(response.isSuccessful()){
  3.                     PhotoItemCollectionDao dao = response.body();
  4.                     secondFragment.setDao(dao.getData());
  5.                     layout = (LinearLayout) rootView.findViewById(R.id.index);
  6.                     int childs = 0;
  7.                     int temp=0;
  8.                     int temp2=0;
  9.                     LinearLayout a = new LinearLayout(getContext());
  10.                     a.setOrientation(LinearLayout.HORIZONTAL);
  11.                     int count=0;
  12.                     for(int i=0; i<dao.getData().size();i++){
  13.                         temp2=i;
  14.                         if(count%2==0) {
  15.                             a = new LinearLayout(getContext());
  16.                             a.setOrientation(LinearLayout.HORIZONTAL);
  17.                         }
  18.                         if(dao.getData().get(i).getParent().equals("")) {
  19.                             childs = 0;
  20.                             while (true) {
  21.  
  22.                                 if ((dao.getData().get(i).getNode() + "").equals(dao.getData().get(childs).getpNode()) || dao.getData().get(i).getStep() != null) {
  23.                                     childs = 1000;
  24.                                     break;
  25.                                 }
  26.                                 else if(childs == dao.getData().size() - 1) {
  27.                                     childs = -1000;
  28.                                     break;
  29.                                 }
  30.                                 childs++;
  31.                             }
  32.                                 count += 1;
  33.                                 if (temp == 0) {
  34.                                     LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(300, 100);
  35.                                     lp.weight = 3;
  36.                                     View view = new View(getContext());
  37.                                     a.addView(view, lp);
  38.                                     lp = new LinearLayout.LayoutParams(
  39.                                             LinearLayout.LayoutParams.WRAP_CONTENT,
  40.                                             LinearLayout.LayoutParams.WRAP_CONTENT);
  41.                                     lp.weight = 3;
  42.                                     Button button = new Button(getContext());
  43.                                     if(childs==1000){
  44.                                         button.setTag("normal");
  45.                                     }
  46.                                     else if(childs==-1000){
  47.                                         button.setTag("unNormal");
  48.                                     }
  49.                                     button.setText(dao.getData().get(i).getAlbumnName());
  50.                                     button.setBackgroundResource(R.drawable.button_grid2);
  51.                                     button.setTextColor(Color.BLACK);
  52.                                     button.setTextSize(20);
  53.                                     button.setOnClickListener(clickListener);
  54.                                     a.addView(button, lp);
  55.                                     temp = 1;
  56.                                 } else {
  57.                                     LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
  58.                                             LinearLayout.LayoutParams.WRAP_CONTENT,
  59.                                             LinearLayout.LayoutParams.WRAP_CONTENT);
  60.                                     lp.weight = 3;
  61.  
  62.                                     Button button = new Button(getContext());
  63.                                     if(childs==1000){
  64.                                         button.setTag("normal");
  65.                                     }
  66.                                     else if(childs==-1000){
  67.                                         button.setTag("unNormal");
  68.                                     }
  69.                                     button.setText(dao.getData().get(i).getAlbumnName());
  70.                                     button.setBackgroundResource(R.drawable.button_grid2);
  71.                                     button.setTextSize(20);
  72.                                     button.setTextColor(Color.BLACK);
  73.                                     button.setOnClickListener(clickListener);
  74.                                     a.addView(button, lp);
  75.                                     layout.addView(a);
  76.                                     temp = 0;
  77.                                 }
  78.                                 childs = 0;
  79.  
  80.                         }
  81.                     }if(temp==1){
  82.                         LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
  83.                                 LinearLayout.LayoutParams.WRAP_CONTENT,
  84.                                 LinearLayout.LayoutParams.WRAP_CONTENT);
  85.                         lp.setMargins(0,0,0,0);
  86.                         lp.weight = 3;
  87.                         Button button = new Button(getContext());
  88.                         button.setText("");
  89.                         button.setBackgroundResource(R.drawable.button_grid2);
  90.                         button.setTextColor(Color.BLACK);
  91.                         button.setTextSize(20);
  92.                         button.setOnClickListener(clickListener);
  93.                         button.setVisibility(View.INVISIBLE);
  94.                         a.addView(button,lp);
  95.                         lp = new LinearLayout.LayoutParams(
  96.                                 LinearLayout.LayoutParams.WRAP_CONTENT,
  97.                                 LinearLayout.LayoutParams.WRAP_CONTENT);
  98.                         lp.setMargins(0,0,0,0);
  99.                         layout.addView(a, lp);
  100.                     }
  101.  
  102.                 }else{
  103.                     //handle
  104.                     try {
  105.                     } catch (Exception e) {
  106.                         e.printStackTrace();
  107.                     }
  108.                 }
  109.             }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement