I have a ListView
with custom adapter and it shows list of wifis around me. When one item is clicked, I show a dialog with details. The dialog is a custom class derived from DialogFragment
and is shown using this code after Wifi scan is complete:
private class WifiScanReceiver extends BroadcastReceiver {
public void onReceive(Context c, Intent intent) {
List<ScanResult> wifiScanList = wifi.getScanResults();
Log.i("WifiAnal", "rec");
lv.setAdapter(new WifiListAdapter(getApplicationContext(), R.layout.itemlistrow, wifiScanList));
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
ScanResult listItem = (ScanResult)lv.getItemAtPosition(position);
WifiDetailsDialogFragment d = new WifiDetailsDialogFragment();
// Supply num input as an argument.
Bundle args = new Bundle();
args.putString("ssid", listItem.SSID);
d.setArguments(args);
d.show(getSupportFragmentManager(), "fir");
// TODO: PUT ASYNC CALL HERE AND PROCESS FETCHED DATA.
// TODO: SHOW ASYNC RESULT ON OPEN DIALOG
}
});
mSwipeRefreshLayout.setRefreshing(false);
}
}
My WifiDetailsDialogFragment
class takes care of inflating its xml layout and displaying it correctly on top of app with Ok button.
Now imagine I show the dialog and now I want to run a background task (say fetch some more details from DB on external server) and after I am done, if dialog is still open put the result into its layout (likely manipulate values of some already existing and inflated TextViews). If it is closed by then, do nothing.
How can I access my layout widgets from a process running in background initiated by onItemClick? I tried d.getView()
but this returns null
. Is the correct way somehow through FragmentManager
? I do not want to draw new dialog, rather edit existing one's members.
Thanks!