2011-07-04 17 views
0

xmlで行うのではなく、javaviewでtextviewオブジェクトのスパンを設定する方法はありますか?私はLayoutParamsを使用して他の誰かのソリューションを試しました。私はそれを正しく実装していないのか、それとも間違った解決策であるのか、あるいは私のミスがコード内にあるのか分からないのかどうかはわかりませんが、アプリケーションがクラッシュする原因になります。どんな助けもありがたいです、下に自分のコードを投稿しています。TableLayoutのTextViewの動的スパン調整

package com.szymon.atrium; 

import java.util.ArrayList; 
import java.util.GregorianCalendar; 

import android.app.Activity; 
import android.os.Bundle; 
import android.widget.TableLayout; 
import android.widget.TableRow; 
import android.widget.TableRow.LayoutParams; 


public class TapeChart extends Activity 
{ 
private ArrayList<Room> rooms; 
private ArrayList<Arrival> arrivals; 
private GregorianCalendar startDate = new GregorianCalendar(2011,1,1); 
private GregorianCalendar endDate = new GregorianCalendar(2011,1,10); 
private ArrivalGrid grid = new ArrivalGrid(arrivals, rooms, startDate.getTime(), endDate.getTime()); 

private ArrayList<ArrayList<Cell>> displayArrival = grid.displayArrivalGrid(); 
private ArrayList<ArrayList<Cell>> displayRooms = grid.displayRoomGrid(); 

@Override 
public void onCreate(Bundle bundle) 
{ 
    super.onCreate(bundle); 
    setContentView(R.layout.tape); 

    TableLayout tbl = (TableLayout)findViewById(R.id.tapeChart); 

    for(ArrayList<Cell> a : displayRooms) 
    { 
     TableRow newRow = new TableRow(this); 

     for(Cell c : a) 
     { 
      LayoutParams param = new LayoutParams(); 
      param.span=c.getColSpan(); 

      MyTextView cell = new MyTextView(this); 
      cell.setText(c.getContent()); 
      cell.setLayoutParams(param); 

      newRow.addView(cell); 
     } 

     tbl.addView(newRow); 
    } 
} 

public TableLayout getArrivalsTableLayout() 
{ 

    return null; 
} 

public void getRoomTableLayout() 
{ 


} 

}

答えて

0

このlinkでのコードの助けを借りて、私は、Javaコード側で動的に行を作成しながら、その

`TableRow.LayoutParams rowSpanLayout = new TableRow.LayoutParams(TableRow.LayoutParams.FILL_PARENT, TableRow.LayoutParams.WRAP_CONTENT); 
    rowSpanLayout.span = 3; 
    TextView textView = new TextView(this); 
    textView.setText("Text Title"); 
    tableRow.addView(textView, rowSpanLayout);` 

のように、この問題を達成持っています。

関連する問題