Android学习之视频音乐列表ListView

路线:一个Video类,把实例保存到容器中,给ListView设置适配器

Video类

public class Video {
    private String name;

    private int imageId;

    private String address;

    private String date;

    private int video_or_music;

    public Video(String name, String address, String date, int imageId, int v_or_m){
        this.name = name;
        this.imageId = imageId;
        this.address = address;
        this.date = date;
        this.video_or_music = v_or_m;
    }

    public String getName(){
        return name;
    }

    public int getimageID(){
        return imageId;
    }

    public String getAddress(){
        return address;
    }

    public String getDate(){
        return date;
    }

    public int getVideo_or_music(){
        return video_or_music;
    }
}
适配器VideoAdapter

public class VideoAdapter extends ArrayAdapter
MainActivity

对象保存到容器中去

private List
导入item布局文件

import static com.example.videoplay.R.layout.video;
配置适配器

final ListView listView = (ListView) findViewById(R.id.list_view_1);
adapter = new VideoAdapter(MainActivity.this,
                video, videoList);
listView.setAdapter(adapter);
添加数据

videoList.add(new Video());
adapter.notifyDataSetChanged();
ListView监听

	//监听listView
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView adapterView, View view, int i, long l) {
                Video video = videoList.get(i);//从容器中获取实例
                if(video.getVideo_or_music()==0){
                    Intent intent = new Intent(MainActivity.this,VideoPlay.class);
                    intent.putExtra("address",video.getAddress());
                    intent.putExtra("name",video.getName());
                    startActivity(intent);
                }
                if(video.getVideo_or_music()==1){
                    Intent intent = new Intent(MainActivity.this,MusicPlay.class);
                    intent.putExtra("address",video.getAddress());
                    intent.putExtra("name",video.getName());
                    startActivity(intent);
                }
            }
        });







你可能感兴趣的:(Android)