Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to implement Video and video list using two Fragments
    text
    copied!<p>I am creating an application for <code>HonyComb</code> in which I have to display videos and video list. For this I have created two fragments,one for displaying video and other for videoList.When user clicks on video list then that video should start playing in <code>videoview</code> in other fragment.</p> <p>I have created custom <code>expandablelist</code> for displaying videoList(AS my videos are categorized into group). I have to display video image, title and description for which I have created a layout with an <code>imageview</code> and two <code>textview</code>.I am able to display the video list. Now I am stuck at two points:</p> <ol> <li>I am not able to play the video when I click on the video list. <code>onChildCLick()</code> is not getting invoked but <code>onTouch()</code> and <code>onGroupClick()</code> are able to get invoked.</li> <li>I want to play the video in full screen when user taps on the <code>VideoView</code>. I don't know how to implement that.</li> </ol> <p>Please help me..</p> <ol> <li><p>fragment_layout.xml</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal" &gt; &lt;fragment android:id="@+id/detailFragment" android:layout_width="0dip" android:layout_height="match_parent" android:layout_weight="1" class="com.abs.qpr.VideoFragment" &gt; &lt;/fragment&gt; &lt;fragment android:id="@+id/listFragment" android:layout_width="0dip" android:layout_height="match_parent" android:layout_weight="0.6" class="com.abs.qpr.VideoListFragment" &gt; &lt;/fragment&gt; &lt;/LinearLayout&gt; </code></pre></li> <li><p>MyActivity .java</p> <pre><code> import android.os.Bundle; public class MyActivity extends android.support.v4.app.FragmentActivity{ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.fragment_layout); } } </code></pre></li> <li><p>VideoFragment.java</p> <pre><code>import android.net.Uri; import android.os.Bundle; import android.support.v4.app.Fragment; public class VideoFragment extends Fragment{ @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { Log.d("VideoFragment", "On Create View"); View view = inflater.inflate(R.layout.activity_my_video, container, false); return view; } @Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); } public void playVideo() { VideoView myVideoView2= (VideoView)getView().findViewById(R.id.my_tecnique_video); String temp="android.resource://" + getActivity().getApplicationContext().getPackageName() + "/" + R.raw.back_circles; System.out.println(temp + ": " + getActivity().getApplicationContext()); Uri video = Uri.parse("android.resource://" + getActivity().getApplicationContext().getPackageName() + "/" + R.raw.back_circles); myVideoView2.setVideoURI(video); myVideoView2.setMediaController(new MediaController(getActivity())); myVideoView2.requestFocus(); myVideoView2.start(); } } </code></pre></li> <li><p>VideoListFragment.java</p> <pre><code>public class VideoListFragment extends Fragment { @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { Log.e("VideoFragment", "On Create View"); View view = inflater.inflate( R.layout.activity_my_techniques_video_list, container, false); return view; } @Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); Log.e("VideoListFragment", "On Activity Created "); ExpandableListView expList = (ExpandableListView) getView() .findViewById(R.id.my_tech_video_listview); expList.setAdapter(new VideoExpandableListAdapter(getActivity())); expList.setOnChildClickListener(new OnChildClickListener() { @Override public boolean onChildClick(ExpandableListView expandablelistview, View view, int i, int j, long l) { // TODO Auto-generated method stub Log.d("Checking.....", "onGroupClick()"); VideoFragment fragment = (VideoFragment) getFragmentManager() .findFragmentById(R.id.detailFragment); if (fragment != null &amp;&amp; fragment.isInLayout()) { fragment.playVideo(); } else { Intent videointent = new Intent(getActivity() .getApplicationContext(), VideoActivity.class); startActivity(videointent); } return false; } }); } </code></pre></li> <li><p>VideoExpandableListAdapter.java</p> <pre><code>public class VideoExpandableListAdapter extends BaseExpandableListAdapter{ private Context myContext; ArrayList&lt;VideoListVO&gt; videoListVO; public VideoExpandableListAdapter(Context context) { myContext = context; } @Override public Object getChild(int groupPosition, int childPosition) { // TODO Auto-generated method stub return null; } @Override public long getChildId(int groupPosition, int childPosition) { // TODO Auto-generated method stub return 0; } @Override public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) { if (convertView == null) { LayoutInflater inflater = (LayoutInflater) myContext .getSystemService(Context.LAYOUT_INFLATER_SERVICE); convertView = inflater.inflate(R.layout.childrow, null); } VideoListVO vlvo= videoListVO.get(groupPosition); VideoDetailsVO vdvo=vlvo.getVideoDetailList().get(childPosition); InputStream is = null; try { String imageName=vdvo.getImageName(); imageName="images/"+imageName+".png"; is = myContext.getResources().getAssets().open(imageName); } catch (IOException e) { Log.w("EL", e); } Bitmap image = BitmapFactory.decodeStream(is); ImageView ib2 = (ImageView) convertView.findViewById( R.id.video_image); ib2.setImageBitmap(image); TextView titleText=(TextView)convertView.findViewById(R.id.video_title_text); titleText.setText(vdvo.getVideoTitle()); TextView descriptionText=(TextView)convertView.findViewById(R.id.video_description); descriptionText.setText(vdvo.getVideoDescription()); return convertView; } @Override public int getChildrenCount(int groupPosition) { // TODO Auto-generated method stub return videoListVO.get(groupPosition).getVideoDetailList().size(); } @Override public Object getGroup(int groupPosition) { // TODO Auto-generated method stub return null; } @Override public int getGroupCount() { // TODO Auto-generated method stub return videoListVO.size(); } @Override public long getGroupId(int groupPosition) { // TODO Auto-generated method stub return 0; } @Override public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) { if (convertView == null) { LayoutInflater inflater = (LayoutInflater) myContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); convertView = inflater.inflate(R.layout.group_row, null); } TextView tvGroupName = (TextView) convertView.findViewById(R.id.tvgrpname); tvGroupName.setText(videoListVO.get(groupPosition).getVideoType()); return convertView; } @Override public boolean hasStableIds() { // TODO Auto-generated method stub return false; } @Override public boolean isChildSelectable(int groupPosition, int childPosition) { // TODO Auto-generated method stub return true; } } </code></pre></li> </ol>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload