2016-03-29 33 views
2

Ben table_row dinamik olarak oluşturuyordum, ancak tablo_layout.i dosyasında görüntülenemiyor, kodumda bir hata bulunamıyor. Kullanıcı her zaman table_row düğmesine basar auto_generate. İşte Biz ...Dinamik olarak TableRow oluşturma

submitButton.setOnClickListener(new View.OnClickListener() { 
    @Override 
    public void onClick(View v) { 

     getSerialNumber = serialNumber.getText().toString(); 
     getItems = items.getText().toString(); 
     getBrand = brand.getText().toString(); 
     getPrice = price.getText().toString(); 

     TableRow row = new TableRow(StoreFirstActivity.this); 
     LayoutParams layoutParams = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); 
     row.setLayoutParams(layoutParams); 

     TextView t = new TextView(StoreFirstActivity.this); 
     t.setLayoutParams(layoutParams); 
     t.setText(getSerialNumber.toString()); 

     TextView t1 = new TextView(StoreFirstActivity.this); 
     t1.setLayoutParams(layoutParams); 
     t1.setText(getItems.toString()); 

     TextView t2 = new TextView(StoreFirstActivity.this); 
     t2.setLayoutParams(layoutParams); 
     t2.setText(getBrand.toString()); 

     TextView t3 = new TextView(StoreFirstActivity.this); 
     t3.setLayoutParams(layoutParams); 
     t3.setText(getPrice.toString()); 


     row.addView(t); 
     row.addView(t1); 
     row.addView(t2); 
     row.addView(t3); 

     Log.i(TAG, getSerialNumber.toString()); 
     Log.i(TAG, getPrice.toString()); 
     Log.i(TAG, getItems.toString()); 

     tableLayout.addView(row); 

     serialNumber.setText(""); 
     items.setText(""); 
     brand.setText(""); 
     price.setText(""); 

     Toast.makeText(StoreFirstActivity.this, "Items Submitted", Toast.LENGTH_SHORT).show(); 

    } 
}); 

benim kodudur xml olduğunu.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     xmlns:app="http://schemas.android.com/apk/res-auto" 
     xmlns:tools="http://schemas.android.com/tools" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:paddingBottom="@dimen/activity_vertical_margin" 
     android:paddingLeft="@dimen/activity_horizontal_margin" 
     android:paddingRight="@dimen/activity_horizontal_margin" 
     android:paddingTop="@dimen/activity_vertical_margin" 
     app:layout_behavior="@string/appbar_scrolling_view_behavior" 
     tools:context="com.example.hamza.store.StoreFirstActivity" 
     android:orientation="vertical" 
     tools:showIn="@layout/activity_store_first"> 

     <ScrollView 
     android:layout_width="match_parent" 
     android:layout_height="200dp" 
     android:layout_marginTop="15dp" 
     android:id="@+id/scrollView"> 

     <TableLayout 
      android:layout_height="match_parent" 
      android:layout_width="match_parent" 
      android:id="@+id/tableLayout"> 
      <TableRow 
       android:id="@+id/one"> 

       <TextView 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:text="Y01398" 
        android:layout_marginLeft="10dp" 
        android:layout_column="0" 
        android:textColor="#808080" 
        android:id="@+id/textView7" /> 

       <TextView 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:text="Cigrate" 
        android:layout_column="1" 
        android:layout_marginLeft="45dp" 
        android:textColor="#808080" 
        android:id="@+id/textView8" /> 

       <TextView 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:text="Camel" 
        android:layout_marginLeft="52dp" 
        android:textColor="#808080" 
        android:id="@+id/textView9" /> 

       <TextView 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:text="5$" 
        android:layout_marginLeft="55dp" 
        android:textColor="#808080" 
        android:id="@+id/textView10" /> 
      </TableRow> 




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

Bu

i enter image description here

+0

Bu sorunun nedeni, hem TableRow hem de TextView öğelerine aynı yükseklik ve genişlik belirtmenizdir. Lütfen WRAP_CONTENT gibi TextView'a farklı düzen paramsları ayarlayın. –

+0

TextView'e farklı mizanpaj params ayarları yaptım ama hala çalışmıyor –

cevap

0

deneyin bir table_lyout içinde table_row göstermek istiyorum nasıl bu

TableRow row = new TableRow(StoreFirstActivity.this); 
    LayoutParams layoutParams = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); 
    row.setLayoutParams(layoutParams); 
    tableLayout.addView(row); 

    LinearLayout ll = new LinearLayout(StoreFirstActivity.this); 
    LinearLayout.LayoutParams llParams = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, 
      LayoutParams.WRAP_CONTENT); 
    ll.setOrientation(LinearLayout.VERTICAL); 
    ll.setLayoutParams(llParams); 

    TextView t = new TextView(StoreFirstActivity.this); 
    t.setLayoutParams(llParams); 
    t.setText(getSerialNumber.toString()); 

    TextView t1 = new TextView(StoreFirstActivity.this); 
    t1.setLayoutParams(llParams); 
    t1.setText(getItems.toString()); 

    TextView t2 = new TextView(StoreFirstActivity.this); 
    t2.setLayoutParams(llParams); 
    t2.setText(getBrand.toString()); 

    TextView t3 = new TextView(StoreFirstActivity.this); 
    t3.setLayoutParams(llParams); 
    t3.setText(getPrice.toString()); 

    ll.addView(t); 
    ll.addView(t1); 
    ll.addView(t2); 
    ll.addView(t3); 

    row.addView(ll); 
+0

Soruyu xml ile güncelledim. –

0

O vardı

ithalat android.view.ViewGroup.LayoutParams

o

ithalat android.widget.TableRow.LayoutParams

herşey olmalıdır şimdi gayet iyi çalışıyor.

İlgili konular