Click here to Skip to main content
15,899,475 members
Home / Discussions / Android
   

Android

 
QuestionWhat is the difference between creating instance like this? Pin
Member 1226347721-Jan-16 22:07
Member 1226347721-Jan-16 22:07 
AnswerRe: What is the difference between creating instance like this? Pin
Richard MacCutchan21-Jan-16 22:43
mveRichard MacCutchan21-Jan-16 22:43 
QuestionPull to Refresh in List view Android Pin
Tirumaleswara Reddy.K21-Jan-16 20:06
Tirumaleswara Reddy.K21-Jan-16 20:06 
QuestionRe: Pull to Refresh in List view Android Pin
David Crow22-Jan-16 2:41
David Crow22-Jan-16 2:41 
QuestionDoubts with HTTP request and responses in android Pin
Member 1226347721-Jan-16 19:02
Member 1226347721-Jan-16 19:02 
AnswerRe: Doubts with HTTP request and responses in android Pin
Richard MacCutchan21-Jan-16 22:40
mveRichard MacCutchan21-Jan-16 22:40 
GeneralRe: Doubts with HTTP request and responses in android Pin
Member 1226347721-Jan-16 22:46
Member 1226347721-Jan-16 22:46 
QuestionHow to add youtube thumbnail in list item ? Pin
Member 1226347713-Jan-16 22:04
Member 1226347713-Jan-16 22:04 
Hello,I'm new to here.. I've created a simple app using YouTube API it contains a collections of list item if any one touch the list item then it'll redirect you into youtube for particular video.Now the thing is I want to add youtube thumbnail with list item of list view. Is there any way to add image there ? Please any one shed some light on this question ?

Activity Main xml

XML
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.example.vinothvino.shortfilmy.MainActivity">

    <ListView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/listView"
        android:layout_gravity="center_vertical"
        android:layout_weight="1" />

    <com.google.android.youtube.player.YouTubeThumbnailView
        android:id="@+id/youtube_thumbnail"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:padding="5dp">
    </com.google.android.youtube.player.YouTubeThumbnailView>

</LinearLayout>


YouTubeView xml
XML
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".YouTubeView">

    <com.google.android.youtube.player.YouTubeThumbnailView
        android:id="@+id/youtube_thumbnail"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:padding="5dp">
    </com.google.android.youtube.player.YouTubeThumbnailView>


    <com.google.android.youtube.player.YouTubePlayerView
        android:id="@+id/youtube_view"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>

</RelativeLayout>


ListView

XML
<?xml version="1.0" encoding="utf-8"?>

    <TextView xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/listviewadapter"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:padding="25dip"
        android:textSize="16dip"
        android:textStyle="bold" >
   </TextView>


MainActivity
Java
package com.example.vinothvino.shortfilmy;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.view.View;
import android.widget.Toast;


public class MainActivity extends Activity {


    //WebView webView;
    ListView listView;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        String[] shortFilms = {"Mudhal Kanave","A Cute Love story","Ennai Saaithaale","Friend ah Figure ah",
                "Perfect You","Aparam","Yaaro Ivan","Honey Money Romantic Thriller"};

