If there is no event like list.onLoadListener (the list is executed with filling in its data), how can I access the first line of the list?
As the list repeats its line for performance, this listener does not exist, which is understandable. But I need to access the first element of the list if at least one element (first element, position 0).
After installing the adapter in the list
list.getChildAt(0)
returns null. So do I need to set a delay to access the first item?
We can access the list items (views in this item) by using the list click listener. I want to use an element when I can be sure that the first element of the list is full.
I am playing a video in a list item using a TextureView. Therefore, as soon as the list is filled with its element, I want to automatically play the video with the first item (without any click or user interaction).
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();
Here is the implementation of the getVideoList () method
private void getVideoList() { final MyProgressDialog progressDialog = new MyProgressDialog(context); new Thread(new Runnable() { @Override public void run() { try {
And here is my adapter
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; } }
I know that the code will not help, but I just send it to the suggestion of some people.
Thanks.