1
ルアではglobal variablename
を実行して、グローバルで をjavaで簡単に実行できますか?ここでJavaファイル全体で変数グローバルを作成するにはどうすればいいですか
が私のコードですが、私はpublic View getView(int position, View convertView, ViewGroup parent){
がそれを使用できるようにloc
変数はグローバルになりたい:
class custom_row_adapter extends ArrayAdapter<Integer> { custom_row_adapter(Context context, int picId, String url) { super(context, R.layout.activity_custom_row_adapter, picId); String loc = url; } @Override public View getView(int position, View convertView, ViewGroup parent){ LayoutInflater picInflater = LayoutInflater.from(getContext()); View customView = picInflater.inflate(R.layout.activity_custom_row_adapter, parent, false); String singlePic = getItem(loc + String.valueOf(position) + ".jpg"); **//this is where loc is viewed** ImageView theImage = (ImageView) customView.findViewById(R.id.singleImg); Glide.with(this).load(singlePic).into(theImage); return customView; }
}
この場合、あなたはそれを 'public static String loc' i beliにする必要がありますあなたは 'class custom_row .....'の行の後に置く必要があり、 'custom_row_adapter.loc'を実行する必要があります。 – 3kings
Javaのグローバル変数スコープは言語に限りません行く(変数にはグローバル名前空間はない)。しかし、参照(例:MyClass.myStaticPublicField) – Durandal
を完全に修飾することで、公開されている静的メンバーを参照できます。回答を投稿する? – Pythogen