Gagouche
Gagouche

Reputation: 29

ListFragment and Custom Adapter Issue

Two issue with List Fragment: 1. I have a class that extends ListFragments.In the onCreated, I am setting my custom Adapter. The issue is that when the user logs in, the adadpter is null and would not have a value until the user searches for an owner. As a result, it throws an exception when it tries to set up the listadapter and it finds the ArrayAdapter object to be null. I have a custome layout that has a listview and a textview, but I still gets the error. See sample code below. I bold the line of code where the issue happens. Also, I bold few other section where I think it may be important to notice.

I implemented Parcelable in the class "Owner" so that I can pass the object as a ParcelableArray. Even though the object is not null, retrieving it in the OwnerDetail class shows null as if I did not pass it it. I've seen several example, but I am not able to get it right. What am I doing wrong here? Note: If I were to call the AsyncTask in the OwnerDetail class and set the ListAdapter, it will work fine. The issue with that is that it will display a list of owners as soon as the user is logged in which is not the expected behavior. The behavior that I want is to login first, search for an owner, display the owner, double click on an owner, and finally display a list of cars that the owner owns. I am doing this project, so I can learn how to use ListFraments.

// Here is the entire code

package com.mb.carlovers;

import android.os.Parcel;
import android.os.Parcelable;

public class Car implements Parcelable {
    private String _make;
    private String _model;
    private String _year;

    public Car()
    {
      this._make = "";
      this._model = "";
      this._year = "";
    }

    public Car(String make)
    {
      this._make = make;
    }
    public Car(String make, String year)
    {
      this._make = make;
      this._year = year;
    }

    public Car(String make, String model, String year)
    {
      this._make = make;
      this._model  = model;
      this._year = year;
    }

    //Getters
    public String getMake()
    {
        return _make;
    }
    public String getModel()
    {
        return _model;
    }
    public String getYear()
    {
        return _year;
    }

    //Setters
    public void setMake(String make)
    {
         _make = make;
    }
    public void setModel(String model)
    {
        _model = model;
    }
    public void setYear(String year)
    {
        _year = year;
    }

    @Override
    public int describeContents() {
        // TODO Auto-generated method stub
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        // TODO Auto-generated method stub

    }
}



package com.mb.carlovers;

import android.os.Bundle;
import android.support.v4.app.ListFragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;

public class CarDetail extends ListFragment {

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        return inflater.inflate(R.layout.customize_layout,container,false);
    }

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        String[] myCars = {};
        super.onActivityCreated(savedInstanceState);
        ArrayAdapter<String> carAdapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_activated_1, myCars);
        setListAdapter(carAdapter);
    }

}


package com.mb.carlovers;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

public class Login extends Activity implements OnClickListener{
 private Button btnLogin;
 private EditText etUsername, etPassword;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.login);
        initializeVariables();
    }

    public void initializeVariables()
    {
      btnLogin = (Button) this.findViewById(R.id.bLogin);
      etUsername = (EditText)this.findViewById(R.id.etUserName);
      etPassword = (EditText)this.findViewById(R.id.etPassword);
      btnLogin.setOnClickListener(this);
    }
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.login, menu);
        return true;
    }

    @Override
    public void onClick(View v) {
        Log.i("Tag", "In Onclick Litener");
        String uName = etUsername.getText().toString();
        String pWord = etPassword.getText().toString();
        if(uName.equals("owner") && pWord.equals("1234"))
        {
            Log.i("Tag", "username =" + uName + "Password =" + pWord);
            Intent intent = new Intent(this, People.class);
            startActivity(intent);
        }
    }

}


package com.mb.carlovers;
import android.os.Parcel;
import android.os.Parcelable;

public class Owner implements Parcelable {

    private String _firstName;
    private String _lastName;
    private String _carId;
    private Car _car;

    public Owner()
    {
      this._firstName = "";
      this._lastName = "";
      this._carId = "";
    }

    public Owner(String lName)
    {
      this._lastName = lName;
    }
    public Owner(String lName, String cId)
    {
      this._lastName = lName;
      this._carId = cId;
    }

