访问列表的第一个项目时列表视图在android系统加载

访问列表的第一个项目时列表视图在android系统加载

本文介绍了访问列表的第一个项目时列表视图在android系统加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果有喜欢list.onLoadListener任何情况(列表与它的数据填充完成)如何进入名单的第一行?

If there is no event like list.onLoadListener(list is done with its data filling) how to access list's first row?

随着列表重用其一行性能监听器是不存在是可以理解的。但我需要访问列表的第一个项目时,至少有一个项目(第一个项目,位置0)。

As list reuses its row for performance this listener is not there that is understandable. But I need to access list's first item when at least there is one item(first item , position 0).

在设置适配器列表

list.getChildAt(0)

返回我空。那么,我需要把延迟访问的第一个项目?

returns me null. So Do i need to put delay for accessing first item?

我们可以使用列表项的点击访问监听器列表中的项目(在该项目的意见)。我想用项目时我可以肯定的是列表的第一个项目填补。

We can access list items(views in that item) on using list item click listener. I want to use item when I can be sure that list's first item has filled.

我使用TextureView播放视频列表项。因此,一旦名单充满了它的项目我想自动播放第一项的视频。(无需任何点击或用户交互)。

I am playing videos in list item using TextureView. So once list is filled with its item I want to play first item's video automatically.(without any click or user interaction).

下面是我的code: -

Here is my code :-

@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()方法执行

Here is getVideoList() method implementation

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;

}

}

我知道code不会帮助很多,但我只是张贴在一些人的建议。

I know code will not help much but I am just posting it on some people's suggestion.

感谢。

推荐答案

我发现从这个线程这种情况的解决方案: -

I found the solution for this situation from this thread :- http://stackoverflow.com/a/6944587/647014

我的要求是尽快完成清单的数据加载访问列表的第一个项目。这样,名单等待,直到它的数据刷新/加载。

My requirement was to accessing list's first item as soon as list completes its data loading. This way list waits till its data is refreshed/loaded.

感谢。

这篇关于访问列表的第一个项目时列表视图在android系统加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-24 19:54