我有一個使用FrameLayout
與屏幕分割成左側導航和右側的內容面板主要活動。左側面板用於導航,將不同的佈局加載到右側面板(稱爲contentLayout
),該面板可以粘貼多個佈局。我在onItemClickListener
s的左側導航面板中有ListView
。在他們分開onItemClick
方法,我用contentLayout.removeAllViews()
然後誇大他們的佈局,像這樣:一個ListView控件,第二佈局不更新
private final OnItemClickListener redListener = new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
contentLayout.removeAllViews();
if (myFirstClassLayout == null) {
myFirstClassLayout = FirstClassLayout.getLayout(
layoutInflater,
MyActivity.this,
resources,
new ArrayList<String>(),
new ArrayList<Desc>()
);
}
CommonClass.updateListeners();
if (FirstClassLayout != null) contentLayout.addView(myFirstClassLayout);
}
};
private final OnItemClickListener blueListener = new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
contentLayout.removeAllViews();
if (mySecondClassLayout== null) {
mySecondClassLayout = SecondClassLayout.getLayout(
layoutInflater,
MyActivity.this,
resources,
new ArrayList<String>(),
textList,
new ArrayList<Desc>(),
hash
);
}
CommonClass.updateListeners();
if (SecondClassLayout != null) contentLayout.addView(mySecondClassLayout);
}
};
在這兩個FirstClassLayout
和SecondClassLayout
,我吹一個ThirdClassLayout
包含動態ListView
(姑且稱之爲commonListView
),使得使用的一個ArrayAdapter<String>
。 ListView
是一個listChoiceIndicatorSingle
樣式視圖,這意味着它在每個列表項右側顯示一個類似單選按鈕的圖標。
當應用程序啓動時,正確的內容面板爲空。如果我觸發了redListener
或blueListener
,它將在右側的內容面板中顯示commonListView
,但未選擇任何列表項目。如果我先觸發紅色,然後觸發藍色,然後在commonListView
中進行選擇,則更改會反射回FirstClassLayout
,這太棒了!然而,當我繼續通過選擇commonListView
從FirstClassLayout別的東西,然後觸發blueListener
去SecondClassLayout
,在SecondClassLayout
的commonListView
並不反映我的選擇。相反,當我最後一次使用SecondClassLayout
時,它卡在我選擇的項目上。
出現這種情況,如果我執行相反的順序測試,所以根據我上次觸發該聽衆,去年聽衆和佈局將有超過兩種佈局適當的UI synching控制。我首先觸發的那個似乎只能控制自己。我需要兩個聽衆能夠在任何給定時間在兩個佈局上顯示完全相同的ListView
選定項目。
的commonListView
從去年佈局先佈局synching通過CommonClass.updateListeners()
實現其作用:
adapter.clear();
for (String title: statusSet) adapter.add(title);
adapter.notifyDataSetChanged();
commonListView.setItemChecked(positionOfItemChecked, true);
Log.i(TAG, "position checked = " + positionOfItemChecked);
adapter.notifyDataSetChanged();
由於這一工程從去年佈局觸發首先,我想這必須與一個UI刷新問題,但我到處搜尋了一個很好的解決方案並嘗試了所有建議。 0123'語句在LogCat
中爲第一個或最後一個佈局觸發正確輸出,所以我知道它正確地打上了代碼。我只是不明白爲什麼第一個無法控制最後一個。我已經試過:
commonListView.invalidate();
((BaseAdapter) commonListView.getAdapter()).notifyDataSetChanged();
和AsyncTask
和其他幾個人,但似乎沒有什麼上刷新的第一個佈局,使其第二匹配工作。有沒有人遇到過這樣的問題?有誰知道如何解決或解決這個問題?
我剛剛在contentLayout.addView裏面加了同樣的if塊。在if區塊外面試過它。第二個佈局的問題仍然不清晰。 – jdynamite 2012-07-31 14:09:59