在首頁,它有listView
(從MySQL檢索)和popup Menu
,其中popup Menu
有視圖頁。還有listView
。如何在同一個tabAdapter中傳遞兩個不同的ID?
視圖
當首頁或視圖點擊列表,它會去片段其中有4個標籤,並允許用戶做編輯b在身份證上。
當首頁列表點擊
public static int ID;
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> listView, View view,
int position, long id) {
ID = search.get(position).getID();
Toast.makeText(getApplicationContext(), "Edit" + ID, Toast.LENGTH_LONG).show();
Intent intent = new Intent(getApplicationContext(), ActivityB.class);
intent.putExtra("ID", ID); // pass to tabAdapter
intent.putExtra("name", name); // pass to tabAdapter
startActivity(intent);
}
});
當查看點擊
public static int ID;
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> listView, View view,
int position, long id) {
ID = search.get(position).getID();
Toast.makeText(getApplicationContext(), "Edit" + ID, Toast.LENGTH_LONG).show();
Intent intent = new Intent(getApplicationContext(), ActivityB.class);
intent.putExtra("ID", ID); // pass to tabAdapter
intent.putExtra("name", name); // pass to tabAdpter
startActivity(intent);
}
});
TabAdapter
public Fragment getItem(int index) {
// TODO Auto-generated method stub
if(index == 0) {
Fragment fragment=new EditInformation();
Bundle bundle = new Bundle();
bundle.putInt("ID", HomePage.ID);
fragment.setArguments(bundle);
return fragment;
}
}
EditInformation
Bundle bundle = this.getArguments();
if (getArguments() != null) {
ID = bundle.getInt("ID");
}
Toast.makeText(getActivity(),"SS"+ID,Toast.LENGTH_LONG).show();
當我點擊主頁上的列表中,它顯示在主頁和EditInformation正確的ID。但是,當我在視圖中單擊列表時,它將顯示正確的ID,,但在EditInformation中沒有ID顯示。
我bundle.putInt("ID", HomePage.ID);
之後添加bundle.putInt("ID", View.ID);
,它適用於所有,但不適用於首頁作品! HomePage列表顯示其ID,但在EditInformation中顯示0 ID。
如何解決這個??? 我們如何區分列表是單擊全部還是視圖?謝謝
只是爲了確保我明白了這個問題:通過單擊HomePage中的列表項目,而不是通過單擊View中的列表項目,雖然您在偵聽器中使用相同的代碼,但ID已正確傳輸到同一目標(ActivityB) ? – 0X0nosugar
@ 0X0nosugar –
沒有像最小,完整等等的東西....例如它很難確定,但我對「**公共靜態** int ID」有不好的感覺。這樣,ID值以某種方式泄漏,而不是僅從其源(View *或* Homepage)傳輸。如果你想讓我更深入地研究一下,那麼我真的需要足夠的代碼來重現錯誤。 – 0X0nosugar