2013-08-28 97 views
1

我有一個自定義Dialog類的子類之外,實現ArrayAdapter有沒有辦法,我可以從另一個類或充氣視圖調用notifyDataSetChanged()更新ArrayAdapter類外

//This is a Subclass 
public class myClass extend ArrayAdapter{ 


    myDialog.showPopDialog(); 

} 


// another class 
public class myDialog implements onClickListener{ 

    public void showPopDialog(){ 
    Button mybutton = (Button) findViewbyId(R.id.mybutton); 
    mybutton.setOnClickListener(this) 
    } 

    @Override 
    public void onClick(View v) { 

     // I want to call notifyDataSetChanged() from here 
    } 
} 
+0

發表您的相關代碼 – Raghunandan

+0

我已經編輯我的代碼 – DevfaR

+0

@DevfaR看,這可能幫助ühttp://stackoverflow.com/questions/3669325/notifydatasetchanged-example – Developer

回答

0

因爲notifyDataSetChanged()是一個公共方法,所以你剛剛需持適配器u需要調用此方法的裁判。
要保存對象的引用,你想要,,,,這有很多方法,比如在你的對話框類,單例類,靜態類等中通過方法(constructer?)傳遞ref。
視圖是一樣的。

+0

我編輯我的代碼,你可以詳細說明你的答案,我似乎無法理解它 – DevfaR

1

希望這將幫助ü

In Your **Actitvity** Class : 

PassengerListView myAdapter; 


//From where u have to call u r notifyDataSetChanged 

myAdapter = new PassengerListView(MainActivity.this, allValues); 
listView.setAdapter(myAdapter); 
myAdapter.notifyDataSetChanged(); 
+0

如果我的數組適配器類是一個子類,我該怎麼稱呼它? – DevfaR

+0

我編輯了我的問題 – DevfaR

+0

所以問關於內部類? – Developer