    public Owner(String lName, String fName, String cId)
    {
      this._lastName = lName;
      this._firstName  = fName;
      this._carId = cId;
    }

    public Owner(String lName, String fName, String cId, Car car)
    {
         this._lastName = lName;
         this._firstName  = fName;
         this._carId = cId;
         this._car = car;
    }

    //Getters
    public String getFirstName()
    {
        return _firstName;
    }
    public String getLastName()
    {
        return _lastName;
    }
    public String getCarId()
    {
        return _carId;
    }

    public Car getCar()
    {
        return _car;
    }
    //Setters
    public void setFirstName(String fName)
    {
         _firstName = fName;
    }
    public void setLastName(String lName)
    {
        _lastName = lName;
    }
    public void setCarId(String cId)
    {
        _carId = cId;
    }

    public void setCar(Car car)
    {
        _car = car;
    }

    @Override
    public int describeContents() {
        // TODO Auto-generated method stub
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
          dest.writeString(_firstName);
          dest.writeString(_lastName);
          dest.writeString(_carId);
          dest.writeParcelable(_car, flags);
    }

     public Owner(Parcel source){
         _firstName = source.readString();
         _lastName = source.readString();
         _carId = source.readString();
         _car = source.readParcelable(Car.class.getClassLoader());
   }

    public class MyCreator implements Parcelable.Creator<Owner> {
          public Owner createFromParcel(Parcel source) {
                return new Owner(source);
          }
          public Owner[] newArray(int size) {
                return new Owner[size];
          }
    }

}


package com.mb.carlovers;
import com.mb.carlovers.adapter.OwnerAdapter;
import android.os.Bundle;
import android.support.v4.app.ListFragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

public class OwnerDetail extends ListFragment {

    OwnerAdapter ownerAdapter = null;
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        return inflater.inflate(R.layout.customize_layout,container, false);
    }


    @Override
    public void onSaveInstanceState(Bundle outState) {
        // TODO Auto-generated method stub
        super.onSaveInstanceState(outState);
    }


    @Override
    public void onCreate(Bundle savedInstanceState) {
        Owner[] myOwners = null;
        super.onCreate(savedInstanceState);
        Bundle values = getActivity().getIntent().getExtras();
        if(values != null)
        {
           myOwners = (Owner[]) values.getParcelableArray("test");
        } 
        super.onActivityCreated(savedInstanceState);
        ownerAdapter = new OwnerAdapter(getActivity(), R.layout.owner_detail , myOwners);
        ownerAdapter.notifyDataSetChanged();

    }


package com.mb.carlovers;

import java.util.List;
import com.mb.carlovers.asynctask.OnwerAsyncTask;

import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.TextView;

public class People extends FragmentActivity implements OnClickListener, OnItemSelectedListener {
  private Button search;
  private EditText etSearchBy, etSearchByID;
  private Spinner spOption;
  private String selectedOption = null;
  private TextView tvErrorMessage;
    @Override
    protected void onCreate(Bundle arg0) {
        super.onCreate(arg0);
        setContentView(R.layout.people);
        InitializeVariables();
    }

