如何在childFragment

时间:2016-01-04 13:41:57

标签: android listview pull-to-refresh

我正在使用PullToRefresh来刷新Child Fragment(嵌套片段)中的ListView但是当我将其拉下来时,会出现一些加载动画,但它不会进行任何更改名单。它仅显示以前加载的数据。

这是我的代码: -

    public class OzoneFeedFragment extends Fragment implements MiFeelingBase, OnClickListener {

    private ArrayList<OzoneFeedData>arrOzoneFeed;
    private ArrayList<OzoneFeedData>arrList=new ArrayList<OzoneFeedData>();
    private FragmentTabHost mTabHost;
    private OzoneAdapter adpter;

    private LinearLayout llUserPost;
    private TextView tvUserPost;
    private String strUserID;
    private String strServerKey;
    //private ListView lv;
    private int page=0;
    private boolean loadingMore=false;
    View loadMoreView;
    int UrlIndex=0;
     // private DatabaseHandler databaseHelper;
        //private SQLiteDatabase mydatabase = null;
        private PullToRefreshListView llList;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        // TODO Auto-generated method stub
         View rootView = inflater.inflate(R.layout.ozone_feed, container, false);
         llUserPost=(LinearLayout)rootView.findViewById(R.id.llUserPost);
         llUserPost.setVisibility(View.VISIBLE);
         tvUserPost=(TextView)rootView.findViewById(R.id.tvWhatOnYourMind);
         tvUserPost.setOnClickListener(this);
         llList=(PullToRefreshListView)rootView.findViewById(R.id.list);
       loadMoreView = ((LayoutInflater)getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.loadmore, null, false);

       llList.addFooterView(loadMoreView);

         Reload();

      //   llList = (PullToRefreshListView) getView();
         llList.setOnRefreshListener(new OnRefreshListener() {

            @Override
            public void onRefresh() {

                llList.postDelayed(new Runnable() {

                    @Override
                    public void run() {
                        llList.onRefreshComplete();

                           APIAccess.fetchData(OzoneFeedFragment.this, getActivity(), getActivity());
                           UrlIndex=0;
                            adpter.notifyDataSetChanged();
                    }
                }, 2000);
            }
        });

        llList.setOnScrollListener(new OnScrollListener() {

            @Override
            public void onScrollStateChanged(AbsListView view, int scrollState) {
                // TODO Auto-generated method stub

            }

            @Override
            public void onScroll(AbsListView view, int firstVisibleItem,
                    int visibleItemCount, int totalItemCount) {
                // TODO Auto-generated method stub
                if(visibleItemCount>0)
                {
                int lastInScreen = firstVisibleItem + visibleItemCount; 
                if((lastInScreen == totalItemCount) && !(loadingMore))
                {
                     APIAccess.fetchPagingData(OzoneFeedFragment.this, getActivity(), getActivity(),true);
                }
                }
            }
        });

      //   llList = (PullToRefreshListView) getView();


          return rootView;
}

    private void Reload() {
        // TODO Auto-generated method stub

        //APIAccess.fetchData(OzoneFeedFragment.this, getActivity(), getActivity(),true);
    }

    @Override
    public void onResume(){
        super.onResume();

         //UrlIndex=0;
         //APIAccess.fetchData(OzoneFeedFragment.this, getActivity(), getActivity());
         //notifyAll();
         //adpter.notifyDataSetChanged();
    }

    @Override
    public void onDestroy() {
        // TODO Auto-generated method stub
        super.onDestroy();
        adpter=null;
        page=0;
        loadingMore=false;
        arrList.clear();

    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
          AppContoller.getInstance().pref=getActivity().getSharedPreferences(AppContoller.getInstance().PREF_NAME, 0);

          try{

            strUserID=AppContoller.getInstance().pref.getString(AppContoller.getInstance().USER_ID, "0");
            strServerKey=AppContoller.getInstance().pref.getString(AppContoller.getInstance().SERVER_KEY, "0");
          }catch(Exception e){

          }

            System.out.println("login detail  " + strUserID + "  " + strServerKey);

         APIAccess.fetchData(OzoneFeedFragment.this, getActivity(), getActivity());
    }

    @Override
    public String httpPost() {
        // TODO Auto-generated method stub

        String response="";
        if(UrlIndex==0){
        loadingMore=true;
        page++;
        response=OpenConnection.callUrl(StaticData.SABAKUCH_OPOST+"id/"+strUserID+"/key/"+strServerKey+"/page/"+page);

        }
        else if(UrlIndex==1){

            loadingMore=true;
            page++;

            response=OpenConnection.callUrl(StaticData.SABAKUCH_OPOST+"id/"+strUserID+"/key/"+strServerKey+"/page/"+page);
            }
        return response;

    }

    @Override
    public String httpAfterPost(String str) {
        // TODO Auto-generated method stub

        if(str!=null)
        {
            if(UrlIndex==0){

        arrOzoneFeed=SabaKuchParse.parseOzoneFeed(str);
        if(arrOzoneFeed.size()>0)
        {
            loadingMore=false;
            arrList.addAll(arrOzoneFeed);
            if(adpter==null)
            { 
            adpter=new OzoneAdapter(getActivity(), arrList);
            llList.setAdapter(adpter);
            adpter.notifyDataSetChanged();
            }else
            {
                adpter.notifyDataSetChanged();
            }

            adpter.notifyDataSetChanged();
        }
        adpter.notifyDataSetChanged();

        }
            else if(UrlIndex==1){
                arrOzoneFeed=SabaKuchParse.parseOzoneFeed(str);
                if(arrOzoneFeed.size()>0)
                {
                    loadingMore=false;
                    arrList.addAll(arrOzoneFeed);
                    adpter.notifyDataSetChanged();
                    if(adpter==null)
                    {
                    adpter=new OzoneAdapter(getActivity(), arrList);
                    llList.setAdapter(adpter);
                    }else

                    {
                        adpter.notifyDataSetChanged();
                    }

                    adpter.notifyDataSetChanged();
                }
                adpter.notifyDataSetChanged();

                }
        }
        return null;
    }


    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub
        Intent i=new Intent(getActivity(),OUserPostActivity.class);
        startActivity(i);
    }
}
  

