2017-11-13 5 views
0

自分のデザインが画面に表示されません。メソッドaddHeaderAttendance()にはヘッダーが含まれ、addSchedule(ArrayList mysched)には自分のデータの表が取り込まれます。私の動的デザインは表示されません。どうして?

ScheduleProf.java:

public class ScheduleProf extends Activity{ 
    String data = ""; 
    TableLayout tl; 
    TableRow tr; 
    TextView label; 
    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_schedprof); 
     tl = (TableLayout) findViewById(R.id.maintable); 
     final BackgroundWorker bw = new BackgroundWorker(ScheduleProf.this,"ScheduleProf"); 
     Bundle get=getIntent().getExtras(); 

     final int profid=get.getInt("id"); //kunin ni schedpof from fragment 
     new Thread(new Runnable() { 
      public void run() { 
       data = bw.getProfSched(profid); 
       System.out.println(data); 

       runOnUiThread(new Runnable() { 

        @Override 
        public void run() { 
         addHeaderAttendance(); 
         ArrayList<Properties> mysched = parseSchedule(data); 
         addSchedule(mysched);      
        } 

       }); 
      } 
     }).start(); 
    } 
public ArrayList<Properties> parseSchedule(String result) { 

     ArrayList<Properties> mysched = new ArrayList<Properties>(); 
     try { 
      JSONArray jArray = new JSONArray(result); 
      for (int i = 0; i < jArray.length(); i++) { 
       JSONObject json_data = jArray.getJSONObject(i); 
       Properties user = new Properties(); 
       user.setRoom(json_data.getString("rooms_id")); 
       user.setCourse(json_data.getString("course_id")); 
       user.setSection(json_data.getString("sections_id")); 

       DateFormat formatter = new SimpleDateFormat("HH:mm:ss"); 
       String formatstart_time=json_data.getString("start_time"); 
       String formatend_time=json_data.getString("end_time"); 

       try { 
        Time startValue = new Time(formatter.parse(formatstart_time).getTime()); 
        Time endValue = new Time(formatter.parse(formatend_time).getTime()); 
        user.setStartTime(startValue);//error 
         user.setStartTime(endValue);//error 
         user.setDay("day"); 
         mysched.add(user); 
       } catch (ParseException e) { 
        // TODO Auto-generated catch block 
        e.printStackTrace(); 
       } 

      } 
     } catch (JSONException e) { 
      Log.e("log_tag", "Error parsing data " + e.toString()); 
     } 
     return mysched; 
    } 
@SuppressWarnings({ "rawtypes" }) 
public void addSchedule(ArrayList<Properties> mysched) { 


    addHeaderAttendance(); 

    for (Iterator i = mysched.iterator(); i.hasNext();) { 

     Properties p = (Properties) i.next(); 

     /** Create a TableRow dynamically **/ 
     tr = new TableRow(this); 

     /** Creating a TextView to add to the row **/ 
     label = new TextView(this); 
     label.setText(p.getStartTime() +"-"+p.getEndTime()+"<html><br></html>"+p.getDay()); 

     label.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, 
       LayoutParams.WRAP_CONTENT)); 
     label.setPadding(10, 10, 10, 10); 
     label.setBackgroundColor(Color.YELLOW); 
     LinearLayout Ll = new LinearLayout(this); 
     LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, 
       LayoutParams.WRAP_CONTENT); 
     params.setMargins(5, 2, 2, 2); 
     //Ll.setPadding(10, 5, 5, 5); 
     Ll.addView(label,params); 
     tr.addView((View)Ll); // Adding textView to tablerow. 

     TextView stats = new TextView(this); 
     stats.setText(p.getCourseId()+" "+p.getSection()+" "+p.getRoom()); 
     stats.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, 
       LayoutParams.WRAP_CONTENT)); 
     stats.setPadding(10, 10, 10, 10); 
     stats.setBackgroundColor(Color.GREEN); 
     Ll = new LinearLayout(this); 
     params = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, 
       LayoutParams.WRAP_CONTENT); 
     params.setMargins(0, 2, 2, 2); 
     //Ll.setPadding(10, 5, 5, 5); 
     Ll.addView(stats,params); 
     tr.addView((View)Ll); // Adding textview to tablerow. 

     // Add the TableRow to the TableLayout 
     tl.addView(tr, new TableLayout.LayoutParams(
       LayoutParams.FILL_PARENT, 
       LayoutParams.WRAP_CONTENT)); 
    } 
} 

void addHeaderAttendance(){ 

    /** Create a TableRow dynamically **/ 
    tr = new TableRow(this); 
    /** Creating a TextView to add to the row **/ 
    label = new TextView(this); 
    label.setText("Time and Day"); 
    label.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, 
      LayoutParams.WRAP_CONTENT)); 
    label.setPadding(10, 10, 10, 10); 
    label.setBackgroundColor(Color.parseColor("#FFD700")); 
    LinearLayout Ll = new LinearLayout(this); 
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, 
      LayoutParams.WRAP_CONTENT); 
    params.setMargins(5, 5, 5, 5); 
    //Ll.setPadding(10, 5, 5, 5); 
    Ll.addView(label,params); 
    tr.addView((View)Ll); // Adding textView to tablerow. 

    /** Creating Qty Button **/ 
    TextView place = new TextView(this); 
    place.setText("Course/Section/Room"); 
    place.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, 
      LayoutParams.WRAP_CONTENT)); 
    place.setPadding(10, 10, 10, 10); 
    place.setBackgroundColor(Color.parseColor("#008000")); 
    Ll = new LinearLayout(this); 
    params = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, 
      LayoutParams.WRAP_CONTENT); 
    params.setMargins(5, 5, 5, 5); 
    //Ll.setPadding(10, 5, 5, 5); 
    Ll.addView(place,params); 
    tr.addView((View)Ll); // Adding textview to tablerow. 

    // Add the TableRow to the TableLayout 
    tl.addView(tr, new TableLayout.LayoutParams(
      LayoutParams.FILL_PARENT, 
      LayoutParams.WRAP_CONTENT)); 
} 
} 

これは私のJavaクラスからのデータの動的集団に対するmaintableを含む私のactivity_schedprof.xmlです:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" > 
     <TableLayout 
      android:id="@+id/maintable" 
      android:layout_width="wrap_content" 
      android:layout_height="0dp" 
      android:stretchColumns="1,1,1" > 
     </TableLayout> 
</RelativeLayout> 

答えて

0

はmatch_parentまたはいくつかのようなTablelayoutの高さを追加しよう固定サイズ...

+0

omgそれは今hahahaha –

関連する問題