3
我需要兩個滾動視圖中的listview,這顯然是不可能與Android,但這是客戶需要的。所以我試圖以編程方式誇大我的列表。我的表格單元格沒有顯示出我目前的設置。如果我調整xml文件中的設置,我可以在頂部顯示一行,但不顯示其他行。我在這裏做錯了什麼?Android創建列表以編程方式
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.alertsview);
inflater = (LayoutInflater)this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
topRows = new ArrayList<View>();
topLayout = (LinearLayout)findViewById(R.id.topListLayout);
bottomRows = new ArrayList<View>();
bottomLayout = (LinearLayout)findViewById(R.id.bottomListLayout);
addRecip = (Button) findViewById(R.id.addRecipient);
addRecip.setOnClickListener(this);
if (SugarLoafContext.currentSite.alertRecipients.size() >= 5)
addRecip.setVisibility(View.GONE);
else
addRecip.setVisibility(View.VISIBLE);
EventBus.subscribe(ConfigureAlertsNotification.class, this);
EventBus.publish(new ViewAlertsNotification());
}
public void setTopList()
{
topLayout.removeAllViews();
topRows.clear();
List<Camera> camList = new ArrayList<Camera>(SitesOrchestrator.getInstance().currentSite.cameraList);
for (int i = 0; i < camList.size(); i++)
{
String index = Integer.toString(i);
Camera cam = camList.get(i);
View row = inflater.inflate(R.layout.cameraalertrow, null);
TextView name = (TextView)row.findViewById(R.id.cameraNameAlerts);
CheckBox chk = (CheckBox)row.findViewById(R.id.camAlertChk);
name.setText(cam.name);
name.setTextColor(Color.GRAY);
chk.setOnCheckedChangeListener(this);
chk.setTag(index);
if (cam.isOnline)
{
chk.setEnabled(true);
if (cam.alertsEnabled && !chk.isChecked())
chk.setChecked(true);
else if (cam.alertsEnabled == false && chk.isChecked())
chk.setChecked(false);
}
else
{
chk.setChecked(cam.alertsEnabled);
chk.setEnabled(false);
name.setTextColor(Color.DKGRAY);
}
topRows.add(row);
topLayout.addView(row);
}
}
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:orientation="vertical"
android:fillViewport="true"
android:id="@+id/alertsTopScroll">
<LinearLayout
android:layout_height="fill_parent"
android:layout_width="fill_parent">
<TextView
android:id="@+id/alertsTopText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#CCCCCC"
android:text="@string/alerts_top_title"
android:gravity="center"
android:textColor="#000000"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true">
</TextView>
<LinearLayout
android:id="@+id/topListLayout"
android:layout_height="wrap_content"
android:layout_width="fill_parent">
</LinearLayout>
<TextView
android:id="@+id/alertsBottomText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#CCCCCC"
android:text="@string/alerts_bottom_title"
android:gravity="center"
android:textColor="#000000"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true">
</TextView>
<LinearLayout
android:id="@+id/bottomListLayout"
android:layout_height="wrap_content"
android:layout_width="wrap_content">
</LinearLayout>
<Button
android:id="@+id/addRecipient"
android:layout_height="50dp"
android:layout_width="fill_parent"
android:layout_centerHorizontal="true"
android:text="@string/addRecipient"/>
</LinearLayout>
</ScrollView>
(是的方法setTopList()被調用)
你能解釋客戶想要什麼嗎?他們想看什麼? – Estel
它會顯示一個文本視圖,然後是項目列表,然後是另一個文本視圖,然後是另一個項目列表,然後是一個按鈕。項目列表需要完全展開,整個屏幕可以滾動。無論如何,我繞過Android的限制並計算每個列表視圖中行的高度,將每個列表視圖擴展爲該高度,並且它們在滾動視圖中工作良好。 – spentak
您是否設置了絕對高度,即px或dip?你確定textviews在所有設備上都會有高低不平的高度嗎?在不同的屏幕分辨率下,會有不同數量的換行符,不同的設備上可能會使用不同高度的不同字體等等。 – thaussma