Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/393.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/199.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/eclipse/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在类扩展基适配器的对象上调用notifyDataSetChanged()时会发生什么情况_Java_Android_Android Adapter - Fatal编程技术网

Java 在类扩展基适配器的对象上调用notifyDataSetChanged()时会发生什么情况

Java 在类扩展基适配器的对象上调用notifyDataSetChanged()时会发生什么情况,java,android,android-adapter,Java,Android,Android Adapter,我正在查看Android上的代码,但不明白在扩展BaseAdapter的类的对象上调用notifyDataSetChanged()时会发生什么。 在代码中,调用了channelListAdapter.notifyDataSetChanged() 以下是ChannelListAdapter类的代码: public class ChannelListAdapter extends BaseAdapter { Field[] fields; Context context;

我正在查看Android上的代码,但不明白在扩展
BaseAdapter
的类的对象上调用
notifyDataSetChanged()
时会发生什么。 在代码中,调用了
channelListAdapter.notifyDataSetChanged()

以下是
ChannelListAdapter
类的代码:

 public class ChannelListAdapter extends BaseAdapter {

    Field[] fields;
    Context context;
    List<Channels> channelList = null;
    String dateString, likeData, ab, imageData;
    Channels item;
    DBVideos dbVideos;
    VideoListAdapter videoListAdapter;
    MostRecentFragment parentFragment;
    public boolean loadingMoreChannels;
    public boolean noMoreChannelFound;
    Map<String, Boolean> map = new HashMap<String, Boolean>();
    Map<String, Integer> totalLikeCount = new HashMap<String, Integer>();
    public Map<String, Boolean> timerMap = new HashMap<String, Boolean>();
    Map<String, List<Videos>> mapVideos = new HashMap<String, List<Videos>>();

    public ChannelListAdapter(Context context) {
        this.context = context;
    }

    public Map<String, List<Videos>> getMapVideos() {
        return mapVideos;
    }

    public void setMapVideos(Map<String, List<Videos>> mapVideos) {
        this.mapVideos = mapVideos;
    }

    public ChannelListAdapter(Context context, List<Channels> channelList) {
        this.context = context;
        // listener = new NewsFeedListener(context, map, totalLikeCount);
        // listener.setListAdapter(this);
        this.channelList = channelList;
    }

    public ChannelListAdapter(Context context, List<Channels> channelList, MostRecentFragment parentFragment) {
        this.context = context;
        this.parentFragment = parentFragment;
        this.channelList = channelList;
    }

    public String getLastFeedModificationTime() {
        Channels lastNews = channelList.get(channelList.size() - 1);
        return lastNews.getLastModifyDate();
    }

    public void setNewsList(List<Channels> channelList) {
        this.channelList = channelList;
    }

    @Override
    public int getCount() {
        return channelList.size();
    }

    @Override
    public Object getItem(int position) {
        return channelList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return channelList.indexOf(getItem(position));
    }

    public static class ViewHolder {
        public TextView channelTitle;
        public ImageView imgProcess;
        ListView videoListView;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = new ViewHolder();
        LayoutInflater mInflater = (LayoutInflater) context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);

        if (convertView == null) {
            convertView = (View) mInflater.inflate(R.layout.channel_list_item, null);
            holder.channelTitle = (TextView) convertView.findViewById(R.id.tv_channel_name);
            holder.imgProcess = (ImageView) convertView.findViewById(R.id.img_process);
            holder.videoListView = (ListView) convertView.findViewById(R.id.list_videos);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        item = (Channels) getItem(position);
        final ViewHolder finalHolder = holder;
        holder.channelTitle.setText(item.getTitle());
        if (mapVideos.size() > 0 && mapVideos.containsKey(item.getId())) {

        } else {
            Glide.with(context).load("http://4.bp.blogspot.com/-rSoHhekcu9A/T6PQ6d8mKSI/AAAAAAAAASg/hStx9Mg18fc/s1600/22.gif").asGif().placeholder(R.drawable.img_loading).crossFade()
                    .into(holder.imgProcess);
            String url = null;
            url = context.getString(R.string.url_6e_channel_context)+CommonUtils.getEncodedUrl(context, context.getString(R.string.url_to_retive_all_video_selected_channel_first)+item.getId())+"+ContentType:Indigo+Video'&rowlimit=3&"+CommonUtils.getEncodedUrl(context,context.getString(R.string.url_to_retive_all_video_selected_channel_sec));
            System.out.println("url ="+url);
            ServiceCallAsync sca = new ServiceCallAsync(context, null,"Get", null, url, new AsyncResponse() {
                @Override
                public void processFinish(Object output) {
                    ServiceResponse serviceResponse = (ServiceResponse) output;
                    if(serviceResponse.getCode()==200){
                        parseDataAndStoreinDb(serviceResponse.getData(),finalHolder);
                    }else{

                    }

                }
            });
            sca.execute();
        }
        if (position == channelList.size() - 1) {
            if (parentFragment != null && !loadingMoreChannels && !noMoreChannelFound) {
                loadingMoreChannels = true;
                parentFragment.loadMore();
            }
        }

        return convertView;
    }

    protected void parseDataAndStoreinDb(String data, ViewHolder finalHolder) {
        List<Videos> videosList = new ArrayList<>();

        try {
            JSONObject mainObj = new JSONObject(data);
            JSONObject dObj = mainObj.getJSONObject("d");
            JSONObject queryObj = dObj.getJSONObject("query");
            JSONObject primaryQueryObj = queryObj.getJSONObject("PrimaryQueryResult");
            JSONObject releventObj = primaryQueryObj.getJSONObject("RelevantResults");
            JSONObject tableObj = releventObj.getJSONObject("Table");
            JSONObject rowsObj = tableObj.getJSONObject("Rows");
            JSONArray resultArray = rowsObj.getJSONArray("results");
            for(int i = 0; i<resultArray.length();i++){
                Map<String ,String> videoFieldsMap=new HashMap<String, String>();
                JSONObject resultObj= resultArray.getJSONObject(i);
                JSONObject cellesObj= resultObj.getJSONObject("Cells");
                JSONArray resultInnerArray = cellesObj.getJSONArray("results");
                for(int j = 0; j<resultInnerArray.length();j++){
                    JSONObject obj= resultInnerArray.getJSONObject(j);
                    //System.out.println("obj ="+obj.getString("Key"));
                    videoFieldsMap.put(obj.getString("Key"), obj.getString("Value"));
                }
                videoFieldsMap.put("ListId", item.getId());
                Videos video = convertMapToVideoModel(videoFieldsMap);
                System.out.println("video convertedMap ="+video);
                videosList.add(video);
            }
            if(dbVideos == null ){
                dbVideos = new DBVideos(context);
            }
            dbVideos.insertVideos(videosList);
        //  mapVideos.put(item.getId(), videosList);
            setVideoListAdapter(videosList,finalHolder);
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }
    private void setVideoListAdapter(List<Videos> list, ViewHolder finalHolder) {
        if(videoListAdapter == null){
            videoListAdapter = new VideoListAdapter(context, list,parentFragment);
        }
        videoListAdapter.setVideoList(list);
        System.out.println("list ="+list.size());
        System.out.println("list ="+list.get(1));
        finalHolder.videoListView.setAdapter(videoListAdapter);
        finalHolder.videoListView.setVisibility(View.VISIBLE);
        finalHolder.imgProcess.setVisibility(View.GONE);
        ListHeightUtils.setListViewHeightBasedOnChildren(finalHolder.videoListView);

    }

    private Videos convertMapToVideoModel(Map<String, String> videoFieldsMap){
        Class clazz=Videos.class;
        Object object = null;
        System.out.println("videoFieldsMap ="+videoFieldsMap);
        try{
            object=clazz.newInstance();
            for(Field field:clazz.getDeclaredFields()){
                field.setAccessible(true);
                System.out.println("field =="+videoFieldsMap.get(field));
                field.set(object, videoFieldsMap.get(field.getName()));
            }
            System.out.println("object ="+object.toString());
        }catch(Exception e){
            e.printStackTrace();
        }
        return (Videos)object;
    }

    }
公共类ChannelListAdapter扩展了BaseAdapter{
字段[]字段;
语境;
List channelList=null;
字符串日期字符串,如数据、ab、图像数据;
渠道项目;
DBVideos-DBVideos;
视频列表适配器;
最短片段;
公共布尔加载更多通道;
找到了公共布尔NomoreChannel;
Map Map=newhashmap();
Map TotalikeCount=新HashMap();
publicmap timerMap=newhashmap();
Map mapVideos=新建HashMap();
公共ChannelListAdapter(上下文){
this.context=上下文;
}
公共地图getMapVideos(){
返回地图视频;
}
公共void setMapVideos(地图地图视频){
this.mapVideos=mapVideos;
}
公共ChannelListAdapter(上下文上下文,列表channelList){
this.context=上下文;
//listener=新的NewsFeedListener(上下文、映射、TotalikeCount);
//setListAdapter(this);
this.channelList=channelList;
}
公共ChannelListAdapter(上下文上下文、列表channelList、MostRecentFragment parentFragment){
this.context=上下文;
this.parentFragment=parentFragment;
this.channelList=channelList;
}
公共字符串getLastFeedModificationTime(){
Channels lastNews=channelList.get(channelList.size()-1);
返回lastNews.getLastModifyDate();
}
公共无效设置新闻列表(列表频道列表){
this.channelList=channelList;
}
@凌驾
public int getCount(){
返回channelList.size();
}
@凌驾
公共对象getItem(int位置){
返回channelList.get(位置);
}
@凌驾
公共长getItemId(int位置){
返回channelList.indexOf(getItem(position));
}
公共静态类视图持有者{
公共文本视图频道标题;
公共图像查看imgProcess;
ListView视频ListView;
}
@凌驾
公共视图getView(int位置、视图转换视图、视图组父视图){
ViewHolder=新的ViewHolder();
LayoutInflater mInflater=(LayoutInflater)context.getSystemService(Activity.LAYOUT\u INFLATER\u SERVICE);
if(convertView==null){
convertView=(视图)最小充气器。充气(R.layout.channel\u list\u项,空);
holder.channelTitle=(TextView)convertView.findViewById(R.id.tv\u频道名称);
holder.imgProcess=(ImageView)convertView.findViewById(R.id.img_进程);
holder.videoListView=(ListView)convertView.findViewById(R.id.list\u视频);
convertView.setTag(支架);
}否则{
holder=(ViewHolder)convertView.getTag();
}
项目=(通道)获取项目(位置);
最终视图持有者finalHolder=持有者;
holder.channelTitle.setText(item.getTitle());
if(mapVideos.size()>0&&mapVideos.containsKey(item.getId()){
}否则{
Glide.with(context.load)(“http://4.bp.blogspot.com/-rSoHhekcu9A/T6PQ6d8mKSI/AAAAAAAAASg/hStx9Mg18fc/s1600/22.gif“”.asGif()占位符(R.drawable.img_加载).crossFade()
.into(holder.imgProcess);
字符串url=null;
url=context.getString(R.string.url\u 6e\u channel\u context)+CommonUtils.getEncodedUrl(context,context.getString(R.string.url\u to\u retive\u all\u video\u selected\u channel\u first)+item.getId()+“+ContentType:Indigo+video'&rowlimit=3&”+CommonUtils.getEncodedUrl(context,context.getString(R.url\u to\u retive\u all\u video\u selected\u channel\u sec));
System.out.println(“url=“+url”);
ServiceCallAsync sca=new ServiceCallAsync(上下文,null,“Get”,null,url,new AsyncResponse(){
@凌驾
公共void processFinish(对象输出){
ServiceResponse ServiceResponse=(ServiceResponse)输出;
if(serviceResponse.getCode()==200){
parseDataAndStoreinDb(serviceResponse.getData(),finalHolder);
}否则{
}
}
});
sca.execute();
}
if(position==channelList.size()-1){
if(parentFragment!=null&&!loadingMoreChannels&&!noMoreChannelFound){
loadingMoreChannels=true;
parentFragment.loadMore();
}
}
返回视图;
}
受保护的void parseDataAndStoreinDb(字符串数据,ViewHolder finalHolder){
List videosList=new ArrayList();
试一试{
JSONObject mainObj=新的JSONObject(数据);
JSONObject dObj=mainObj.getJSONObject(“d”);
JSONObject queryObj=dObj.getJSONObject(“查询”);
JSONObject primaryQueryObj=queryObj.getJSONObject(“PrimaryQueryResult”);
JSONObject releventObj=primaryQueryObj.getJSONObject(“相关结果”);
JSONObject tableObj=releventObj.getJSONObject(“表”);
JSONObject rowsObj=tableObj.getJSONObject(“行”);
JSONArray resultArray=rowsObj.getJSONArray(“结果”);

对于(int i=0;i,适配器定义了在视图中显示项目列表的规则-它通常在ListView或RecyclerView的上下文中(但实际上可以是多种内容)。视图不知道基础数据集何时更改,因此在其初始绘制后,需要告知其数据何时不再是最新的

假设您有以下列表:

[甲、乙、丙]

在某个时刻,