I get the error Variable might be initialized I am using onChildClickListener, which makes me declare the variable as final. I need to put my variable inside try-Catch that is why I need to declare the variable outside.
I can´t figure how to declare the variable to make this error disappear. Any idea?
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_balance, container, false);
ExpandableListView expandableListView = (ExpandableListView)view.findViewById(R.id.fragBalance_expListView);
final ArrayList<Balance> arrayList;
try {
arrayList = (ArrayList<Balance>) new BalanceController(new BalanceFromApiJson()).getBalance(getContext(),"http://10.113.10.10:50591/api/Balance?reservationID=1452455");
} catch (ExecutionException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
BalanceAdapter balanceAdapter = new BalanceAdapter(getContext(),arrayList);
expandableListView.setAdapter(balanceAdapter);
expandableListView.setOnChildClickListener(new ExpandableListView.OnChildClickListener() {
@Override
public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) {
Toast.makeText(getContext(),arrayList.get(groupPosition).getTransactions().get(childPosition).toString() , Toast.LENGTH_SHORT).show();
return false;
}
});
return view;
}