この'extendsImageView'クラスをコードのどこかに初期化して、レイアウトを膨らませると思いますか?すなわち:
CustomImageView myImageView = new CustomImageView();
[...]
yourRootView.addView(myImageView);
その場合、初期化時にintを渡すことができます。
CustomImageView myImageView = new CustomImageView(yourInt);
CustomImageView.classがcunstructorでそれをキャッチします。
public CustomImageView(int yourInt) {
Log.i("Hello", "This is the int your were looking for" + yourInt);
もう1つの方法は、CustomImageView.classでセッター/ゲッターを設定することです。
private yourInt;
public void setInt(int yourInt) {
this.yourInt = yourInt;
}
アクティビティから、次のことを実行できます。
CustomImageView myImageView = new CustomImageView();
myImageView.setInt(yourInt);
申し訳ありませんが、これで質問に答えられない場合は、情報がほとんど提供されていないため、推測する必要がありました(*編集、[コメント]ボタンが見つかりませんでした...コメント)
編集
あなたのアクティビティクラス:
class MyActivtiy extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_someactivity);
MyImageView myImageView = new MyImageView(2); // 2 is our Example Integer
//**Alternative** - Needs setInger(int someInt) in ImageView class (see below)
myImageView.setInteger(4);
}
}
ImageViewクラス
class MyImageView extends ImageView {
Int anInteger;
public MyImageView(int anInteger) {
Log.i("Hello", "The integer is: " + anInteger);
// Above line will show in Logcat as "The integer is: 2
this.anInteger = anInteger;
// Above line will set anInteger so you can use it in other methods
}
public void printIntToLogCat() {
Log.i("Hello", "You can use the integer here, it is: " + anInteger);
// Above line in logcat: "You can [...], it is: 2"
}
//**Alternative**
public void setInteger(int someInt) {
this.anInteger = someInt; // With above example this will set anInteger to 4
printIntToLogCat();
// Above Line will print: "You can[...], it is: 4"
}
}