android - 有没有代替ListView,GridView的好用的第三方库呢?
阿神
阿神 2017-04-17 15:44:19
0
5
518
阿神
阿神

闭关修行中......

reply all(5)
阿神

This can only mean that your grasp of ListView is not enough. ListView relies on the data connection of the data adapter Adapter. Data modification also exists in the data source or data adapter. It does not mean that you need to regenerate the data adapter.

小葫芦

Use the notifyDataSetChanged() method of the adapter Adapter to update. . .
Give me an example:

protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        button_add = (Button) findViewById(R.id.button);

        //  1.绑定GridView
        gridView = (GridView) findViewById(R.id.gridView);

        //  2.创建List资源类对象:
        list = new ArrayList<Map<String, Object>>();
        for (int i=0; i<images.length; i++) {
            Map<String,Object> map = new HashMap<String, Object>();
            map.put("imageid",images[i]);
            map.put("words",words[i]);
            list.add(map);
        }

        //  3.创建一个 SimpleAdapter
        simpleAdapter = new SimpleAdapter(
                this,   //上下文
                list,   //资源对象
                R.layout.simple_adapter_cell,
                new String[] {"imageid","words"},
                new int[] {R.id.imageView,R.id.textView}                
        );

        //  4.加载到GridView中
        gridView.setAdapter(simpleAdapter);

        //  5.设置 GridView的点击事件:
        gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Log.e("AdapterView",Integer.toString(parent.getId()));
                Log.e("View",Integer.toString(view.getId()));
                Log.e("position",Integer.toString(position));
                Log.e("id", Long.toString(id));
            }
        });

        //  6.GridView 的动态更新
        button_add.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                //  6.1 给资源类添加新的 Map
                Map<String,Object> temp = new HashMap<String, Object>();    //新建Map
                temp.put("imageid",images[0]);                              //添加新的资源
                temp.put("words","P");
                list.add(temp);

                //  6.2 通知 GridView 更新
                simpleAdapter.notifyDataSetChanged();

            }
        });


    }
Peter_Zhu

Add directly to the data source List, and then notify the Adapter to update the data, adapter.notifyDataSetChanged();

Peter_Zhu

Add new data to the adapter’s list and then adapter.notifiedxxx

洪涛

RecyclerView cooperates with staggergroidlayoutmanager
Inherit adapter yourself
Use adapter.notifydatachanged() to notify updates

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!