ArrayList适配器NotifyDataSetChanged无法正常工作

时间:2013-11-06 20:29:01

标签: java android listview android-arrayadapter

我有ListView,其中设置了CustomArray适配器。我在这个适配器中发送一个名为SimpleLoationWithPaging的模型,这是我的SimpleLocationWithPaging模型类。

public class SimpleLocationWithPaging{
    private SimpleLocation location;
    private PagingModel paging1;
    private PagingModel paging2;
    private PagingModel paging3;
    //With it's getters and setters
}

这里是我的数组适配器的getView方法,我把代码放在这里更充分使用..

@Override
public View getView(int position, View convertView, ViewGroup parent){
    final int a = position;
    View v = convertView;
        if (v == null) {
             LayoutInflater inflater = (LayoutInflater)getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            v = inflater.inflate(R.layout.test, null);
        }
        final SimpleLoctaionWithPaging i = objects.get(position);//Objects is list of(SimpleLocationWithPaging)
       if (i != null) {
            TextView locationTextView = (TextView) v.findViewById(R.id.locationTextView);
            locationTextView.setText(i.getLocation().getLocationName());
           if(i.getPaging1 != null){
                 RelativeLayout relativeLayout = (RelativeLayout)v.findById(R.id.PagingLayOut1);
                 //Set some images and text in this paging layout
           }
           if(i.getPaging2 !=null){
                 RelativeLayout relativeLayout2 = (RelativeLayout)v.findById(R.id.PagingLayOut2);
                 //Set some images and text in this paging layout
           }
           if(i.getPaging3 !=null){
                RelativeLayout relativeLayout = (RelativeLayout)v.findById(R.id.PagingLayOut3);
                 //Set some images and text in this paging layout
           }


      }//end of i !=null if
}//End of getView method

问题是当我设置SimpleLocationWithPaging.setPaging1(pagingModel)并在适配器上调用notifyDataSetChange时它没有显示更改但我必须在屏幕上做一个小滚动,而不是向我显示UI上的更改。

修改 的 我在这里调用我的通知数据集已更改。我试过三种方式 1 - 通过在此类中设置我的适配器实例并直接调用notifyDataSetChanged(); 2-asyncThread并调用notifyDataSetChanged();在onPostExecute()方法中 但是有时它们都工作不正常。请记住,在套接字连接时调用此方法addPagingInLocationList(即服务器通过套接字向我发送数据)。

public void addPagingInLocationList(PagingModel pagingModel){

    AddPagingUpdateUiTask addPagingUpdateUiTask = new AddPagingUpdateUiTask(pageLocationAdapterInstance);
    String a[] = null;
    if(pagingModel != null){
        SimpleLoctaionWithPaging simpleLoctaionWithPaging = this.findSimpleLoctaionWithPaging(pagingModel.getLocation_id());
        if(simpleLoctaionWithPaging.getPage1() == null) {
            simpleLoctaionWithPaging.setPage1(pagingModel);
            addPagingUpdateUiTask.setPagingModel(pagingModel);
            //startTimersOfPagings(pagingModel);


        }
        else if(simpleLoctaionWithPaging.getPage2() == null){
            simpleLoctaionWithPaging.setPage2(pagingModel);
            addPagingUpdateUiTask.setPagingModel(pagingModel);
        }
        else {
            simpleLoctaionWithPaging.setPage3(pagingModel);
            addPagingUpdateUiTask.setPagingModel(pagingModel);
        }
    }

    addPagingUpdateUiTask.execute(a);


    //pageLocationAdapterInstance.updateSimpleLocationWithPagingList(simpleLoctaionWithPagingList);


}

0 个答案:

没有答案