これは、アプリケーションの構造を設計するときに私が考えなかった問題です。Androidの拡張ビュークラスからアクティビティメソッドを呼び出す
基本的に私は3つのクラスを持っています。
ProfileActivity //The main activity for the application.
ProfileView //Which extends Linear Layout so that I can tinker with my own view. Note that this is just part of the whole activity and not the main layout
ProfileData //This is just a class for storing data.
アクティビティには、それぞれが1つのprofileDataを含む複数のProfileViewが含まれています。
私が立ち往生している場所。私のプロフィールのViewには、アクティビティのPopulateメソッドを呼び出す必要があるon clickメソッドが割り当てられています。残念なことに `` ``
//I'm inside the activity
public void populateProfileDataForm(ProfileData pd)
{
//edit some text fields and other widgets from here
}
profileViewクラスからアクティビティメソッドを呼び出す方法はありますか?
もしそうでなければ、エラーは私の設計であり、誰もデータ、ビュー、およびアクティビティをバインドするためのより良いソリューションに向いていますか?
私はコンテキストを理解するとは思えません。これについて簡単に質問します。 Profileviewはlinearlayoutを拡張します。コンテキストはsuper(context、attrs)として渡されます。ですから、私はprofileView(コードではなく、XMLで)を作成するときに、どのように私はそれに正しいコンテキストを渡すのですか? IE getBaseContext()、getApplicationContext()、this.something()? – OVERTONE
http://www.mail-archive.com/[email protected]/msg154153.html – OVERTONE
@OVERTONE申し訳ありません。パスは、インスタンスはうまくいきます。 profileActivityでprofileViewを作成するので、 'this'または' ProfileActivity.this'を渡すだけです。 – dreamtale