如果没有像list.onLoadListener(列表完成其数据填充)的事件如何访问列表的第一行?在android中加载列表视图时访问列表的第一个项目
当列表重用其行为表现这个听众是不存在的,这是可以理解的。但是,至少有一个项目(第一个项目,位置0)时,我需要访问列表的第一个项目。
设置适配器后列出
list.getChildAt(0)
返回我空。所以我需要延迟访问第一个项目?
我们可以使用列表项目单击监听器访问列表项目(该项目中的视图)。当我确定列表的第一项已填满时,我想使用项目。
我正在使用TextureView在列表项目中播放视频。所以一旦列表中充满了它的项目,我想自动播放第一个项目的视频(没有任何点击或用户交互)。
这里是我的代码: -
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.home);
list = (ListView) v.findViewById(R.id.list);
videoListDatas = new ArrayList<VideoListData>();
adapter = new MyVideoListAdapterNew(getActivity(), videoListDatas);
list.setAdapter(adapter);
getVideoList(); //Method which get data from server
}
这里是getVideoList()方法执行
private void getVideoList() {
final MyProgressDialog progressDialog = new MyProgressDialog(context);
new Thread(new Runnable() {
@Override
public void run() {
try {
// Implementation goes here fill array with data
} catch (Exception e) {
e.printStackTrace();
}
runOnUiThread(new Runnable() {
@Override
public void run() {
adapter.notifyDataSetChanged();
progressDialog.dismiss();
}
});
}
}).start();
}
这里是我的适配器
public class MyVideoListAdapterNew extends BaseAdapter {
Context context;
private LayoutInflater inflater;
ArrayList<VideoListData> videoListDatas;
public MyVideoListAdapterNew(FragmentActivity fragmentActivity,
ArrayList<VideoListData> videoListDatas) {
context = fragmentActivity;
this.videoListDatas = videoListDatas;
inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return videoListDatas.size();
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return videoListDatas.get(position);
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return 0;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView == null) {
convertView = inflater.inflate(R.layout.myvideo_row, null);
holder = new ViewHolder();
holder.flVideo = (FrameLayout) convertView
.findViewById(R.id.flVideo);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
try {
//Filling views by getting values from array
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if(position == 0){
//Code to play first video automatically
}else{
}
return convertView;
}
private static class ViewHolder {
FrameLayout flVideo;
}
}
我知道代码将帮助不大但我只是将它发布在一些人的建议上。
谢谢。
你必须在这里发布一些相关的代码。 –