2016-03-26 9 views
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; 
} 

}

+1

この場合、あなたはそれを 'public static String loc' i beliにする必要がありますあなたは 'class custom_row .....'の行の後に置く必要があり、 'custom_row_adapter.loc'を実行する必要があります。 – 3kings

+0

Javaのグローバル変数スコープは言語に限りません行く(変数にはグローバル名前空間はない)。しかし、参照(例:MyClass.myStaticPublicField) – Durandal

+0

を完全に修飾することで、公開されている静的メンバーを参照できます。回答を投稿する? – Pythogen

答えて

2

同じようにそれを追加し、この

のようなフィールド
public class example { 

private String 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); 
     loc = url; 
    } 
    } 
} 
関連する問題