开发者

Android Dynamic Table Row creation problem

开发者 https://www.devze.com 2023-04-06 04:47 出处:网络
I am new to this site..Please indicate me if there are any wrong I have xml.That contain TableLayout.Table row dynamically insert.

I am new to this site..Please indicate me if there are any wrong I have xml.That contain TableLayout.Table row dynamically insert.

This is my xml :

    <?xml version="1.0" encoding="utf-8"?>
   <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="vertical"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:background="@drawable/wallpaper">

<ScrollView android:layout_width="fill_parent"  
            android:layout_height="wrap_content" 
            android:id="@+id/sView1" 
            android:scrollbars="vertical">

    <LinearLayout android:id="@+id/lLayout2" 
                  android:layout_width="fill_parent" 
                  android:layout_height="396dp">

        <HorizontalScrollView android:id="@+id/hScrollView1" 
                              android:layout_width="fill_parent" 
                              android:layout_height="wrap_content" >

            <LinearLayout android:id="@+id/lLayout3" 
                          android:layout_width="fill_parent" 
                          android:layout_height="fill_parent" 
                          android:orientation="horizontal">

                <TableLayout  android:stretchColumns="*" 
                              android:layout_width="fill_parent" 
                              android:layout_margin="5pt" 
                              android:layout_marginTop="5dp"  
                              android:id="@+id/lineTable" 
                              android:layout_height="fill_parent">

                </TableLayout>
            </LinearLayout>
        </HorizontalScrollView>
    </LinearLayout>
</ScrollView>



 <!-- Footer -->
    <LinearLayout android:id="@+id/header"
        android:background="#000000"
        android:layout_height="wrap_content"
        android:layout_width="fill_parent">

        <Button android:layout_width="wrap_content" 
                android:text="Cancel" 
                android:background="@drawable/btn_yellow"
                android:layout_height="wrap_content" 
                android:layout_marginLeft="5dp"
                android:layout_marginRight="190dp"
                android:id="@+id/button2" 
                android:textColor="#FFFFFF"
                android:onClick="onCancelAction">
       </Button>

        <Button android:layout_width="wrap_content" 
                android:text="Complete" 
                android:background="@drawable/btn_yellow"
                android:layout_height="wrap_content" 
                android:textColor="#FFFFFF"
                android:id="@+id/button2" 
                android:onClick="onCompleteAction">
       </Button>
    </LinearLayout>

This is dynamic table row creation :

    private  void loadTableLayout(){

    TableLayout.LayoutParams rowLp = new TableLayout.LayoutParams(
            ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT,
            1.0f);
    TableRow.LayoutParams cellLp = new TableRow.LayoutParams(
            ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT,
            1.0f);

    //Table Header
    TableRow th = new TableRow(this);

    TextView thCode = new TextView(this);
    thCode.setTextSize(1, 12);
    thCode.setTextColor(Color.BLACK);
    thCode.setText("Criteria");
    thCode.setPadding(10, 0, 12, 0);
    th.addView(thCode,cellLp); 

    TextView thDes = new TextView(this);
    thDes.setTextSize(1, 12);
    thDes.setTextColor(Color.BLACK);
    thDes.setText("Name");
    thDes.setPadding(10, 0, 16, 0);
    th.addView(thDes,cellLp); 

    TextView thQty = new TextView(this);
    thQty.setTextSize(1, 12);
    thQty.setText("DisQty");
    thQty.setTextColor(Color.BLACK);
    thQty.setPadding(10, 0, 10, 0);
    th.addView(thQty,cellLp); 

    TextView thValue = new TextView(this);
    thValue.setTextSize(12);
    thValue.setText("DisValue");
    thValue.setPadding(10, 0, 10, 0);
    thValue.setTextColor(Color.BLACK);
    th.addView(thValue,cellLp); 

    TextView thDisVal = new TextView(this);
    thDisVal.setTextSize(12);
    thDisVal.setText("DisProductCode");
    thDisVal.setPadding(10, 0, 8, 0);
    thDisVal.setTextColor(Color.BLACK);
    th.addView(thDisVal,cellLp); 
    th.setBackgroundDrawable(getResources().getDrawable(R.drawable.table_shape));
    tl.addView(th,rowLp);

    if(lineDisList.size() > 0){
        //dynamic Table Contents
        for (int i = 0; i <lineDisList.size(); i++) {

            TableRow tr = new TableRow(this);   
            tr.setTag(i);

            //Set PDA Top panel data, when the list is load
            if(i == 0){

            }
            System.out.println(" --- " + lineDisList.get(i).getProductCode());
            System.out.println(" --- " + lineDisList.get(i).getCriteriaName());
            System.out.println(" --- " + lineDisList.get(i).getDiscountQty());
            System.out.println(" --- " + lineDisList.get(i).getDiscountValue());
            System.out.println(" --- " + lineDisList.get(i).getDiscountProductCode().length);


            TextView critiria = new TextView(this);
            critiria.setTextSize(12);
            critiria.setText(lineDisList.get(i).getProductCode());
            critiria.setPadding(10, 0, 10, 0);
            tr.addView(critiria,cellLp); 



            TextView description = new TextView(this);
            description.setTextSize(12);
            description.setText(lineDisList.get(i).getCriteriaName());
            description.setPadding(10, 0, 10, 0);
            description.setTextColor(Color.BLACK);
            tr.addView(description,cellLp);

            TextView disValue = new TextView(this);
            disValue.setTextSize(12);
            disValue.setPadding(10, 0, 10, 0);
            disValue.setTextColor(Color.BLACK);
            disValue.setText(Double.toString(lineDisList.get(i).getDiscountValue()));
            tr.addView(disValue,cellLp);


            TextView disQuantity = new TextView(this);
            disQuantity.setTextSize(12);
            disQuantity.setText("0.00");
            disQuantity.setPadding(10, 0, 10, 0);
            disQuantity.setTextColor(Color.BLACK);
            tr.addView(disQuantity,cellLp);

            tr.setBackgroundDrawable(getResources().getDrawable(R.drawable.table_shape));
            tl.addView(开发者_开发百科tr,rowLp);

        }
    }

}

