在我的應用程序中,我有一個字符串數組,我在其中存儲我的字符串。我行android,陣列適配器不顯示行的內容
private static String[] tokens = new String[1024];
格式,我在XML文件中創建,它是:
<TableLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:shrinkColumns="*"
android:stretchColumns="*" >
<TableRow
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:layout_marginTop="10dip"
android:layout_marginBottom="10dip" >
<TextView
android:id="@+id/outstanding_contractdate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#ffffff"
android:textSize="15sp" />
<TextView
android:id="@+id/outstanding_contractno"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#ffffff"
android:textSize="15sp" />
<TextView
android:id="@+id/outstanding_contractamount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:textColor="#ffffff"
android:textSize="15sp" />
</TableRow>
</TableLayout>
在的onCreate(),我定義爲:
lvOutstanding = (ListView) findViewById(R.id.outstanding_list);
myListAdapter = new MyListAdapter();
lvOutstanding.setAdapter(myListAdapter);
,這是我的適配器:
class MyListAdapter extends ArrayAdapter<String>{
MyListAdapter(){
super(MSOutStanding.this, R.layout.list_outstanding, tokens);
}
public View getView(int position, View convertView, ViewGroup parent){
View row = convertView;
if(row == null){
LayoutInflater inflater = getLayoutInflater();
row = inflater.inflate(R.layout.list_outstanding, parent, false);
}
TextView tvContDate = (TextView) row.findViewById(R.id.outstanding_contractdate);
TextView tvContNo = (TextView) row.findViewById(R.id.outstanding_contractno);
TextView tvContAmount = (TextView) row.findViewById(R.id.outstanding_contractamount);
if(position == 0)
count = 0;
else
count = 3;
if(arrayLoop>0){
tvContDate.setText(tokens[position * count]);
Log.i("Count:", tokens[position * count]);
tvContNo.setText(tokens[position * count + 1]);
Log.i("Count:", tokens[position * count +1]);
tvContAmount.setText(tokens[position * count + 2]);
Log.i("Count:", tokens[position * count+2]);
arrayLoop -= 3;
Log.i("Count:", String.valueOf(arrayLoop));
}
return(row);
}
}
正如你所看到的,在每一行我有三個textView,我想在每一行顯示每個三項數組。 「arrayLoop」是和int變量,保存了「tokens []」數組中的項目數。
現在,當我運行應用程序時,仿真器顯示1024行而沒有任何數據。我的錯誤在哪裏? 當我檢查logcat(感謝谷歌新的美麗的設計logCat!),沒有問題,並在數組中的前12項目有參數和那裏(12/3 = 4),我應該看到4行信息。不過,我有1024行,而不信息:(
arrayLoop是全局變量,其內容是我從服務器獲取的項目數。例如(在這種情況下),我從服務器中獲取12個項目並將其存儲在令牌數組中。 arrayLoop告訴我使用了tokens.lingth中的12個項目。 – Hesam