を使用して作成されたグリッドがありTableLayout
ます。を動的に追加しTableRows
ていTableLayout
ます。レイアウトをフラグメントとして作成しましたが、そのフラグメントをフラグメントに追加するとFragmentActivity
、次のエラーが発生します。
Binary XML file line #25: Error inflating class fragment
これが私のコードです:
public class TodayPriceList extends Fragment {
LinearLayout llTop = null;
LinearLayout llPriceList = null;
RelativeLayout rlPriceTableHeading = null;
TableLayout priceTableHedaer = null;
TableLayout tlPriceList = null;
ScrollView svGridScroll = null;
TableRow row;
TextView tvSymbol = null;
TextView tvSharevolume = null;
TextView tvOpen = null;
TextView tvHigh = null;
TextView tvLow = null;
TextView tvLastTrade = null;
TextView symbol,shareVol,open,high,low,lastTrade;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.todaypricelist, container, false);
llTop = (LinearLayout)view.findViewById(R.id.ll_top);
llPriceList = (LinearLayout)view.findViewById(R.id.ll_priceList);
rlPriceTableHeading = (RelativeLayout)view.findViewById(R.id.rl_priceTable_heading);
llPriceList = (LinearLayout)view.findViewById(R.id.ll_priceList);
tlPriceList = (TableLayout)view.findViewById(R.id.priceTable);
priceTableHedaer = (TableLayout)view.findViewById(R.id.priceTableHedaer);
svGridScroll = (ScrollView)view.findViewById(R.id.ScrollView11);
tvSymbol = (TextView)view.findViewById(R.id.tvSymbol);
tvSharevolume = (TextView)view.findViewById(R.id.tvSharevolume);
tvOpen = (TextView)view.findViewById(R.id.tvOpen);
tvHigh = (TextView)view.findViewById(R.id.tvHigh);
tvLow = (TextView)view.findViewById(R.id.tvLow);
tvLastTrade = (TextView)view.findViewById(R.id.tvLastTrade);
//fillPriceTable(container);
priceTableHedaer.addView(tvSymbol);
priceTableHedaer.addView(tvSharevolume);
priceTableHedaer.addView(tvOpen);
priceTableHedaer.addView(tvHigh);
priceTableHedaer.addView(tvLow);
priceTableHedaer.addView(tvLastTrade);
//define array data
String[] dummy=new String[]{"AEL.N000","48.56","16.00","15.00","16.00","18.00"};
//Converting to dip unit
int dip = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_PX,
(float) 1, getResources().getDisplayMetrics());
for (int i = 0; i < 100; i++) {
row=new TableRow(container.getContext());
int rowcount=i%2;
if(rowcount>0){
row.setBackgroundColor(Color.parseColor("#E0F8F7"));
}
symbol = new TextView(container.getContext());
//t1.setTextColor(getResources().getColor(R.color.yellow));
shareVol = new TextView(container.getContext());
//t2.setTextColor(getResources().getColor(R.color.dark_red));
open=new TextView(container.getContext());
high=new TextView(container.getContext());
low=new TextView(container.getContext());
lastTrade=new TextView(container.getContext());
symbol.setText(dummy[0]);
shareVol.setText(dummy[1]);
open.setText(dummy[2]);
high.setText(dummy[3]);
low.setText(dummy[4]);
lastTrade.setText(dummy[5]);
symbol.setWidth(55*dip);
shareVol.setWidth(30*dip);
open.setWidth(30*dip);
high.setWidth(30*dip);
low.setWidth(30*dip);
lastTrade.setWidth(30*dip);
symbol.setGravity(android.view.Gravity.CENTER_VERTICAL);
shareVol.setGravity(android.view.Gravity.CENTER_VERTICAL);
open.setGravity(android.view.Gravity.CENTER_VERTICAL);
high.setGravity(android.view.Gravity.CENTER_VERTICAL);
low.setGravity(android.view.Gravity.CENTER_VERTICAL);
lastTrade.setGravity(android.view.Gravity.CENTER_VERTICAL);
symbol.setTextSize(12);
shareVol.setTextSize(12);
open.setTextSize(12);
high.setTextSize(12);
low.setTextSize(12);
lastTrade.setTextSize(12);
symbol.setHeight(20*dip);
symbol.setPadding(5, 0, 0, 0);
row.addView(symbol);
row.addView(shareVol);
row.addView(open);
row.addView(high);
row.addView(low);
row.addView(lastTrade);
tlPriceList.addView(row, new TableLayout.LayoutParams(
LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
}
rlPriceTableHeading.addView(priceTableHedaer);
svGridScroll.addView(tlPriceList);
llPriceList.addView(svGridScroll);
llTop.addView(rlPriceTableHeading);
llTop.addView(llPriceList);
return view;
}
}
これが私のlayout.xmlファイルです
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:id="@+id/ll_top"
>
<RelativeLayout
android:id="@+id/rl_priceTable_heading"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#E6E6E6" >
<TableLayout
android:id="@+id/priceTableHedaer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:stretchColumns="*"
android:shrinkColumns="*"
android:weightSum="50">
<TableRow >
<TextView android:id="@+id/tvSymbol"
android:layout_width="70dip"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:gravity="center|left"
android:text="@string/symbol"
android:textStyle="normal"
android:textColor="#2E2EFE"
android:textSize="11dip"
android:paddingLeft="5dip"
>
</TextView>
<TextView
android:id="@+id/tvSharevolume"
android:layout_width="45dip"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toRightOf="@+id/tvSymbol"
android:gravity="center|left"
android:text="@string/sharevolume"
android:textColor="#2E2EFE"
android:textSize="11dip"
android:textStyle="normal"
>
</TextView>
<TextView
android:id="@+id/tvOpen"
android:layout_width="35dip"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toRightOf="@+id/tvSharevolume"
android:gravity="center|left"
android:text="@string/open"
android:textColor="#2E2EFE"
android:textSize="11dip"
android:textStyle="normal" />
<TextView
android:id="@+id/tvHigh"
android:layout_width="45dip"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toRightOf="@+id/tvOpen"
android:gravity="center|left"
android:text="@string/high"
android:textColor="#2E2EFE"
android:textSize="11dip"
android:textStyle="normal" />
<TextView
android:id="@+id/tvLow"
android:layout_width="45dip"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toRightOf="@+id/tvHigh"
android:gravity="center|left"
android:text="@string/low"
android:textColor="#2E2EFE"
android:textSize="11dip"
android:textStyle="normal" />
<TextView
android:id="@+id/tvLastTrade"
android:layout_width="45dip"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toRightOf="@+id/tvLow"
android:gravity="center|left"
android:text="@string/lastTrad"
android:textColor="#2E2EFE"
android:textSize="11dip"
android:textStyle="normal" />
</TableRow>
</TableLayout>
</RelativeLayout>
<LinearLayout android:id="@+id/ll_priceList"
android:layout_height="wrap_content" android:layout_width="wrap_content">
<ScrollView android:id="@+id/ScrollView11"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:fillViewport="true">
<TableLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/priceTable"
android:layout_width="wrap_content"
android:background="#FFFFFF"
android:stretchColumns="*"
android:shrinkColumns="*"
android:layout_height="50dip">
</TableLayout>
</ScrollView>
</LinearLayout>
</LinearLayout>
編集:これは問題を修正した更新されたコードです。
public class TodayPriceList extends Fragment {
TableLayout tlPriceList = null;
TableRow row;
TextView tvSymbol = null;
TextView tvSharevolume = null;
TextView tvOpen = null;
TextView tvHigh = null;
TextView tvLow = null;
TextView tvLastTrade = null;
TextView symbol,shareVol,open,high,low,lastTrade;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.todaypricelist, container, false);
tlPriceList = (TableLayout)view.findViewById(R.id.priceTable);
tvSymbol = (TextView)view.findViewById(R.id.tvSymbol);
tvSharevolume = (TextView)view.findViewById(R.id.tvSharevolume);
tvOpen = (TextView)view.findViewById(R.id.tvOpen);
tvHigh = (TextView)view.findViewById(R.id.tvHigh);
tvLow = (TextView)view.findViewById(R.id.tvLow);
tvLastTrade = (TextView)view.findViewById(R.id.tvLastTrade);
//define array data
String[] dummy=new String[]{"AEL.N000","48.56","16.00","15.00","16.00","18.00"};
//Converting to dip unit
int dip = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_PX,
(float) 1, getResources().getDisplayMetrics());
for (int i = 0; i < 100; i++) {
row = new TableRow(tlPriceList.getContext());
int rowcount=i%2;
if(rowcount>0){
row.setBackgroundColor(Color.parseColor("#E0F8F7"));
}
symbol = new TextView(tlPriceList.getContext());
//t1.setTextColor(getResources().getColor(R.color.yellow));
shareVol = new TextView(tlPriceList.getContext());
//t2.setTextColor(getResources().getColor(R.color.dark_red));
open=new TextView(tlPriceList.getContext());
high=new TextView(tlPriceList.getContext());
low=new TextView(tlPriceList.getContext());
lastTrade=new TextView(tlPriceList.getContext());
symbol.setText(dummy[0]);
shareVol.setText(dummy[1]);
open.setText(dummy[2]);
high.setText(dummy[3]);
low.setText(dummy[4]);
lastTrade.setText(dummy[5]);
symbol.setWidth(55*dip);
shareVol.setWidth(30*dip);
open.setWidth(30*dip);
high.setWidth(30*dip);
low.setWidth(30*dip);
lastTrade.setWidth(30*dip);
symbol.setGravity(android.view.Gravity.CENTER_VERTICAL);
shareVol.setGravity(android.view.Gravity.CENTER_VERTICAL);
open.setGravity(android.view.Gravity.CENTER_VERTICAL);
high.setGravity(android.view.Gravity.CENTER_VERTICAL);
low.setGravity(android.view.Gravity.CENTER_VERTICAL);
lastTrade.setGravity(android.view.Gravity.CENTER_VERTICAL);
symbol.setTextSize(12);
shareVol.setTextSize(12);
open.setTextSize(12);
high.setTextSize(12);
low.setTextSize(12);
lastTrade.setTextSize(12);
symbol.setHeight(20*dip);
symbol.setPadding(5, 0, 0, 0);
row.addView(symbol);
row.addView(shareVol);
row.addView(open);
row.addView(high);
row.addView(low);
row.addView(lastTrade);
tlPriceList.addView(row, new TableLayout.LayoutParams(
LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
}
return view;
}
}