表示したいデータが3つあります。3 つすべてがデータの配列です。
String[] debtName = new String[10];
String[] debtAmount = new String[10];
String[] debtPayment = new String[10];
TableLayout で次のことを試みました。
public class DebtList extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.debtlist);
SharedPreferences sharedPref= getSharedPreferences("chaosdata", 0);
//Load Data
Bundle extras = getIntent().getExtras();
String[] debtName = new String[10];
String[] debtAmount = new String[10];
String[] debtRate = new String[10];
String[] debtPayment = new String[10];
TableLayout tl = (TableLayout) findViewById(R.id.debtListTableView);
TableRow tr = new TableRow(this);
TextView tv1 = new TextView(this);
TextView tv2 = new TextView(this);
TextView tv3 = new TextView(this);
for (int i=0;i<10;i++)
{
TextView tv0 = new TextView(this);
if (debtName[i] == null && extras != null)
{
debtName[i] = extras.getString("debtName");
debtAmount[i] = extras.getString("debtAmount");
debtRate[i] = extras.getString("debtRate");
debtPayment[i] = extras.getString("debtPayment");
}
tv1.setText("" + debtName[i]);
tv2.setText("" + debtAmount[i]);
tv3.setText("" + debtPayment[i]);
TableRow.LayoutParams trlp = new TableRow.LayoutParams();
trlp.span = 3;
tr.setLayoutParams(trlp);
tr.addView(tv0);
}
tl.addView(tr);
String str = "";
for (int i = 0;i<debtName.length; i++) {
str = str+debtName[i];
// Do not append comma at the end of last element
if(i<debtName.length-1){
str = str+",";
}
}
SharedPreferences.Editor editor= sharedPref.edit();
editor.putString("debtNames", str);
String str1 = "";
for (int i = 0;i<debtAmount.length; i++) {
str1 = str1+debtAmount[i];
// Do not append comma at the end of last element
if(i<debtAmount.length-1){
str1 = str1+",";
}
}
editor.putString("debtAmounts", str1);
String str2 = "";
for (int i = 0;i<debtRate.length; i++) {
str2 = str2+debtRate[i];
// Do not append comma at the end of last element
if(i<debtRate.length-1){
str2 = str2+",";
}
}
editor.putString("debtRates", str2);
String str3 = "";
for (int i = 0;i<debtPayment.length; i++) {
str3 = str2+debtPayment[i];
// Do not append comma at the end of last element
if(i<debtPayment.length-1){
str3 = str3+",";
}
}
editor.putString("debtRates", str3);
}
これは私の現在の.XMLファイルです
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/debtListTableView"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TableRow
android:id="@+id/tableRow1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/textAdditionalAmount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Additional Payments = $" />
<TextView
android:id="@+id/dispAdditionalAmount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="0.00" />
</TableRow>
<TableRow
android:id="@+id/tableRow2"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/textView1"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center_vertical"
android:text="Name" />
<TextView
android:id="@+id/textView2"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center_vertical"
android:text="Amount" />
<TextView
android:id="@+id/textOriginalPayoffDate"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center_vertical"
android:text="Payment" />
<TextView
android:id="@+id/dispOriginalPayoffDate"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center_vertical"
android:text="Months Remaining" />
</TableRow>
この編集されたバージョンはエラーをスローしませんが、データはまだ表示されていません。