If there is no event like list.onLoadListener(list is done with its data filling) how to access list's first row?
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).
After setting adapter to list
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.
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).
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
}
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();
}
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 code will not help much but I am just posting it on some people's suggestion.
Thanks.