I'm trying to create a hashmap in a static function in a fragment. But I get an error creating the hashmap saying my function cannot be static. Can you tell me how can I do to keep my function static and keeping my hashmap inside?
My fragment :
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());
}
}
Error : this cannot be referenced from a static context on this line :
textviewresmap.put("textview" + i, new TextView(this.getContext()));