1

I have a parent activity and two fragments are defined there. In my parent activity, I have defined a spinner.In spinner, data is coming through JSON parsing. The spinner position is on the toolbar.So that it will be shown on both of my fragments. In my fragment activity, I have to choose from that spinner and on item select, I will get the id and send that id to async task in fragment activity and get the JSON data and show the data in the fragment. The problem I am facing is that on Item select from spinner nothing is happening. But when I change the orientation data is showing in the fragment. How do I connect my spinner which is defined in my parent activity with the async task doing background method in my fragment activity? Or how can I refresh/recreate my fragment view with new data ?

Spinner defined in parent activity

@Override
protected void onPostExecute(Void args) {
    // Locate the spinner in activity_main.xml
    final Spinner mySpinner = (Spinner) findViewById(R.id.spinner_nav);

    // Spinner adapter
    mySpinner
            .setAdapter(new ArrayAdapter<String>(ParentScreen.this,
                    android.R.layout.simple_spinner_dropdown_item,
                    cLists));

    // Spinner on item clicks listener
mySpinner
            .setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

                @SuppressLint("SetTextI18n")
                @Override
                public void onItemSelected(AdapterView<?> arg0,
                                           View arg1, int position, long arg3) {
                    // TODO Auto-generated method stub

                    String item = allC.get(position).getId();
                    String name = allC.get(position).getName();
                    Toast.makeText(getApplication(), "Selected: " + item + name, Toast.LENGTH_LONG).show();
G.I Joe
  • 87
  • 2
  • 11

0 Answers0