    private void InitializeVariables()
    {
        etSearchBy = (EditText) this.findViewById(R.id.etByLastName);
        etSearchByID = (EditText) this.findViewById(R.id.etCarID);
        spOption = (Spinner) this.findViewById(R.id.spOption);
        search = (Button) this.findViewById(R.id.bSearch);
        search.setOnClickListener(this);
        tvErrorMessage = (TextView) this.findViewById(R.id.tvErrorMessage);

        ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this,R.array.spOptions, android.R.layout.simple_spinner_dropdown_item);
        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        spOption.setAdapter(adapter);
        spOption.setOnItemSelectedListener(this);

    }
    @Override
    protected void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
    }

     @Override
        protected void onPause() {
            super.onPause();
        }

    @Override
    public void onClick(View v) {
        String searchByName = etSearchBy.getText().toString();
        String searchById = etSearchByID.getText().toString();
       if(selectedOption == null || selectedOption == "All")
       {
           if(searchByName.matches("") || searchById.matches(""))
           {
               tvErrorMessage.setText("You must select a last name and car id");
           } else
           {

           }

       } else if(selectedOption == "Name")
       {
           if(!searchByName.matches(""))
           {
                      OnwerAsyncTask asynTask = new OnwerAsyncTask();
                     List<Owner> lt = null;
                      try {
                            lt = asynTask.execute("").get();
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                        Owner myOwners[] = lt.toArray(new Owner[lt.size()]);
                        Bundle data = new Bundle();
                        data.putParcelableArray("test", myOwners);

           } else
           {
               tvErrorMessage.setText("You must enter the last name of the owner.");
           }

       } else if (selectedOption == "ID") 
       {

           if(!searchById.matches(""))
           {
              String st = null;
              String d = st;
           } else
           {
               tvErrorMessage.setText("You must enter the car id that you'd like to search.");
           }
       }
    }

    @Override
    public void onItemSelected(AdapterView<?> parent, View view, int pos,long id) {
        switch(pos)
        {
        case 0:
            selectedOption = "All";
            break;
        case 1:
            selectedOption ="Name";
            break;
        case 2:
            selectedOption ="ID";
            break;
            default:
                selectedOption = null;
                break;
        }
    }

    @Override
    public void onNothingSelected(AdapterView<?> arg0) {
        selectedOption ="ALL";
    }


}


package com.mb.carlovers.adapter;

import com.mb.carlovers.Car;
import com.mb.carlovers.R;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class CarAdapter extends ArrayAdapter<Car> {

    private Context context;
    private int layoutResourceId;
    private Car data[] = null;

    public CarAdapter(Context context, int resource, Car[] data) {
        super(context, resource, data);
        this.context = context;
        this.layoutResourceId = resource;
        this.data = data;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View row = convertView;
        CarHolder holder = null;
        if(row == null)
        {
            LayoutInflater inflater = ((Activity)context).getLayoutInflater();
            row = inflater.inflate(layoutResourceId, parent, false);
            holder = new CarHolder();
            holder.tvMake = (TextView) row.findViewById(R.id.tvMake);
            holder.tvModel = (TextView) row.findViewById(R.id.tvModel);
            holder.tvYear = (TextView) row.findViewById(R.id.tvYear);
            row.setTag(holder);
        } else
        {
            holder = (CarHolder) row.getTag();
        }

        Car item = data[position];
        holder.tvMake.setText(item.getMake().toString());
        holder.tvModel.setText(item.getModel().toString());
        holder.tvYear.setText(item.getYear().toString());

        return row;
    }

    public static class CarHolder
    {
        TextView tvMake;
        TextView tvModel;
        TextView tvYear;
    }
}


package com.mb.carlovers.adapter;

import com.mb.carlovers.Owner;
import com.mb.carlovers.R;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class OwnerAdapter extends ArrayAdapter<Owner> {

    private Context context;
    private int layoutResourceId;
    private Owner data[] = null;

    public OwnerAdapter(Context context, int textViewResourceId,Owner[] data) {
        super(context, textViewResourceId, data);
        this.context = context;
        this.layoutResourceId = textViewResourceId;
        this.data = data;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View row = convertView;
        OwnerHolder holder = null;

        if(row == null)
        {
            LayoutInflater inflater = ((Activity)context).getLayoutInflater();
            row = inflater.inflate(layoutResourceId, parent, false);
            holder = new OwnerHolder();
            holder.tvFName = (TextView) row.findViewById(R.id.tvFirstName);
            holder.tvLName = (TextView) row.findViewById(R.id.tvLastName);
            holder.tvCId = (TextView) row.findViewById(R.id.tvCarID);
            row.setTag(holder);
        } else
        {
            holder = (OwnerHolder) row.getTag();
        }

        Owner item = data[position];
        holder.tvFName.setText(item.getFirstName());
        holder.tvLName.setText("Example");
        holder.tvCId.setText("1");
        return row;
    }

    static class OwnerHolder
    {
      TextView tvFName;
      TextView tvLName;
      TextView tvCId;
    }
}