        listView = (ListView) findViewById(R.id.listView);
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,R.layout.list_view,shortFilms);


        listView.setAdapter(adapter);

       // webView = (WebView)findViewById(R.id.webView);
       // webView.setWebViewClient(new MyWebView());
       // webView.getSettings().setLoadsImagesAutomatically(true);
       // webView.getSettings().setJavaScriptEnabled(true);


        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

                int itemPos = position;

                String itemVal = (String)listView.getItemAtPosition(itemPos);

                switch (itemPos){

                    case 0:


                        Intent i = new Intent(getApplicationContext(),YouTubeView.class);
                        i.putExtra("value1","rk7NYXql2dc");
                        startActivity(i);

                        Toast.makeText(getApplicationContext(),itemVal,Toast.LENGTH_SHORT).show();
                        break;
                    case 1:

                        Intent i1 = new Intent(getApplicationContext(),YouTubeView.class);
                        i1.putExtra("value1", "j1lc8p8NFNw");
                        startActivity(i1);

                        Toast.makeText(getApplicationContext(),itemVal,Toast.LENGTH_SHORT).show();
                        break;
                    case 2:

                        Intent i2 = new Intent(getApplicationContext(),YouTubeView.class);
                        i2.putExtra("value1","8au0FflDO-I");
                        startActivity(i2);

                        Toast.makeText(getApplicationContext(),itemVal,Toast.LENGTH_SHORT).show();
                        break;

                    case 3:

                        Intent i3 = new Intent(getApplicationContext(),YouTubeView.class);
                        i3.putExtra("value1","9daIXm6lSTc");
                        startActivity(i3);

                        Toast.makeText(getApplicationContext(),itemVal,Toast.LENGTH_SHORT).show();
                        break;

                    case 4:

                        Intent i4 = new Intent(getApplicationContext(),YouTubeView.class);
                        i4.putExtra("value1","s3s838owcOY");
                        startActivity(i4);

                        Toast.makeText(getApplicationContext(),itemVal,Toast.LENGTH_SHORT).show();
                        break;

                    case 5:

                        Intent i5 = new Intent(getApplicationContext(),YouTubeView.class);
                        i5.putExtra("value1","RIMsCCMy80E");
                        startActivity(i5);

                        Toast.makeText(getApplicationContext(),itemVal,Toast.LENGTH_SHORT).show();
                        break;

                    case 6:

                        Intent i6 = new Intent(getApplicationContext(),YouTubeView.class);
                        i6.putExtra("value1","LE5M3YYe_cE");
                        startActivity(i6);

                        Toast.makeText(getApplicationContext(),itemVal,Toast.LENGTH_SHORT).show();
                        break;

                    case 7:

                        Intent i7 = new Intent(getApplicationContext(),YouTubeView.class);
                        i7.putExtra("value1","yjpQ4qVd7Os");
                        startActivity(i7);

                        Toast.makeText(getApplicationContext(),itemVal,Toast.LENGTH_SHORT).show();
                        break;

                    default:
                        Toast.makeText(getApplicationContext(),"Sorry!!! There is no video",Toast.LENGTH_SHORT).show();

                }


            }
        });

    }

}


YouTubeView
Java
package com.example.vinothvino.shortfilmy;

/**
 * Created by vinothvino on 13/01/16.
 */

import android.os.Bundle;
import android.content.Intent;
import android.widget.Toast;

import com.google.android.youtube.player.YouTubeInitializationResult;
import com.google.android.youtube.player.YouTubePlayer;
import com.google.android.youtube.player.YouTubePlayerView;
import com.google.android.youtube.player.YouTubeBaseActivity;
import com.google.android.youtube.player.YouTubePlayer.Provider;
import com.google.android.youtube.player.YouTubePlayer.PlaybackEventListener;
import com.google.android.youtube.player.YouTubePlayer.PlayerStateChangeListener;
import com.google.android.youtube.player.YouTubeThumbnailLoader;
import com.google.android.youtube.player.YouTubeThumbnailView;
import com.google.android.youtube.player.YouTubeThumbnailLoader.ErrorReason;

public class YouTubeView extends YouTubeBaseActivity implements YouTubePlayer.OnInitializedListener{   //,YouTubeThumbnailView.OnInitializedListener

    public static final int RECOVER_REQUEST = 1;
    private YouTubePlayerView youTubeView;
    private YouTubeThumbnailView youTubeThumbnailView;
    private YouTubeThumbnailLoader youTubeThumbnailLoader;




    protected void onCreate(Bundle savedInstanceState){
         super.onCreate(savedInstanceState);
         setContentView(R.layout.youtube_view);


         youTubeView = (YouTubePlayerView)findViewById(R.id.youtube_view);
         youTubeView.initialize(Config.API_KEY,this);


        //youTubeThumbnailView = (YouTubeThumbnailView)findViewById(R.id.youtube_thumbnail);
       // youTubeThumbnailView.initialize(Config.API_KEY,this);

     }


    public void onInitializationSuccess(Provider provider,YouTubePlayer player,boolean wasRestored) {

        //Creating bundle and store video id
        Bundle videoIdFromMainActiviy = getIntent().getExtras();
        String videoID = videoIdFromMainActiviy.getString("value1");

        player.setPlaybackEventListener(myPlaybackEvent);
        player.setPlayerStateChangeListener(myPlayerState);

        if (!wasRestored) {
            player.cueVideo(videoID);
        }
    }

        private PlaybackEventListener myPlaybackEvent = new PlaybackEventListener() {
            @Override
            public void onPlaying() {

                Toast.makeText(getApplicationContext(),"Playing...",Toast.LENGTH_SHORT).show();
            }

            @Override
            public void onPaused() {

                Toast.makeText(getApplicationContext(),"Paused...",Toast.LENGTH_SHORT).show();
            }

            @Override
            public void onStopped() {

                Toast.makeText(getApplicationContext(),"Stopped...",Toast.LENGTH_SHORT).show();
            }

            @Override
            public void onBuffering(boolean b) {

            }

            @Override
            public void onSeekTo(int i) {

            }
        };