这是我的OzoneAdapter类

     public OzoneAdapter(Context cxt,ArrayList<OzoneFeedData>arr)

    {
        this.cxt=cxt;
        this.arr=arr;


        try{
         AppContoller.getInstance().pref=cxt.getSharedPreferences(AppContoller.getInstance().PREF_NAME, 0);

            strUserID=AppContoller.getInstance().pref.getString(AppContoller.getInstance().USER_ID, "0");
            strServerKey=AppContoller.getInstance().pref.getString(AppContoller.getInstance().SERVER_KEY, "0");
        }catch(Exception e){

        }
    }

    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        return arr.size();
    }

    @Override
    public Object getItem(int position) {
        // TODO Auto-generated method stub
        return position;
    }

    @Override
    public long getItemId(int position) {
        // TODO Auto-generated method stub
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        // TODO Auto-generated method stub

        final ViewHolder holder;
        if(convertView==null)
        {
            LayoutInflater inflater = ((Activity) cxt).getLayoutInflater();
            convertView=inflater.inflate(R.layout.ozone_feed_item, null);
            holder=new ViewHolder();

            holder.userImage=(ImageView)convertView.findViewById(R.id.profilePic);

            holder.userImage.setScaleType(ImageView.ScaleType.CENTER_CROP);

            holder.LocationPhoto=(NetworkImageView)convertView.findViewById(R.id.LocationImage);
            holder.tvName=(TextView)convertView.findViewById(R.id.name);
            holder.tvFavCount=(TextView)convertView.findViewById(R.id.tvFavCount);
            holder. tvShareinfo=(TextView)convertView.findViewById(R.id.tvSharedInfohh);

            holder.rvshare=(RelativeLayout)convertView.findViewById(R.id.relativesahrecount);
            holder.rvreply=(RelativeLayout)convertView.findViewById(R.id.relativereplycount);
            holder.rvfav=(RelativeLayout)convertView.findViewById(R.id.relativefaveecount);


        **Initializing the elements**

            convertView.setTag(holder);

        }
        else {

            holder = (ViewHolder) convertView.getTag();
        }

        holder.show.setOnClickListener(new OnClickListener() {

             @Override
             public void onClick(View v) {
              System.out.println("Show button");
              holder.show.setVisibility(View.INVISIBLE);
              holder.hide.setVisibility(View.VISIBLE);
              holder. tvContent.setMaxLines(Integer.MAX_VALUE);

             }
            });

        holder.hide.setOnClickListener(new OnClickListener() {

             @Override
             public void onClick(View v) {
              System.out.println("Hide button");
              holder.hide.setVisibility(View.INVISIBLE);
              holder.show.setVisibility(View.VISIBLE);
              holder.tvContent.setMaxLines(1);

             }
            });



        Picasso.with(cxt) //
        .load(arr.get(position).strUserImage).transform(new CircleTransform())
        .noFade()//
        .error(R.drawable.loader)
        .resize(200, 200)
        .centerCrop()// Keep proportion
        .into((ImageView)convertView.findViewById(R.id.profilePic));


        if(arr.get(position).strreportinfo.equalsIgnoreCase(""))
            {
           holder.tvShareinfo.setVisibility(View.GONE); 
            }else
            {
                holder.tvShareinfo.setVisibility(View.VISIBLE);

                holder.tvShareinfo.setText(arr.get(position).strreportinfo +"Shared post by"+arr.get(position).strName);
            }

    holder.tvShareinfo.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {


            Intent i=new Intent(cxt,OUserProfileDetail.class);


            i.putExtra("userid", arr.get(position).strreportinfoid);
            i.putExtra("username", arr.get(position).strreportinfo);


            cxt.startActivity(i);


        }
    });

        if(arr.get(position).strTweetLocation.equalsIgnoreCase("")){

            holder.tvTweetLocation.setVisibility(View.GONE);
        }else 
        {
            holder.tvTweetLocation.setVisibility(View.VISIBLE);
            holder.tvTweetLocation.setText(arr.get(position).strTweetLocation);

        }


        holder.tvName.setText(arr.get(position).strName);

        holder.tvFavCount.setText(arr.get(position).strFavouriteCount);

        holder.tvReplyCount.setText(arr.get(position).strReplyCount);

        holder.tvShareCount.setText(arr.get(position).strRetweetCount);

        holder.tvTimeStamp.setText(StaticData.convertDate(arr.get(position).strCreatedDate));

        if(arr.get(position).strContent.equalsIgnoreCase(""))
        {
        holder.tvContent.setVisibility(View.GONE);  
        }else
        {
            holder.tvContent.setVisibility(View.VISIBLE);

            ssp = arr.get(position).strContent;

            Log.d("sspppp", ssp);
            ssp = ssp.replace("\n", "<br>");
            Spanned sp = Html.fromHtml(ssp);
            Log.d("sssspppp2", sp.toString());
            holder.tvContent.setText(sp);
            holder.tvContent.setMovementMethod(LinkMovementMethod.getInstance());
        }

        if(arr.get(position).strContent.equalsIgnoreCase("")){

            holder.show.setVisibility(View.INVISIBLE);

        }else if(arr.get(position).strContent.length()<100){

            holder.show.setVisibility(View.INVISIBLE);

        }else if(arr.get(position).strContent.length()>100){

            holder.show.setVisibility(View.VISIBLE);

        }


        if(arr.get(position).arrTweetImage.size()>0)
        {

            if(arr.get(position).arrTweetImage.size()==1)
            {

        holder.feedImageView1.setImageUrl(arr.get(position).arrTweetImage.get(0), imageLoader);
        holder.feedImageView1.setVisibility(View.VISIBLE);
        holder.feedImageView2.setVisibility(View.GONE);
        holder.feedImageView3.setVisibility(View.GONE);

        holder.feedImageView1.setResponseObserver(new FeedImageView.ResponseObserver() {
                    @Override
                    public void onError() 
                    {
                        //
                    }

                    @Override
                    public void onSuccess() 
                    {
                        //
                    }
                });
            }
            else if(arr.get(position).arrTweetImage.size()==2)
            {
                holder.feedImageView1.setImageUrl(arr.get(position).arrTweetImage.get(0), imageLoader);
                holder.feedImageView2.setImageUrl(arr.get(position).arrTweetImage.get(1), imageLoader);
                holder.feedImageView1.setVisibility(View.VISIBLE);
                holder.feedImageView2.setVisibility(View.VISIBLE);
                holder.feedImageView3.setVisibility(View.GONE);

                holder.feedImageView1.setResponseObserver(new FeedImageView.ResponseObserver() {

                    @Override
                    public void onSuccess() {
                        // TODO Auto-generated method stub
                    }

                    @Override
                    public void onError() {
                        // TODO Auto-generated method stub
                    }
                });
              holder.feedImageView2.setResponseObserver(new FeedImageView.ResponseObserver() {

                    @Override
                    public void onSuccess() {
                        // TODO Auto-generated method stub
                    }

                    @Override
                    public void onError() {
                        // TODO Auto-generated method stub
                    }
                });

            }
            else if(arr.get(position).arrTweetImage.size()>=3)
            {
                holder.feedImageView1.setImageUrl(arr.get(position).arrTweetImage.get(0), imageLoader);
                holder.feedImageView2.setImageUrl(arr.get(position).arrTweetImage.get(1), imageLoader);
                holder.feedImageView3.setImageUrl(arr.get(position).arrTweetImage.get(2), imageLoader);
                holder.feedImageView1.setVisibility(View.VISIBLE);
                holder.feedImageView2.setVisibility(View.VISIBLE);
                holder.feedImageView3.setVisibility(View.VISIBLE);
            }

        }
        else
       {
   holder.feedImageView1.setVisibility(View.GONE);
   holder.feedImageView2.setVisibility(View.GONE);
   holder.feedImageView3.setVisibility(View.GONE);
       }

        // Click Listener



        holder.rvfav.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                urlIndex=0;
                selectedPosition=position;
                APIAccess.fetchData(OzoneAdapter.this, cxt, (Activity)cxt);
            }
        });

        holder.rvshare.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                urlIndex=2;
               selectedPosition=position;
               APIAccess.fetchData(OzoneAdapter.this, cxt, (Activity)cxt);
            }
        });

        holder.rvreply.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                Intent i=new Intent(cxt,OReplyActivity.class);
                i.putExtra("tweet_id", arr.get(position).strTweetID);
                i.putExtra("obj", arr.get(position));
                cxt.startActivity(i);
            }
        });

        holder.ivHide.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub

                selectedPosition=position;
                getPopupWindow();

               popupWindow.showAsDropDown(v, -5, 0);    
            }
        });

             holder.ivfavourite.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                urlIndex=0;
                selectedPosition=position;
                APIAccess.fetchData(OzoneAdapter.this, cxt, (Activity)cxt);
            }
        });

        holder.userImage.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub

                Intent i=new Intent(cxt,OUserProfileDetail.class);

                i.putExtra("userid", arr.get(position).strUserID);
                i.putExtra("username", arr.get(position).strName);


                cxt.startActivity(i);
            }
        });

        holder.feedImageView1.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                Intent i=new Intent(cxt,OImageDetailActivity.class);
                i.putExtra("obj", arr.get(position));
                cxt.startActivity(i);
            }
        });
