我有一個ListView與ViewSwitcher項目。我們的目標是點擊一個列表項來切換ViewSwitcher視圖。輕擊按預期工作,但從輕敲項目滾動,然後返回有時會更改哪些項目正在顯示ViewSwitcher的第二個視圖。ViewSwitcher作爲ListView項目 - 如何在正確的ViewSwitcher項目上調用.showNext()?
這裏是我的ListView項佈局,ViewSwitcher是@ + ID /詳細信息:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android = "http://schemas.android.com/apk/res/android"
android:layout_width = "fill_parent"
android:layout_height = "wrap_content" >
<ViewSwitcher
android:id = "@+id/details"
android:layout_width = "fill_parent"
android:layout_height = "fill_parent"
android:measureAllChildren = "false" >
<!-- two views I want to switch between are here -->
</ViewSwitcher>
</RelativeLayout>
我的活動,發現@ ID /細節,並呼籲.showNext()。
public class MyActivity extends ListActivity {
private MySQLiteOpenHelper data;
private SimpleCursorAdapter adapter;
private Cursor cursor;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
String[] FROM = { "_id", "_id", "name", "name" };
int[] TO = { R.id.my_list_id, R.id.my_list_id2, R.id.my_list_name, R.id.my_list_name_details };
data = new MySQLiteOpenHelper(this);
cursor = data.myList();
startManagingCursor(cursor);
adapter = new SimpleCursorAdapter(this, R.layout.list_item, cursor, FROM, TO);
setListAdapter(adapter);
ListView list = getListView();
list.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> adapter, View view, int position, long id) {
ViewSwitcher item = (ViewSwitcher) view.findViewById(R.id.details);
item.showNext();
}
});
}
}
我認爲我的問題可能是@ ID /詳細信息實際上並沒有獨特的,滾動時如此不確定的行爲發生。
如果是這種情況,那麼我該如何爲每個ViewSwitcher分配一個唯一的ID或找到正確的ViewSwitcher來調用.showNext()?
的ArrayList?你覺得它沒有改變? –
是的,當我向後滾動時,它不被切換,並且一個*不同的*項被切換。 – mjwhitt
示例:列表中的10項,點擊#9,向上滾動,點擊#2(看不到#9),向下滾動,#9被夾在中間,#10 *被*切換。向上滾動並再次點擊#2,向下滾動,並且#9被切換。奇怪的不切換/切換似乎只發生在ListView中視圖之外的ViewSwitchers上。 – mjwhitt