I got this kind of error:

    09-21 17:18:01.959: ERROR/AndroidRuntime(389): FATAL EXCEPTION: main
09-21 17:18:01.959: ERROR/AndroidRuntime(389): java.lang.StackOverflowError
09-21 17:18:01.959: ERROR/AndroidRuntime(389):     at android.view.View.draw(View.java:6880)
09-21 17:18:01.959: ERROR/AndroidRuntime(389):     at android.view.ViewGroup.drawChild(ViewGroup.java:1646)
09-21 17:18:01.959: ERROR/AndroidRuntime(389):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
09-21 17:18:01.959: ERROR/AndroidRuntime(389):     at android.view.View.draw(View.java:6883)
09-21 17:18:01.959: ERROR/AndroidRuntime(389):     at android.view.ViewGroup.drawChild(ViewGroup.java:1646)
09-21 17:18:01.959: ERROR/AndroidRuntime(389):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
09-21 17:18:01.959: ERROR/AndroidRuntime(389):     at android.view.ViewGroup.drawChild(ViewGroup.java:1644)
09-21 17:18:01.959: ERROR/AndroidRuntime(389):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
09-21 17:18:01.959: ERROR/AndroidRuntime(389):     at android.view.ViewGroup.drawChild(ViewGroup.java:1644)
09-21 17:18:01.959: ERROR/AndroidRuntime(389):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
09-21 17:18:01.959: ERROR/AndroidRuntime(389):     at android.view.View.draw(View.java:6986)
09-21 17:18:01.959: ERROR/AndroidRuntime(389):     at android.widget.FrameLayout.draw(FrameLayout.java:357)
09-21 17:18:01.959: ERROR/AndroidRuntime(389):     at android.widget.HorizontalScrollView.draw(HorizontalScrollView.java:1409)
09-21 17:18:01.959: ERROR/AndroidRuntime(389):     at android.view.ViewGroup.drawChild(ViewGroup.java:1646)
09-21 17:18:01.959: ERROR/AndroidRuntime(389):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
09-21 17:18:01.959: ERROR/AndroidRuntime(389):     at android.view.ViewGroup.drawChild(ViewGroup.java:1644)
09-21 17:18:01.959: ERROR/AndroidRuntime(389):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
09-21 17:18:01.959: ERROR/AndroidRuntime(389):     at android.view.View.draw(View.java:6986)
09-21 17:18:01.959: ERROR/AndroidRuntime(389):     at android.widget.FrameLayout.draw(FrameLayout.java:357)
09-21 17:18:01.959: ERROR/AndroidRuntime(389):     at android.widget.ScrollView.draw(ScrollView.java:1409)
09-21 17:18:01.959: ERROR/AndroidRuntime(389):     at android.view.ViewGroup.drawChild(ViewGroup.java:1646)
09-21 17:18:01.959: ERROR/AndroidRuntime(389):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
09-21 17:18:01.959: ERROR/AndroidRuntime(389):     at android.view.View.draw(View.java:6883)
09-21 17:18:01.959: ERROR/AndroidRuntime(389):     at android.view.ViewGroup.drawChild(ViewGroup.java:1646)
09-21 17:18:01.959: ERROR/AndroidRuntime(389):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
09-21 17:18:01.959: ERROR/AndroidRuntime(389):     at android.view.View.draw(View.java:6883)
09-21 17:18:01.959: ERROR/AndroidRuntime(389):     at android.widget.FrameLayout.draw(FrameLayout.java:357)
09-21 17:18:01.959: ERROR/AndroidRuntime(389):     at android.view.ViewGroup.drawChild(ViewGroup.java:1646)
09-21 17:18:01.959: ERROR/AndroidRuntime(389):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
09-21 17:18:01.959: ERROR/AndroidRuntime(389):     at android.view.ViewGroup.drawChild(ViewGroup.java:1644)
09-21 17:18:01.959: ERROR/AndroidRuntime(389):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
09-21 17:18:01.959: ERROR/AndroidRuntime(389):     at android.view.ViewGroup.drawChild(ViewGroup.java:1644)
09-21 17:18:01.959: ERROR/AndroidRuntime(389):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
09-21 17:18:01.959: ERROR/AndroidRuntime(389):     at android.view.View.draw(View.java:6883)
09-21 17:18:01.959: ERROR/AndroidRuntime(389):     at android.view.ViewGroup.drawChild(ViewGroup.java:1646)
09-21 17:18:01.959: ERROR/AndroidRuntime(389):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
09-21 17:18:01.959: ERROR/AndroidRuntime(389):     at android.view.ViewGroup.drawChild(ViewGroup.java:1644)
09-21 17:18:01.959: ERROR/AndroidRuntime(389):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
09-21 17:18:01.959: ERROR/AndroidRuntime(389):     at android.view.View.draw(View.java:6883)
09-21 17:18:01.959: ERROR/AndroidRuntime(389):     at android.widget.FrameLayout.draw(FrameLayout.java:357)
09-21 17:18:01.959: ERROR/AndroidRuntime(389):     at android.view.ViewGroup.drawChild(ViewGroup.java:1646)
09-21 17:18:01.959: ERROR/AndroidRuntime(389):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
09-21 17:18:01.959: ERROR/AndroidRuntime(389):     at android.view.ViewGroup.drawChild(ViewGroup.java:1644)
09-21 17:18:01.959: ERROR/AndroidRuntime(389):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
09-21 17:18:01.959: ERROR/AndroidRuntime(389):     at android.view.View.draw(View.java:6883)
09-21 17:18:01.959: ERROR/AndroidRuntime(389):     at android.widget.FrameLayout.draw(FrameLayout.java:357)
09-21 17:18:01.959: ERROR/AndroidRuntime(389):     at android.view.ViewGroup.drawChild(ViewGroup.java:1646)
09-21 17:18:01.959: ERROR/AndroidRuntime(389):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
09-21 17:18:01.959: ERROR/AndroidRuntime(389):     at android.view.ViewGroup.drawChild(ViewGroup.java:1644)
09-21 17:18:01.959: ERROR/AndroidRuntime(389):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
09-21 17:18:01.959: ERROR/AndroidRuntime(389):     at android.view.ViewGroup.drawChild(ViewGroup.java:1644)
09-21 17:18:01.959: ERROR/AndroidRuntime(389):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
09-21 17:18:01.959: ERROR/AndroidRuntime(389):     at android.view.View.draw(View.java:6883)
09-21 17:18:01.959: ERROR/AndroidRuntime(389):     at android.view.ViewGroup.drawChild(ViewGroup.java:1646)
09-21 17:18:01.959: ERROR/AndroidRuntime(389):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
09-21 17:18:01.959: ERROR/AndroidRuntime(389):     at android.view.ViewGroup.drawChild(ViewGroup.java:1644)
09-21 17:18:01.959: ERROR/AndroidRuntime(389):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
09-21 17:18:01.959: ERROR/AndroidRuntime(389):     at android.view.View.draw(View.java:6883)
09-21 17:18:01.959: ERROR/AndroidRuntime(389):     at android.widget.FrameLayout.draw(FrameLayout.java:357)
09-21 17:18:01.959: ERROR/AndroidRuntime(389):     at android.view.ViewGroup.drawChild(ViewGroup.java:1646)
09-21 17:18:01.959: ERROR/AndroidRuntime(389):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
09-21 17:18:01.959: ERROR/AndroidRuntime(389):     at android.view.ViewGroup.drawChild(ViewGroup.java:1644)
09-21 17:18:01.959: ERROR/AndroidRuntime(389):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
09-21 17:18:01.959: ERROR/AndroidRuntime(389):     at android.view.View.draw(View.java:6883)
09-21 17:18:01.959: ERROR/AndroidRuntime(389):     at android.widget.FrameLayout.draw(FrameLayout.java:357)
09-21 17:18:01.959: ERROR/AndroidRuntime(389):     at com.android.internal.policy.impl.PhoneWindow$DecorView.draw(PhoneWindow.java:1862)
09-21 17:18:01.959: ERROR/AndroidRuntime(389):     at android.view.ViewRoot.draw(ViewRoot.java:1522)
09-21 17:18:01.959: ERROR/AndroidRuntime(389):     at android.view.ViewRoot.performTraversals(ViewRoot.java:1258)
09-21 17:18:01.959: ERROR/AndroidRuntime(389):     at android.view.ViewRoot.handleMessage(ViewRoot.java:1859)
09-21 17:18:01.959: ERROR/AndroidRuntime(389):     at android.os.Handler.dispatchMessage(Handler.java:99)
09-21 17:18:01.959: ERROR/AndroidRuntime(389):     at android.os.L

Please kindly request everybody, if you know any suggestion or idea please advice me what is wrong in my code?

Thanks


following links may help you.

http://www.stealthcopter.com/blog/2010/01/android-eclipse-and-problems-with-dynamic-tables-adding-rows/

how to add child to tablerow dynamically in android?

http://en.androidwiki.com/wiki/Dynamically_adding_rows_to_TableLayout

Thank you.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号