package com.mb.carlovers.asynctask;

import java.util.ArrayList;
import java.util.List;

import com.mb.carlovers.Car;
import android.os.AsyncTask;

public class CarAsyncTask extends AsyncTask<String, Void, List<Car>> {

    private List<Car> item = null;
    @Override
    protected List<Car> doInBackground(String... params) {

        item = new ArrayList<Car>();
        item.add(new Car("Chevy","Caprice","2002"));
        item.add(new Car("Chevy","Malibu","2014"));
        item.add(new Car("Dodge","Stratus","2002"));
        item.add(new Car("Saturn","L300","2004"));

        return item;
    }

    @Override
    protected void onPostExecute(List<Car> result) {
        super.onPostExecute(result);
    }

}


package com.mb.carlovers.asynctask;

import java.util.ArrayList;
import java.util.List;

import com.mb.carlovers.Owner;
import android.os.AsyncTask;

public class OnwerAsyncTask extends AsyncTask<String, Void, List<Owner>> {

    private List<Owner> items = null;
    @Override
    protected List<Owner> doInBackground(String... params) {

        try
        {
            items = new ArrayList<Owner>();
            Owner own = new Owner();
            own.setFirstName("John");
            own.setLastName("Smith");
            own.setCarId("1");
            items.add(own);

            Owner own1 = new Owner();
            own1.setFirstName("Samantha");
            own1.setLastName("Right");
            own1.setCarId("2");
            items.add(own1);

            Owner own2 = new Owner();
            own2.setFirstName("Regie");
            own2.setLastName("Miller");
            own2.setCarId("3");
            items.add(own2);

            Owner own3 = new Owner();
            own3.setFirstName("Mark");
            own3.setLastName("Adam");
            own3.setCarId("4");
            items.add(own3);

        } catch(Exception ex)
        {
            ex.toString();
        }
        return items;
    }

    @Override
    protected void onPostExecute(List<Owner> result) {
        // TODO Auto-generated method stub
        super.onPostExecute(result);
    }

}


// car_detail.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Car Detail Page" />

</LinearLayout>


// car_row.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal" >

    <TextView
        android:id="@+id/tvMake"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="" />

    <TextView
        android:id="@+id/tvModel"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="" />

    <TextView
        android:id="@+id/tvYear"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="" />

</LinearLayout>


//customize_layout.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <ListView
        android:id="@id/android:list"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >
    </ListView>

     <TextView
        android:id="@id/android:empty"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="No record to be displayed." 
        />
</LinearLayout>


//Login.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/LinearLayout1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".Login" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="User Name"
        android:textSize="30sp"
        android:layout_marginTop="10dp"
        android:layout_gravity="center"
         />

    <EditText
        android:id="@+id/etUserName"
        android:layout_width="300dp"
        android:layout_height="wrap_content"
        android:ems="10"
        android:layout_gravity="center"
        android:layout_marginTop="10dp"
         >

        <requestFocus />
    </EditText>

    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Password" 
        android:textSize="30sp"
        android:layout_marginTop="10dp"
        android:layout_gravity="center"
        />

    <EditText
        android:id="@+id/etPassword"
        android:layout_width="300dp"
        android:layout_height="wrap_content"
        android:ems="10"
        android:layout_gravity="center"
        android:layout_marginTop="10dp"
        android:inputType="textPassword" />

    <Button
        android:id="@+id/bLogin"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:layout_gravity="center"
        android:text="Login" />

</LinearLayout>


//owner_detail.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal" >

 <TextView
        android:id="@+id/tvFirstName"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="10dp"
        android:text="TextView" />

    <TextView
        android:id="@+id/tvLastName"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="10dp"
        android:text="TextView" />

    <TextView
        android:id="@+id/tvCarID"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="10dp"
        android:text="TextView" />

</LinearLayout>


