1

레이아웃 인플레이터를 사용하여 테이블 행을 테이블에 추가하려고합니다.선형 레이아웃의 인플레이터를 사용하여 tablerow 추가하기

여기 여기

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

    <ScrollView 
    android:id="@+id/ScrollView1" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_marginTop="75dp"> 
    <TableLayout 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:orientation="vertical" 
android:id="@+id/myTableLayout1"> 

<TableRow android:layout_marginTop="1dp" android:layout_marginLeft="10dp"> 

    </TableRow> 
    </TableLayout> 

    </ScrollView> 
    </LinearLayout> 

customlistviewitem.xml라는 나의 XML 파일, 나는 테이블

LinearLayout l = (LinearLayout) findViewById(R.id.mylayout1); 
      LayoutInflater linflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
      JSONArray jArray; 
      try { 
       jArray = new JSONArray(result); 

      JSONObject json_data=null; 
      for(int i=0;i<jArray.length();i++){ 
       //Log.e("Carlist","Result" +result); 
       json_data = jArray.getJSONObject(i); 
        int ct_id = json_data.getInt("id"); 
        String make = json_data.getString("make"); 
        String model = json_data.getString("model"); 
        String price = json_data.getString("price"); 

        TableRow tr = new TableRow(this); 
         tr.setId(ct_id); 
         tr.setClickable(true); 

         tr.setOnClickListener(new OnClickListener() { 

           @Override 
           public void onClick(final View v) { 

            String sdet_id; 
            int det_id; 
         //   v.setBackgroundColor(Color.GRAY); 
            det_id = v.getId(); 
            sdet_id = String.valueOf(det_id); 
            final Intent i = new Intent(); 
            i.setClassName("demo.example.com", "demo.example.com.cardetails"); 
            i.putExtra("Det_id", sdet_id); 
            startActivity(i); 

          //  v.setBackgroundColor(Color.TRANSPARENT); 
            // TODO Auto-generated method stub 
           } 
          }); 
         TableLayout.LayoutParams tableRowParams= 
           new TableLayout.LayoutParams 
           (TableLayout.LayoutParams.FILL_PARENT,TableLayout.LayoutParams.WRAP_CONTENT); 

          int leftMargin=20; 
          int topMargin=10; 
          int rightMargin=15; 
          int bottomMargin=20; 

          tableRowParams.setMargins(leftMargin, topMargin, rightMargin, bottomMargin); 

          tr.setLayoutParams(tableRowParams); 

           /* Create a Button to be the row-content. */ 
         ImageView myimage = new ImageView(this); 

         BitmapFactory.Options bmOptions; 
         bmOptions = new BitmapFactory.Options(); 
         bmOptions.inSampleSize = 1; 
         Bitmap bm = LoadImage(image_URL, bmOptions); 
         myimage.setImageBitmap(bm); 
         tr.addView(myimage); 
         TextView tmake=new TextView(this); 
         // tmake.setText(make); 
         tmake.setText(Html.fromHtml("<H1>" + make)); 
         tr.addView(tmake); 

         TextView tmodel=new TextView(this); 
         tmodel.setText(Html.fromHtml("<b><H1>" + "&nbsp;&nbsp;" + "€" + price + "</b></H1></br></br>")); 
         tr.addView(tmodel); 



        /* Add row to TableLayout. */ 
        // tr.setPadding(50, 0, 0, 0); 
         tl.addView(tr); 
         View v = new View(this); 
         v.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.FILL_PARENT, 1)); 
         v.setBackgroundColor(Color.rgb(51, 51, 51)); 
         tl.addView(v); 

      } 
      } catch (JSONException e) { 
       // TODO Auto-generated catch block 
       e.printStackTrace(); 
      } 

이 테이블 행을 추가하지 않는 행을 추가하기 위해 사용하고있는 코드입니다. 행과 텍스트 항목을 추가하려면 어떻게해야합니까?

+0

[TableLayout을 내부 동적 테이블 행에 대한 포스트를 확인 (http://stackoverflow.com/questions/7683154/android-softkeyboard-enter-the-numeric-value-into-edittext-very-slow) – Venky

답변

1

LayoutParams가 The TableRow로 설정되고 Views가 TableRow에 추가 된 것처럼 보이는 경우 설정 레이아웃 매개 변수에 주석을 달고 결과를 확인해보십시오.

LinearLayout l = (LinearLayout) findViewById(R.id.mylayout1); 
      LayoutInflater linflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
      JSONArray jArray; 
      try { 
       jArray = new JSONArray(result); 

      JSONObject json_data=null; 
      for(int i=0;i<jArray.length();i++){ 
       //Log.e("Carlist","Result" +result); 
       json_data = jArray.getJSONObject(i); 
        int ct_id = json_data.getInt("id"); 
        String make = json_data.getString("make"); 
        String model = json_data.getString("model"); 
        String price = json_data.getString("price"); 

        TableRow tr = new TableRow(this); 
         tr.setId(ct_id); 
         tr.setClickable(true); 

         tr.setOnClickListener(new OnClickListener() { 

           @Override 
           public void onClick(final View v) { 

            String sdet_id; 
            int det_id; 
         //   v.setBackgroundColor(Color.GRAY); 
            det_id = v.getId(); 
            sdet_id = String.valueOf(det_id); 
            final Intent i = new Intent(); 
            i.setClassName("demo.example.com", "demo.example.com.cardetails"); 
            i.putExtra("Det_id", sdet_id); 
            startActivity(i); 

          //  v.setBackgroundColor(Color.TRANSPARENT); 
            // TODO Auto-generated method stub 
           } 
          }); 


           /* Create a Button to be the row-content. */ 
         ImageView myimage = new ImageView(this); 

         BitmapFactory.Options bmOptions; 
         bmOptions = new BitmapFactory.Options(); 
         bmOptions.inSampleSize = 1; 
         Bitmap bm = LoadImage(image_URL, bmOptions); 
         myimage.setImageBitmap(bm); 
         tr.addView(myimage); 
         TextView tmake=new TextView(this); 
         // tmake.setText(make); 
         tmake.setText(Html.fromHtml("<H1>" + make)); 
         tr.addView(tmake); 

         TextView tmodel=new TextView(this); 
         tmodel.setText(Html.fromHtml("<b><H1>" + "&nbsp;&nbsp;" + "€" + price + "</b></H1></br></br>")); 
         tr.addView(tmodel); 



        /* Add row to TableLayout. */ 
        // tr.setPadding(50, 0, 0, 0); 
         tl.addView(tr); 
         View v = new View(this); 

         v.setBackgroundColor(Color.rgb(51, 51, 51)); 
         tl.addView(v); 

      } 
      } catch (JSONException e) { 
       // TODO Auto-generated catch block 
       e.printStackTrace(); 
      } 
+0

TableRow tr = 새 TableRow (this); "생성자 Tablerow (mainactivity.getdata)가 정의되지 않았습니다."오류 발생 – user1197941

+0

이 줄을 TableRow로 변경 tr = new TableRow (this); to TableRow tr = 새로운 TableRow (mainactivity.this); – jeet

+0

나는 테이블에 아무것도 추가하지 않았다. 로그는 아이템이 추가되고 있음을 보여준다. – user1197941

관련 문제