how play video on listview where on is focuses



I write application for android but have some problems



package com.example.test5.timeline;

import java.util.ArrayList;

import android.content.Context;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.VideoView;

import com.example.test5.R;
import com.example.test5.testmsgActivity;

public class TimelineAdapter extends BaseAdapter {
private VideoView vv;
private TextView comment;
private LinearLayout video_layout, user_field, video_name_field,
users_info_field;
private int screen_w = 0, screen_h = 0;
private ImageView user_profile_image, google_plus;

Context ctx;
LayoutInflater lInflater;
ArrayList<SimplePost> posts;

TimelineAdapter(Context context, ArrayList<SimplePost> post) {
ctx = context;
posts = post;
lInflater = (LayoutInflater) ctx
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}

// кол-во элементов
@Override
public int getCount() {
return posts.size();
}

// элемент по позиции
@Override
public Object getItem(int position) {
return posts.get(position);
}

// id по позиции
@Override
public long getItemId(int position) {
return position;
}

// пункт списка
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// используем созданные, но не используемые view
View view = convertView;
if (view == null) {
view = lInflater
.inflate(R.layout.simple_post_layout, parent, false);
}

SimplePost p = getProduct(position);

screen_w = 1080;
screen_h = 1920;

comment = (TextView) view.findViewById(R.id.video_coment_count);

vv = (VideoView) view.findViewById(R.id.user_video);
vv.setVideoPath("http://server_ip/uploads/CAM00262.mp4");
vv.getLayoutParams().height = screen_w;
vv.getLayoutParams().width = screen_w;

video_layout = (LinearLayout) view.findViewById(R.id.video_layout);
video_layout.getLayoutParams().height = screen_w;
video_layout.getLayoutParams().width = screen_w;

user_field = (LinearLayout) view.findViewById(R.id.user_field);

video_name_field = (LinearLayout) view
.findViewById(R.id.video_name_field);

users_info_field = (LinearLayout) view
.findViewById(R.id.users_info_field);

google_plus = (ImageView) view.findViewById(R.id.video_plus_share);

user_profile_image = (ImageView) view
.findViewById(R.id.user_profile_image);

video_layout.getLayoutParams().height = vv.getLayoutParams().height;
video_layout.getLayoutParams().width = vv.getLayoutParams().height;

comment.setOnClickListener(
new View.OnClickListener()
{
@Override
public void onClick(View view)
{
vv.start();
}
}
);
return view;
}

public DisplayMetrics getScreenSize() {
testmsgActivity ttt = new testmsgActivity();
return ttt.getScreenSize();
}

SimplePost getProduct(int position) {
return ((SimplePost) getItem(position));
}

}


user_timeline_layout.xml



<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://ift.tt/nIICcg"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<TabHost
android:id="@android:id/tabhost"
android:layout_width="match_parent"
android:layout_height="wrap_content" >

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<TabWidget
android:id="@android:id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</TabWidget>

<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="match_parent" >

<LinearLayout
android:id="@+id/tab1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<ListView
android:id="@+id/TimelinelistView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1" >
</ListView>
</LinearLayout>

<LinearLayout
android:id="@+id/tab2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
</LinearLayout>

<LinearLayout
android:id="@+id/tab3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
</LinearLayout>
</FrameLayout>
</LinearLayout>
</TabHost>

</LinearLayout>


simple_post.xml



<LinearLayout xmlns:android="http://ift.tt/nIICcg"
android:id="@+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >


<LinearLayout
android:id="@+id/user_field"
android:layout_width="match_parent"
android:layout_height="50px"
android:orientation="horizontal" >

<ImageView
android:id="@+id/user_profile_image"
android:layout_width="50px"
android:layout_height="50px"
android:layout_marginLeft="10dp"
android:layout_marginTop="2px"
android:background="@drawable/photo" />

<TextView
android:id="@+id/user_profile_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:text="Vahagn Vardanyan" >
</TextView>
</LinearLayout>

<LinearLayout
android:id="@+id/video_name_field"
android:layout_width="match_parent"
android:layout_height="60px"
android:orientation="horizontal" >

<TextView
android:id="@+id/video_name"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="10dp"
android:layout_marginTop="2dp"
android:text="my first text video #first" >
</TextView>
</LinearLayout>

<LinearLayout
android:id="@+id/video_layout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#000000"
android:gravity="center" >

<VideoView
android:id="@+id/user_video"
android:layout_width="wrap_content"
android:layout_height="150px"
android:gravity="center" />
</LinearLayout>

<LinearLayout
android:id="@+id/users_info_field"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >

<TextView
android:id="@+id/video_view_count"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="view" />

<TextView
android:id="@+id/video_like_count"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="like" >
</TextView>

<TextView
android:id="@+id/video_coment_count"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:onClick="play_video"
android:text="comment" >
</TextView>

<ImageView
android:id="@+id/video_plus_share"
android:layout_width="match_parent"
android:layout_height="30px"
android:layout_weight="1"
android:src="@drawable/plus" />
</LinearLayout>

</LinearLayout>


where I insert post array on VistView (user_timeline_layout.xml) after press comment textview for play video, in this moment played all video . please help, how I can play video in x position or where in is focuses.


No comments:

Post a Comment