holder.feedImageView2.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                Intent i=new Intent(cxt,OImageDetailActivity.class);
                i.putExtra("obj", arr.get(position));
                cxt.startActivity(i);
            }
        });

holder.feedImageView3.setOnClickListener(new OnClickListener() {

    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub
        Intent i=new Intent(cxt,OImageDetailActivity.class);
        i.putExtra("obj", arr.get(position));
        cxt.startActivity(i);
    }
}); 
        return convertView;
    }


    @Override
    public String httpPost() {
        // TODO Auto-generated method stub

        String response="";
        if(urlIndex==0)
        {
        response=OpenConnection.callUrl(StaticData.SABAKUCH_OFAV_OUNFAV+"post_id/"+arr.get(selectedPosition).strTweetID+"/userid/"+strUserID+"/key/"+strServerKey);
        }else if(urlIndex==1)
        {
            response=OpenConnection.callUrl(StaticData.SABAKUCH_OPOSTDELETE+"id/"+arr.get(selectedPosition).strTweetID+"/userid/"+strUserID+"/key/"+strServerKey);
        }
        else if(urlIndex==2)
        {
            response=OpenConnection.callUrl(StaticData.SABAKUCH_OSHAREPOST+"post_id/"+arr.get(selectedPosition).strTweetID+"/userid/"+strUserID+"/key/"+strServerKey);
        }
        else if(urlIndex==3) {

            response=OpenConnection.callUrl(StaticData.SABAKUCH_OMUTEPOST+"id/"+arr.get(selectedPosition).strTweetID+"/login_id/"+strUserID+"/userid/"+strUserID+"/check/mute/key/"+strServerKey);
        }
        else if(urlIndex==4)
        {
            postUserBlock();
            response=APIAccess.openConnection(StaticData.SABAKUCH_OMUTEPOST, reqEntity);
             //response = OpenConnection.callUrl(StaticData.SABAKUCH_OMUTEPOST+"post_id/"+arr.get(selectedPosition).strTweetID+"/ownerid/"+arr.get(selectedPosition).strUserID+"/userid/"+strUserID+"/key/"+strServerKey); 
        }
        return response;
    }

    @Override
    public String httpAfterPost(String str) {
        // TODO Auto-generated method stub

        if(str!=null)
        {
            if(urlIndex==0)
            {
            if(SabaKuchParse.parseFavData(str).equalsIgnoreCase(" "))
            {

            }else
            {
                OzoneFeedData obj=new OzoneFeedData();
                obj.strContent=arr.get(selectedPosition).strContent;
                obj.strCreatedDate=arr.get(selectedPosition).strCreatedDate;
                obj.strFavouriteCount=SabaKuchParse.parseFavData(str);
                obj.strGender=arr.get(selectedPosition).strGender;
                obj.strlat=arr.get(selectedPosition).strlat;
                obj.strlon=arr.get(selectedPosition).strlon;
                obj.strName=arr.get(selectedPosition).strName;
                obj.strreportinfo=arr.get(selectedPosition).strreportinfo;
                obj.strReplyCount=arr.get(selectedPosition).strReplyCount;
                obj.strRetweetCount=arr.get(selectedPosition).strRetweetCount;
                obj.strTweetID=arr.get(selectedPosition).strTweetID;
                obj.strTweetLocation=arr.get(selectedPosition).strTweetLocation;
                obj.strUserID=arr.get(selectedPosition).strUserID;
                obj.strUserImage=arr.get(selectedPosition).strUserImage;
                obj.arrTweetImage=arr.get(selectedPosition).arrTweetImage;

                arr.set(selectedPosition, obj);
                notifyDataSetChanged();

            }
            }
            else if(urlIndex==1)
            {
                if(SabaKuchParse.jsonStatus(str)==1)
                {
                    //Toast.makeText(cxt, SabaKuchParse.jsonErrorMessage(str), Toast.LENGTH_SHORT).show();
                    arr.remove(selectedPosition);
                    notifyDataSetChanged();
                }
                else
                {
                    Toast.makeText(cxt, SabaKuchParse.jsonErrorMessage(str), Toast.LENGTH_SHORT).show();

                }
            }else if(urlIndex==2)
            {
                if(SabaKuchParse.parseShareData(str).equalsIgnoreCase(" "))
                {

                }
                else
                {
                    OzoneFeedData obj = new OzoneFeedData();
                    obj.strContent=arr.get(selectedPosition).strContent;
                    obj.strCreatedDate=arr.get(selectedPosition).strCreatedDate;
                    obj.strFavouriteCount=arr.get(selectedPosition).strFavouriteCount;
                    obj.strGender=arr.get(selectedPosition).strGender;
                    obj.strlat=arr.get(selectedPosition).strlat;
                    obj.strlon=arr.get(selectedPosition).strlon;
                    obj.strName=arr.get(selectedPosition).strName;
                    obj.strReplyCount=arr.get(selectedPosition).strReplyCount;
                    obj.strRetweetCount=SabaKuchParse.parseShareData(str);
                    obj.strreportinfo=arr.get(selectedPosition).strreportinfo;
                    obj.strTweetID=arr.get(selectedPosition).strTweetID;
                    obj.strTweetLocation=arr.get(selectedPosition).strTweetLocation;
                    obj.strUserID=arr.get(selectedPosition).strUserID;
                    obj.strUserImage=arr.get(selectedPosition).strUserImage;
                    obj.arrTweetImage=arr.get(selectedPosition).arrTweetImage;

                    arr.set(selectedPosition, obj);
                    notifyDataSetChanged();
                }
                }
                else if(urlIndex==3){
                try{
                    JSONObject jsonObj = new JSONObject(str);
                    if(jsonObj.getJSONObject("feeds").getInt("succeses")==1)
                    {
                //  Toast.makeText(cxt, jsonObj.getJSONObject("feeds").getString("msessage"), Toast.LENGTH_SHORT).show();   
                        arr.remove(selectedPosition);
                        notifyDataSetChanged();
                    }
                }
                catch(Exception e){

                }

            }else if(urlIndex==4)
            {
                try{
                    JSONObject jsonObj = new JSONObject(str);
                    if(jsonObj.getJSONObject("feeds").getInt("successes")==1)
                    {
                    Toast.makeText(cxt, jsonObj.getJSONObject("feeds").getString("message"), Toast.LENGTH_SHORT).show();    
                        arr.remove(selectedPosition);
                        notifyDataSetChanged();
                    }

                }
                catch(Exception e)
                {

                }
            }
}
        return null;
    }
    public void postUserBlock()
    {
        try
        {
         StringBody post_id=new StringBody(arr.get(selectedPosition).strTweetID);
         StringBody key=new StringBody(strServerKey);
         StringBody userid=new StringBody(strUserID);
         StringBody ownerid=new StringBody(arr.get(selectedPosition).strUserID);
         StringBody block=new StringBody("block");

        reqEntity = new MultipartEntity();

        reqEntity.addPart("post_id", post_id);
        reqEntity.addPart("key", key);
        reqEntity.addPart("userid", userid);
        reqEntity.addPart("ownerid", ownerid);
        reqEntity.addPart("block", block);

        }
        catch(Exception e)
        {
            System.out.println("err" + e);
        }

    }

    public void getPopupWindow()
    {

        popupWindow=new PopupWindow(cxt);
        ListView popList=new ListView(cxt);
        ArrayList<String>arrPopItem=new ArrayList<String>();
    //  selectedPosition ;
        arrPopItem.add("Mute");
        arrPopItem.add("Block or Spam");
        //String ID =arr.get(selectedPosition).strUserID;
    //  Log.d("hdfu", ID);
        if(strUserID.equalsIgnoreCase(arr.get(selectedPosition).strUserID))
        {
            arrPopItem.remove("Mute");
            arrPopItem.remove("Block or Spam");
            arrPopItem.add("Delete");

        //  POPVALUE ="Delete";
        }
        PopupAdapter adpter=new PopupAdapter(arrPopItem);
        popList.setAdapter(adpter);
        popupWindow.setFocusable(true);
        popupWindow.setHeight(WindowManager.LayoutParams.WRAP_CONTENT);
        popupWindow.setWidth(200);
        popupWindow.setContentView(popList);

    }

    private class PopupAdapter extends BaseAdapter
    {
      ArrayList<String> arrPop;
    public  PopupAdapter (ArrayList<String>arr)
    {
    this.arrPop=arr;

    }

        @Override
        public int getCount() {
            // TODO Auto-generated method stub
            return arrPop.size();
        }

        @Override
        public Object getItem(int position) {
            // TODO Auto-generated method stub
            return position;
        }

        @Override
        public long getItemId(int position) {
            // TODO Auto-generated method stub
            return position;
        }

        @Override
        public View getView(final int position, View convertView, ViewGroup parent) {
            // TODO Auto-generated method stub
            View v=convertView;

            if(v==null)
            {
                v=View.inflate(cxt, R.layout.popup_window_row, null);
                /*NetworkImageView profilePic = (NetworkImageView)v
                        .findViewById(R.id.profilePic);
                profilePic.setVisibility(View.GONE);*/

                TextView tvCategery=(TextView)v.findViewById(R.id.tvPopuptext);

                tvCategery.setText(arrPop.get(position));
                tvCategery.setTextColor(Color.WHITE);

                tvCategery.setOnClickListener(new OnClickListener() {

                    //String uu =arr.get(position).strName;

                    @Override
                    public void onClick(View v) {
                        // TODO Auto-generated method stub
                        if((position==2))
                        {
                        urlIndex=3;
                        APIAccess.fetchData(OzoneAdapter.this, cxt, (Activity)cxt);
                        }else if(position==0)
                        {
                            urlIndex=3;
                            APIAccess.fetchData(OzoneAdapter.this, cxt, (Activity)cxt);
                        }else if(position==1)
                        {
                            Intent i =new Intent(cxt,Ozonespamactivity.class);
                            i.putExtra("postid", arr.get(selectedPosition).strTweetID);


                            i.putExtra("name", arr.get(selectedPosition).strName);
                            i.putExtra("userid", arr.get(selectedPosition).strUserID);

                            cxt.startActivity(i);
                        }

                    popupWindow.dismiss();
                    }
                });

                //profilePic.setImageUrl(StaticData.MIF_PROFILE_IMG_URL+arr.get(position).strCatRelativePath+"/"+arr.get(position).strCatID+".jpg", imageLoader);

            }
               return v;
        }
    }

请让我知道我在这里缺少的东西。

1 个答案:

答案 0 :(得分:0)

谢谢大家的支持。我已经解决了我的问题。

我刚刚在调用refresh()方法之后添加新项目之前添加了清除listview。

llList.setOnRefreshListener(new OnRefreshListener() {

            @Override
            public void onRefresh() {

                //llList.setAdapter(null);
                android.support.v4.app.Fragment fragment = null;
                fragment = new OzoneFragment();

                 APIAccess.fetchData(OzoneFeedFragment.this, getActivity(), getActivity());

                llList.postDelayed(new Runnable() {


                    @Override
                    public void run() {
                        llList.onRefreshComplete();
                        //messageList = new ArrayList<MessageBean>();

                           UrlIndex=0;

                           arrList.clear(); //this is what I did torefresh the list 

                            adpter.notifyDataSetChanged();
                            Log.e("check", "check");
                    }
                }, 2000);
            }
        });