        private PlayerStateChangeListener myPlayerState = new PlayerStateChangeListener() {
            @Override
            public void onLoading() {

                Toast.makeText(getApplicationContext(),"Please be patient... ",Toast.LENGTH_SHORT).show();
            }

            @Override
            public void onLoaded(String s) {

            }

            @Override
            public void onAdStarted() {

                Toast.makeText(getApplicationContext(),"Ayyayooo Add vandhuteyyy",Toast.LENGTH_LONG).show();
            }

            @Override
            public void onVideoStarted() {

                Toast.makeText(getApplicationContext(),"Video started",Toast.LENGTH_LONG).show();
            }

            @Override
            public void onVideoEnded() {

                Toast.makeText(getApplicationContext(),"See some other videos",Toast.LENGTH_LONG).show();
            }

            @Override
            public void onError(YouTubePlayer.ErrorReason errorReason) {

            }
        };


    public void onInitializationFailure(Provider provider,YouTubeInitializationResult errorReason){

        if (errorReason.isUserRecoverableError()){

            errorReason.getErrorDialog(this,RECOVER_REQUEST).show();

        }else {

            String error = String.format(getString(R.string.error), errorReason.toString());
            Toast.makeText(this,error,Toast.LENGTH_LONG).show();

        }
    }

    protected void onActivityResult(int requestcode, int resultcode, Intent data){

        if (requestcode==RECOVER_REQUEST){

            getYoutubePlayerProvider().initialize(Config.API_KEY,this);
        }

    }

    protected Provider getYoutubePlayerProvider(){

        return youTubeView;

    }
}


Please help me.. Thanks in advanced
SuggestionRe: How to add youtube thumbnail in list item ? Pin
Richard MacCutchan14-Jan-16 2:52
mveRichard MacCutchan14-Jan-16 2:52 
GeneralRe: How to add youtube thumbnail in list item ? Pin
Member 1226347714-Jan-16 4:43
Member 1226347714-Jan-16 4:43 
GeneralRe: How to add youtube thumbnail in list item ? Pin
Richard MacCutchan14-Jan-16 5:13
mveRichard MacCutchan14-Jan-16 5:13 
GeneralRe: How to add youtube thumbnail in list item ? Pin
Member 1226347714-Jan-16 5:16
Member 1226347714-Jan-16 5:16 
GeneralRe: How to add youtube thumbnail in list item ? Pin
Member 1226347714-Jan-16 5:18
Member 1226347714-Jan-16 5:18 
GeneralRe: How to add youtube thumbnail in list item ? Pin
Richard MacCutchan14-Jan-16 5:26
mveRichard MacCutchan14-Jan-16 5:26 
QuestionRe: How to add youtube thumbnail in list item ? Pin
David Crow14-Jan-16 6:00
David Crow14-Jan-16 6:00 
AnswerRe: How to add youtube thumbnail in list item ? Pin
Member 1226347721-Jan-16 18:58
Member 1226347721-Jan-16 18:58 
QuestionHow can I get data from WAZE? Pin
Member 1147089810-Jan-16 5:31
Member 1147089810-Jan-16 5:31 
QuestionRe: How can I get data from WAZE? Pin
David Crow10-Jan-16 15:50
David Crow10-Jan-16 15:50 
QuestionStop refreshing List Item-view in ListView in Android Pin
Tirumaleswara Reddy.K4-Jan-16 22:44
Tirumaleswara Reddy.K4-Jan-16 22:44 
AnswerRe: Stop refreshing List Item-view in ListView in Android Pin
Afzaal Ahmad Zeeshan4-Jan-16 23:14
professionalAfzaal Ahmad Zeeshan4-Jan-16 23:14 
GeneralRe: Stop refreshing List Item-view in ListView in Android Pin
Tirumaleswara Reddy.K5-Jan-16 18:31
Tirumaleswara Reddy.K5-Jan-16 18:31 
GeneralRe: Stop refreshing List Item-view in ListView in Android Pin
Tirumaleswara Reddy.K5-Jan-16 22:28
Tirumaleswara Reddy.K5-Jan-16 22:28 
QuestionRe: Stop refreshing List Item-view in ListView in Android Pin
David Crow5-Jan-16 2:17
David Crow5-Jan-16 2:17 
AnswerRe: Stop refreshing List Item-view in ListView in Android Pin
Tirumaleswara Reddy.K5-Jan-16 18:37
Tirumaleswara Reddy.K5-Jan-16 18:37 
GeneralRe: Stop refreshing List Item-view in ListView in Android Pin
Tirumaleswara Reddy.K5-Jan-16 22:31
Tirumaleswara Reddy.K5-Jan-16 22:31 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.