フラグメント内のスタティック関数でハッシュマップを作成しようとしています。 しかし、私の関数が静的ではないというハッシュマップの作成中にエラーが発生します。どうすればの機能を静的に保つことができますかと私のハッシュマップを内部に保つことができますか?フラグメント内の静的関数内のオブジェクトでハッシュマップを作成します
マイ断片:
public class AddMatriceResult extends Fragment {
private static int i = 0, j = 0, l = 0;
private static int o = MatriceActivity.n * MatriceActivity.m;
private static HashMap<String, LinearLayout> layoutresmap = new HashMap<String, LinearLayout>();
private static HashMap<String, TextView> textviewresmap = new HashMap<String, TextView>();
private static List<LinearLayout> layoutreslist;
private static List<TextView> textviewreslist;
private static TextView noAddMatriceResult;
private static LinearLayout layoutResultCalc;
public AddMatriceResult() {
// Required empty public constructor
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.add_matrice_result, container, false);
layoutResultCalc = (LinearLayout) v.findViewById(R.id.LayoutMatriceRes);
noAddMatriceResult = (TextView) v.findViewById(R.id.noAddMatriceResult);
return v;
}
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
}
public static void Result(){
if(AddMatriceCalc.flag == 1)
{
noAddMatriceResult.setVisibility(View.GONE);
layoutResultCalc.setVisibility(View.VISIBLE);
for(i=0;i<MatriceActivity.m;i++) {
layoutresmap.put("layout" + i, new LinearLayout(this.getContext()));
}
layoutreslist = new ArrayList<LinearLayout>(layoutresmap.values());
for(i=0;i<o;i++) {
textviewresmap.put("textview" + i, new TextView(this.getContext()));
}
textviewreslist = new ArrayList<TextView>(textviewresmap.values());
}
}
エラー:これは、この行に静的コンテクスト から参照できません、それ自体にJavaで
textviewresmap.put("textview" + i, new TextView(this.getContext()));
感謝を!それが危険なのか、悪いコード方法なのか、それとも良い方法なのか教えてください。 – Jey10
私はアクティビティがnullであるとは想像もできませんので、これは危険な方法ではないと思います。 –