// People.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal" >

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:layout_weight="1"
         >

        <TextView
            android:id="@+id/textView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Search by last name" 
            android:textSize="30sp"
            android:layout_marginLeft="10dp"
            android:layout_marginTop="15dp"
            />

        <EditText
            android:id="@+id/etByLastName"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:ems="10"
            android:layout_marginTop="10dp"
            android:layout_marginLeft="10dp"
            android:inputType="textPersonName" >

            <requestFocus />
        </EditText>

        <TextView
            android:id="@+id/textView2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Search by car id" 
            android:textSize="30sp"
            android:layout_marginLeft="10dp"
            android:layout_marginTop="10sp"
            />

        <EditText
            android:id="@+id/etCarID"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:ems="10" 
            android:layout_marginLeft="10dp"
            android:layout_marginTop="10sp"
            />

        <Spinner
            android:id="@+id/spOption"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" 
            android:entries="@array/spOptions"
            />

        <TextView
            android:id="@+id/tvErrorMessage"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textColor="#FF0000"
            android:layout_marginTop="10dp"
            android:text="" />

        <Button
            android:id="@+id/bSearch"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            android:text="Button" />

    </LinearLayout>

   <LinearLayout
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:orientation="vertical" 
        android:layout_weight="2"
        >

        <fragment
            android:id="@+id/fOwnerDetail"
            android:name="com.mb.carlovers.OwnerDetail"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
             />

        <fragment
            android:id="@+id/fragment1"
            android:name="com.mb.carlovers.CarDetail"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="2"
             />

    </LinearLayout>

</LinearLayout>





    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        setListAdapter(ownerAdapter);
    }
}

Upvotes: 0

Views: 472

Answers (1)

user
user

Reputation: 87064

Your code has a lot of problems:

1 Never call lifecycle methods on your own like you do in the OwnerDetail class with super.onActivityCreated(savedInstanceState);

2 Bundle values = getActivity().getIntent().getExtras(); ... values.getParcelableArray("test"); will normally fail because this piece of code will get the activity reference, get the Intent that started the activity and then try to find data passed in under the test key in that Intent. You don't pass such data to the People activity so there will be nothing to be found. You'd normally want to pass a Bundle containing the data at the moment of the creation of the fragment.

3 If you use the fragment in the xml layout you'll not be able to use a Bundle to pass data, instead you either add the fragment manually with transactions and then use a Bundle or you create a setter method in the fragment class and use that. So instead of Bundle data = new Bundle(); data.putParcelableArray("test", myOwners);, which does nothing, get a reference to your fragment and pass the myOwners array through a method.

4 Your AsyncTask will be pretty useless if you use them with .get() because the get() method will wait the AsyncTask to finish, blocking the UI tread as well. Instead you should just start the AsyncTask and then in the onPostExecute() pass the data around.

Here is an example with a simple method which will not change most of your code(which will happen if you manually add the fragments):

// where you start the owner asynctask
if(!searchByName.matches("")) {
    OnwerAsyncTask asynTask = new OnwerAsyncTask(People.this);
    asynTask.execute("");
}
//...

Then change the OnwerAsyncTask like this:

public class OnwerAsyncTask extends AsyncTask<String, Void, List<Owner>> {

  private List<Owner> items = null;
  private FragmentActivity mActivity;  

  public OnwerAsyncTask(FragmentActivity activity) {
      mActivity = activity;
  }

  // doInBackground()...

  @Override
  protected void onPostExecute(List<Owner> result) {
       //I'm assuming that items is the data you want to return, so 
       // find the OwnerDetail fragment and directly assign the data
       OwnerDetail fragment = (OwnerDetail)mActivity.getSupportFragmentManager().findFragmentById(R.id.fOwnerDetail);
       fragment.setData(); // to setData you'll pass the data you have in the AsyncTask
                           // the items list? or you transform that into an array?         
  }

and in the OwnerDetail fragment:

public class OwnerDetail extends ListFragment {

    OwnerAdapter ownerAdapter = null;

    public void setData() {
       // update the adapter, create a new one etc.
    }

Upvotes: 1

Related Questions