statik işlev nesne ile hashmap oluşturun. Ancak, hashmap'ın işlevimin statik olamayacağını söyleyen bir hata alıyorum. işlevinin statik işlevimi nasıl koruyabileceğini ve hashmap'ımı içeride tutabileceğimi söyleyebilir misiniz?Bir parçasındaki bir <strong>statik</strong> işlevinde hashmap oluşturmaya çalışıyorum parçası
My parçası:
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());
}
}
Hata: bu hat üzerinde statik bir bağlam başvurulan olamaz: kendisi için Java
textviewresmap.put("textview" + i, new TextView(this.getContext()));
Teşekkür !! Tehlikeli mi, kötü bir yol mu, yoksa iyi bir yöntem mi? – Jey10
Etkinliğin hiç boş olmadığını hayal edemiyorum, bu yüzden bunun tehlikeli bir yöntem olduğunu düşünmüyorum. –