I have craeted a CustomAdapter class that extends BaseAdapter (so I cannot extend the class to Fragment).
In CustomAdapter
class I create my custom ListView
with items. Uppon button clicked I would like to go another Fragment.
CustomAdapter class is being initialized in MyLocationFragment.java
. In this Fragment I offer the user to select an Item from ListView, and when the user clicks the Button (which is next to the TextView / Item) I want to go to HomeScreenFragment and do something with the stored value from the TextView that the Button belonged to (same position).
MyLocationFragment (parts that matter in this case, otherwise too big):
if(adminMode) {
ArrayList<String> data = new ArrayList<>(Arrays.asList(locationsArray));
CustomAdapter adapter = new CustomAdapter(data, getActivity());
// Assign adapter to ListView
listView.setAdapter(adapter);
}
CustomAdapter.java (partially,where the Listeners comes in):
holder.localData.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
fMyLocation = new MyLocationFragment();
// Store selected values into Strings and pass them to setter method
String selectedLocation = (String) holder.items.getText().toString();
String [] locationsArrayValues = v.getResources().getStringArray(R.array.locations_array_value);
String selectedLocationUrl = locationsArrayValues[position];
fMyLocation.setInputLocation(selectedLocation);
fMyLocation.setInputLocationUrl(selectedLocationUrl);
FragmentActivity myContext;
// On Item Click, go to the HomeScreen
Fragment fragment = new HomeScreenFragment();
FragmentManager fManager = myContext.getSupportFragmentManager();
FragmentTransaction fTransaction = fManager.beginTransaction();
fTransaction.replace(R.id.fragment_holder, fragment);
fTransaction.commit();
}
});
The above code results into Cannot Resolve getFragmentManager();
Any idea how could I get to the HomeScreenFragment
from non-Fragment class ?
Any help will be appreciated.