我的动态设计并没有出现。为什么?

时间:2017-11-13 04:29:05

标签: java android eclipse

我的设计没有出现在我的屏幕上。方法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));
}
}

这是我的activity_schedprof.xml,其中包含来自我的java类的动态数据库的维护:

<?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>

1 个答案:

答案 0 :(得分:0)

尝试添加Tablelayout高度,如match_parent或某些固定大小......