Android 适配器中的共享首选项为空

Android 适配器中的共享首选项为空,android,android-fragments,android-asynctask,sharedpreferences,Android,Android Fragments,Android Asynctask,Sharedpreferences,这是当我点击switch rent时的视图,然后异步任务将运行,我得到一个结果数据循环视图未更新,它显示图像按钮和循环视图空指针异常这是我的代码 public void rent\u buy\u选择(字符串类型、字符串propertyID、字符串placeId、字符串buildingName、字符串卧室) { Property_listing1 listing1=新的Property_listing1(类型、propertyID、placeId、buildingName、卧室); listin

这是当我点击switch rent时的视图,然后异步任务将运行,我得到一个结果数据循环视图未更新,它显示图像按钮和循环视图空指针异常这是我的代码

public void rent\u buy\u选择(字符串类型、字符串propertyID、字符串placeId、字符串buildingName、字符串卧室)
{
Property_listing1 listing1=新的Property_listing1(类型、propertyID、placeId、buildingName、卧室);
listing1.execute();
}
公共类属性\u listing1扩展了异步任务{
字符串属性ID;
字符串placeId;
字符串属性类型;
字符串BuildingName;
串卧室;
字符串image1,SenderId;
JSONArray详细信息;
JSONParser ob=新的JSONParser();
杰索纳雷·贾雷;
属性列表1(字符串类型、字符串属性ID、字符串位置ID、字符串建筑名称、字符串卧室){
Log.e(“listFragment”,“:”+类型);
PropertyID=PropertyID;
placeId=placeId;
BuildingName=BuildingName;
卧室=卧室;
属性类型=类型;
/*if(getActivity().getIntent().hasExtra(“PropertyID”)){
PropertyID=getActivity().getIntent().getExtras().getString(“PropertyID”);
}
if(getActivity().getIntent().hasExtra(“PropertyID”)){
placeId=getActivity().getIntent().getExtras().getString(“placeId”);
}
属性类型=类型;//getActivity().getIntent().getExtras().getString(“属性类型”);
if(getActivity().getIntent().hasExtra(“PropertyID”)){
BuildingName=getActivity().getIntent().getExtras().getString(“BuildingName”);
}
if(getActivity().getIntent().hasExtra(“PropertyID”)){
卧室=getActivity().getIntent().getExtras().getString(“卧室”);
}
if(getActivity().getIntent().hasExtra(“PropertyID”)){
SenderId=getActivity().getIntent().getExtras().getString(“SenderId”);
}*/
}
列表数据=新的ArrayList();
@凌驾
受保护的布尔doInBackground(Void…params){
试一试{
//建筑参数
List params=new ArrayList();
添加参数(新的BasicNameValuePair(“更多列表”,“1”);
添加(新的BasicNameValuePair(“PropertyID”,PropertyID));
添加(新的BasicNameValuePair(“属性类型”,属性类型));
添加(新的BasicNameValuePair(“BuildingName”,BuildingName));
参数添加(新BasicNameValuePair(“卧室”,卧室));
添加(新的BasicNameValuePair(“placeId”,placeId));
试一试{
/*if(getActivity().getIntent().hasExtra(“共享”)){
添加参数(新的BasicNameValuePair(“共享”、“1”);
添加(新的BasicNameValuePair(“SenderId”,SenderId));
}*/
}
捕获(例外e)
{
e、 printStackTrace();
}
//获取JSON对象
//请注意,创建产品url接受POST方法
JSONObject json=ob.makeHttpRequest(“http://208.77.22.13/proprek_android/property_listing.php“,”职位“,参数);
Log.d(“参数”,“:”+参数);
//检查logcat是否有响应
d(“创建响应”,json.toString());
//检查成功标签
试一试{
String success=json.getString(“status”);
Log.d(“test123”,“:”+成功);
if(success.equals(“true”)){
jArray=json.getJSONArray(“结果”);
//从json中提取数据并作为类对象存储到ArrayList中

对于(int i=0;i这是当我单击switch rent时的视图,然后异步任务将运行,我得到一个结果数据循环视图未更新,它显示图像按钮和循环视图空指针异常这是我的代码

public void rent\u buy\u选择(字符串类型、字符串propertyID、字符串placeId、字符串buildingName、字符串卧室)
{
Property_listing1 listing1=新的Property_listing1(类型、propertyID、placeId、buildingName、卧室);
listing1.execute();
}
公共类属性\u listing1扩展了异步任务{
字符串属性ID;
字符串placeId;
字符串属性类型;
字符串BuildingName;
串卧室;
字符串image1,SenderId;
JSONArray详细信息;
JSONParser ob=新的JSONParser();
杰索纳雷·贾雷;
属性列表1(字符串类型、字符串属性ID、字符串位置ID、字符串建筑名称、字符串卧室){
Log.e(“listFragment”,“:”+类型);
PropertyID=PropertyID;
placeId=placeId;
BuildingName=BuildingName;
卧室=卧室;
属性类型=类型;
/*if(getActivity().getIntent().hasExtra(“PropertyID”)){
PropertyID=getActivity().getIntent().getExtras().getString(“PropertyID”);
}
if(getActivity().getIntent().hasExtra(“PropertyID”)){
placeId=getActivity().getIntent().getExtras().getString(“placeId”);
}
属性类型=类型;//getActivity().getIntent().getExtras().getString(“属性类型”);
if(getActivity().getIntent().hasExtra(“PropertyID”)){
BuildingName=getActivity().getIntent().getExtras().getString(“BuildingName”);
}
if(getActivity().getIntent().hasExtra(“PropertyID”)){
卧室=getActivity().getIntent().getExtras().getString(“卧室”);
}
if(getActivity().getIntent().hasExtra(“PropertyID”)){
SenderId=getActivity().getIntent().getExtras().getString(“SenderId”);
}*/
}
列表数据=新的ArrayList();
@凌驾
受保护的布尔doInBackground(Void…params){
试一试{
//建筑参数
List params=new ArrayList();
添加参数(新的BasicNameValuePair(“更多列表”,“1”);
参数添加(新Bas)
public void rent_buy_selection(String type,String propertyID,String placeId,String buildingName,String bedRooms)
{
    Property_listing1 listing1  = new Property_listing1(type,propertyID,placeId,buildingName,bedRooms);
    listing1.execute();

}


public class Property_listing1 extends AsyncTask<Void, Void, Boolean> {
    String PropertyID;
    String placeId;
    String property_type;
    String BuildingName;
    String BedRooms;
    String image1,SenderId;

    JSONArray detail;

    JSONParser ob = new JSONParser();
    JSONArray jArray;
    Property_listing1(String type,String propertyID,String PlaceId,String buildingName,String bedRooms) {
        Log.e("listFragment",":"+type);
        PropertyID   = propertyID;
        placeId      = PlaceId;
        BuildingName = buildingName;
        BedRooms     = bedRooms;
        property_type= type;

      /*  if(getActivity().getIntent().hasExtra("PropertyID")) {
            PropertyID = getActivity().getIntent().getExtras().getString("PropertyID");
        }
        if(getActivity().getIntent().hasExtra("PropertyID")) {
            placeId = getActivity().getIntent().getExtras().getString("placeId");
        }

        property_type     = type;//getActivity().getIntent().getExtras().getString("property_type");

        if(getActivity().getIntent().hasExtra("PropertyID")) {
            BuildingName = getActivity().getIntent().getExtras().getString("BuildingName");
        }
        if(getActivity().getIntent().hasExtra("PropertyID")) {
            BedRooms = getActivity().getIntent().getExtras().getString("BedRooms");
        }
        if(getActivity().getIntent().hasExtra("PropertyID")) {
            SenderId = getActivity().getIntent().getExtras().getString("SenderId");
        }*/

    }
    List<DataProperty> data=new ArrayList<>();


    @Override
    protected Boolean doInBackground(Void... params) {

        try {
            // Building Parameters
            List<NameValuePair> paramss = new ArrayList<NameValuePair>();


            paramss.add(new BasicNameValuePair("more_list", "1"));
            paramss.add(new BasicNameValuePair("PropertyID", PropertyID));
            paramss.add(new BasicNameValuePair("property_type", property_type));
            paramss.add(new BasicNameValuePair("BuildingName", BuildingName));
            paramss.add(new BasicNameValuePair("BedRooms", BedRooms));
            paramss.add(new BasicNameValuePair("placeId", placeId));

            try {

               /* if (getActivity().getIntent().hasExtra("shared")) {

                    paramss.add(new BasicNameValuePair("shared", "1"));
                    paramss.add(new BasicNameValuePair("SenderId", SenderId));

                }*/
            }
            catch (Exception e)
            {
                e.printStackTrace();
            }
            // getting JSON Object
            // Note that create product url accepts POST method
            JSONObject json = ob.makeHttpRequest("http://208.77.22.13/proprek_android/property_listing.php", "POST", paramss);
            Log.d("Parameters",":"+paramss);
            // check logcat for response
            Log.d("Create Response", json.toString());

            // check for success tag
            try {

                String success = json.getString("status");
                Log.d("test123",":"+success);
                if (success.equals("true")) {


                     jArray  = json.getJSONArray("result");

                    // Extract data from json and store into ArrayList as class objects
                    for(int i=0;i<jArray.length();i++){
                        JSONObject json_data     = jArray.getJSONObject(i);
                        DataProperty fishData    = new DataProperty();
                        fishData.Title           = json_data.getString("title");
                        fishData.Id              = json_data.getString("id");
                        fishData.agentId         = json_data.getString("agent_id");
                        fishData.prprtyId        = json_data.getString("property_id");
                        fishData.Price           = json_data.getString("price");
                        fishData.Area            = json_data.getString("area");
                        fishData.agent_name      = json_data.getString("first_name");
                        fishData.agent_pic       = json_data.getString("fb_img");
                        fishData.Bedrooms        = json_data.getString("bedrooms");
                        fishData.Bathrooms       = json_data.getString("bathrooms");
                        fishData.Image           = json_data.getString("agent_logo");
                        fishData.Phone           = json_data.getString("phone");
                        fishData.property_Img    = json_data.getString("image1");
                        fishData.agent_logo      = json_data.getString("agent_logo");
                        fishData.company_name    = json_data.getString("company_name");


                                fishData.shared = "0";
                                fishData.description = "0";
                               // data.add(fishData);

                        }
                        catch (Exception e)
                        {
                            e.printStackTrace();
                        }

                        Log.e("agent_name",":"+fishData.agent_name);
                        data.add(fishData);

                    }


                } else {
                    // failed to create product
                    // flag = true;
                    throw new InterruptedException("test");
                }
                // Simulate network access.
                //Thread.sleep(2000);

            } catch (InterruptedException e) {

                return false;
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return true;
    }

    @Override
    protected void onPostExecute(final Boolean success) {
        String Title="";
        try {


                mAdapter = new PropertyAdapter(getActivity(), data);
                mRVFishPrice.setAdapter(mAdapter);
                mAdapter.notifyDataSetChanged();
                mRVFishPrice.setLayoutManager(new LinearLayoutManager(getActivity()));

        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
    }
}
 public PropertyAdapter(Context context, List<DataProperty> data){

    Log.e("shared",":test");
    SharedPreferences sharedPreferences =   context.getSharedPreferences("reg_id",Context.MODE_PRIVATE);
    user_id = sharedPreferences.getString("id","");
    this.context=context;
   // inflater= (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    this.data=data;


    PropertyID        = ((Activity) context).getIntent().getExtras().getString("PropertyID");
    placeId           = ((Activity) context).getIntent().getExtras().getString("placeId");
    property_type     = ((Activity) context).getIntent().getExtras().getString("property_type");
    BuildingName      = ((Activity) context).getIntent().getExtras().getString("BuildingName");
    BedRooms          = ((Activity) context).getIntent().getExtras().getString("BedRooms");
    SenderId          = ((Activity) context).getIntent().getExtras().getString("SenderId");
}
public void rent_buy_selection(String type,String propertyID,String placeId,String buildingName,String bedRooms)
{
    Property_listing1 listing1  = new Property_listing1(type,propertyID,placeId,buildingName,bedRooms);
    listing1.execute();

}


public class Property_listing1 extends AsyncTask<Void, Void, Boolean> {
    String PropertyID;
    String placeId;
    String property_type;
    String BuildingName;
    String BedRooms;
    String image1,SenderId;

    JSONArray detail;

    JSONParser ob = new JSONParser();
    JSONArray jArray;
    Property_listing1(String type,String propertyID,String PlaceId,String buildingName,String bedRooms) {
        Log.e("listFragment",":"+type);
        PropertyID   = propertyID;
        placeId      = PlaceId;
        BuildingName = buildingName;
        BedRooms     = bedRooms;
        property_type= type;

      /*  if(getActivity().getIntent().hasExtra("PropertyID")) {
            PropertyID = getActivity().getIntent().getExtras().getString("PropertyID");
        }
        if(getActivity().getIntent().hasExtra("PropertyID")) {
            placeId = getActivity().getIntent().getExtras().getString("placeId");
        }

        property_type     = type;//getActivity().getIntent().getExtras().getString("property_type");

        if(getActivity().getIntent().hasExtra("PropertyID")) {
            BuildingName = getActivity().getIntent().getExtras().getString("BuildingName");
        }
        if(getActivity().getIntent().hasExtra("PropertyID")) {
            BedRooms = getActivity().getIntent().getExtras().getString("BedRooms");
        }
        if(getActivity().getIntent().hasExtra("PropertyID")) {
            SenderId = getActivity().getIntent().getExtras().getString("SenderId");
        }*/

    }
    List<DataProperty> data=new ArrayList<>();


    @Override
    protected Boolean doInBackground(Void... params) {

        try {
            // Building Parameters
            List<NameValuePair> paramss = new ArrayList<NameValuePair>();


            paramss.add(new BasicNameValuePair("more_list", "1"));
            paramss.add(new BasicNameValuePair("PropertyID", PropertyID));
            paramss.add(new BasicNameValuePair("property_type", property_type));
            paramss.add(new BasicNameValuePair("BuildingName", BuildingName));
            paramss.add(new BasicNameValuePair("BedRooms", BedRooms));
            paramss.add(new BasicNameValuePair("placeId", placeId));

            try {

               /* if (getActivity().getIntent().hasExtra("shared")) {

                    paramss.add(new BasicNameValuePair("shared", "1"));
                    paramss.add(new BasicNameValuePair("SenderId", SenderId));

                }*/
            }
            catch (Exception e)
            {
                e.printStackTrace();
            }
            // getting JSON Object
            // Note that create product url accepts POST method
            JSONObject json = ob.makeHttpRequest("http://208.77.22.13/proprek_android/property_listing.php", "POST", paramss);
            Log.d("Parameters",":"+paramss);
            // check logcat for response
            Log.d("Create Response", json.toString());

            // check for success tag
            try {

                String success = json.getString("status");
                Log.d("test123",":"+success);
                if (success.equals("true")) {


                     jArray  = json.getJSONArray("result");

                    // Extract data from json and store into ArrayList as class objects
                    for(int i=0;i<jArray.length();i++){
                        JSONObject json_data     = jArray.getJSONObject(i);
                        DataProperty fishData    = new DataProperty();
                        fishData.Title           = json_data.getString("title");
                        fishData.Id              = json_data.getString("id");
                        fishData.agentId         = json_data.getString("agent_id");
                        fishData.prprtyId        = json_data.getString("property_id");
                        fishData.Price           = json_data.getString("price");
                        fishData.Area            = json_data.getString("area");
                        fishData.agent_name      = json_data.getString("first_name");
                        fishData.agent_pic       = json_data.getString("fb_img");
                        fishData.Bedrooms        = json_data.getString("bedrooms");
                        fishData.Bathrooms       = json_data.getString("bathrooms");
                        fishData.Image           = json_data.getString("agent_logo");
                        fishData.Phone           = json_data.getString("phone");
                        fishData.property_Img    = json_data.getString("image1");
                        fishData.agent_logo      = json_data.getString("agent_logo");
                        fishData.company_name    = json_data.getString("company_name");


                                fishData.shared = "0";
                                fishData.description = "0";
                               // data.add(fishData);

                        }
                        catch (Exception e)
                        {
                            e.printStackTrace();
                        }

                        Log.e("agent_name",":"+fishData.agent_name);
                        data.add(fishData);

                    }


                } else {
                    // failed to create product
                    // flag = true;
                    throw new InterruptedException("test");
                }
                // Simulate network access.
                //Thread.sleep(2000);

            } catch (InterruptedException e) {

                return false;
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return true;
    }

    @Override
    protected void onPostExecute(final Boolean success) {
        String Title="";
        try {


                mAdapter = new PropertyAdapter(getActivity(), data);
                mRVFishPrice.setAdapter(mAdapter);
                mAdapter.notifyDataSetChanged();
                mRVFishPrice.setLayoutManager(new LinearLayoutManager(getActivity()));

        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
    }
}
 public PropertyAdapter(Context context, List<DataProperty> data){

    Log.e("shared",":test");
    SharedPreferences sharedPreferences =   context.getSharedPreferences("reg_id",Context.MODE_PRIVATE);
    user_id = sharedPreferences.getString("id","");
    this.context=context;
   // inflater= (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    this.data=data;


    PropertyID        = ((Activity) context).getIntent().getExtras().getString("PropertyID");
    placeId           = ((Activity) context).getIntent().getExtras().getString("placeId");
    property_type     = ((Activity) context).getIntent().getExtras().getString("property_type");
    BuildingName      = ((Activity) context).getIntent().getExtras().getString("BuildingName");
    BedRooms          = ((Activity) context).getIntent().getExtras().getString("BedRooms");
    SenderId          = ((Activity) context).getIntent().getExtras().getString("SenderId");
}