I program an app android to view youtube . I have a problem with android studio. I was copy YouTubeAndroidPlayerApi.jar to folder libs and code in java is fine , but in the xml is has error
Rendering Problems The following classes could not be found com.google.android.youtube.player.YouTubePlayerView (Fix Build Path, Create Class)
Tip: Try to build the project.
I was try to build project but it have the same error. Here is the code
<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" android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin" tools:context=".MainActivity">
<com.google.android.youtube.player.YouTubePlayerView
android:id="#+id/youtube_player"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#fff"
android:padding="5dp" />
Please help :D Tks all
I would recomend you adding the fragment programatically in your code like this:
YouTubePlayerSupportFragment videoStreamingPlayerFragment = YouTubePlayerSupportFragment.newInstance();
videoStreamingPlayerFragment.initialize(mDevKey, new PlayerInitializedListener());
FragmentTransaction ft = getChildFragmentManager().beginTransaction();
ft.replace(R.id.Container, videoStreamingPlayerFragment);
ft.commitAllowingStateLoss();
in case you want to use the View instead of the fragment you could add it with the function addView:
YouTubePlayerView youtubeView = new YouTubePlayerView(this);
youtubeView.initialize(mDevKey, new PlayerInitializedListener());
FrameLayout youtubeContainer = (FrameLayout) findViewById(R.id.YoutubeContainer);
youtubeContainer.addView(mYoutubeView);
The activity where you do the operation must extend YouTubeBaseActivity
Related
I want to add two fragments when the device is tablet(landscape). But i get the next Error:
java.lang.IllegalArgumentException: No view found for id 0x7f0d006d (com.example.placesearch1:id/container2) for fragment FragMap
I created two layouts : main_activity(for phone):
<FrameLayout
android:id="#+id/container1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerHorizontal="true">
</FrameLayout>
and main_activity (for tablet landscape - activity_main.xml(sw600dp-land) :
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
>
<FrameLayout
android:id="#+id/container1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1">
</FrameLayout>
<FrameLayout
android:id="#+id/container2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1">
</FrameLayout>
</LinearLayout>
I have RecycleView of places(main_activity layout in container1). When i click the item, i get an latitude and longitude of a place and pass the values with bundle to Map fragment and put the map into one of the containers : if device is phone then in container1, but if device is tablet then in container2.
If the device is phone it works perfectly, but if the device is tablet, then i get an error.
in GetPlace method :
Bundle bundle = new Bundle();
bundle.putDouble("lat", place.getLat());
bundle.putDouble("lng", place.getLng());
FragMap fragMap = new FragMap();
fragMap.setArguments(bundle);
if(getResources().getBoolean(R.bool.isTab)) {
getSupportFragmentManager().beginTransaction()
.replace(R.id.container1, new ListFragment())
.replace(R.id.container2, fragMap)
.addToBackStack(null)
.commit();
}
else {
getSupportFragmentManager().beginTransaction()
.replace(R.id.container1, fragMap)
.addToBackStack(null)
.commit();
}
usually when you are designing the xml for phone or tablet the file should be same and also in both xml the content should be same. But here in your case for phone there is only one framelayout but for tablet why two framelayout
Remove this line from GetPlace method
.replace(R.id.container1, new ListFragment())
It's the first time I'm working on an android wear application. I have implemented a list of items and is all right. Now I would like to show to the user an extra information when the users click in one item in a kind of card like in the image.
My click is working ok:
#Override
public void onClick(WearableListView.ViewHolder viewHolder) {
//Toast.makeText(this, "working", Toast.LENGTH_SHORT).show();
}
But I have no idea how to popup a card when the user click in an item. Any idea?
Thanks!
EDITED:
I have added in my activity_main.xml the code below:
<?xml version="1.0" encoding="utf-8"?>
<android.support.wearable.view.WatchViewStub
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/watch_view_stub"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:rectLayout="#layout/rect_activity_main"
app:roundLayout="#layout/round_activity_main"
tools:context=".MainActivity"
tools:deviceIds="wear">
<android.support.wearable.view.BoxInsetLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_height="match_parent"
android:layout_width="match_parent">
<FrameLayout
android:id="#+id/frame_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_box="bottom">
</FrameLayout>
</android.support.wearable.view.BoxInsetLayout>
</android.support.wearable.view.WatchViewStub>
Then after fill the list I want to allow to the user to click on any item and show the card, so I have added the code below:
#Override
public void onClick(WearableListView.ViewHolder viewHolder) {
FragmentManager fragmentManager = getFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
CardFragment cardFragment = CardFragment.create("title",
"description");
fragmentTransaction.add(R.id.frame_layout, cardFragment);
fragmentTransaction.commit();
}
and I'm getting an error:
No view found for id 0x7f0e0014 (wk.gon250.myApp/frame_layout) for fragment CardFragment{207c1da5 #0 id=0x7f0e0014}
The error make sense but I don't know how to fix the error.
The images you have, are showing Cards and there is code snippets here that shows you how to build a card in your app; it is basically a CardFragment and if you are familiar with building a fragment, it shouldn't come as anything strange for you.
FIXED
I outsourced the Bluetooth scanning to a separate thread which was a failure. :D Having fixed this the code now works. Thanks for all support!
ORIGINAL QUESTION
I'm having troubles with exchanging dynamically added fragments (I use the support library and my minimal API version is 8 (Android 2.2)). In my XML which can be seen below file I have a FrameLayout which contains the fragment.
<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" android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
tools:context=".BluetoothConnectionManager">
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/frmlFragmentContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"/>
<android.support.v7.widget.Toolbar
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/tbBottom"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize"
android:background="#color/hafnertec"
android:layout_alignParentBottom="true">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView android:id="#+id/lblMode"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/lblMode"
android:layout_centerInParent="true"/>
<ImageButton android:id="#+id/btnRefresh"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_action_refresh"
android:layout_alignParentRight="true"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_alignRight="#id/lblMode"
android:clickable="false"
android:longClickable="false"
android:onClick="updateData"/>
</RelativeLayout>
</android.support.v7.widget.Toolbar>
</RelativeLayout>
For exchanging the fragments i use a SupportFragmentManager. Furthermore, I also instantiate the two fragments in the onCreate() method. In addition, the fragment for discovering Bluetooth devices is added to the frame layout which works fine.
#Override
protected void onCreate(Bundle savedInstanceState)
{
...
// fetch a FragmentManager used for exchanging the fragments
this.fmFragmentExchanger = this.getSupportFragmentManager();
this.btDiscoveryFragment = new BluetoothDiscoveryFragment();
this.btConnectorFragment = new BluetoothConnectorFragment();
if (this.findViewById(R.id.frmlFragmentContainer) != null)
{
this.fmFragmentExchanger.beginTransaction().add(R.id.frmlFragmentContainer, this.btDiscoveryFragment).disallowAddToBackStack().commit();
}
...
}
Moreover, I've taken care that the fragments extend the Fragment class provided by the support library:
import android.support.v4.app.Fragment;
public class BluetoothDiscoveryFragment extends Fragment implements ...
{
// see: https://developer.android.com/training/basics/fragments/creating.html
#Override
public View onCreateView(LayoutInflater inflater, #Nullable ViewGroup container, Nullable Bundle savedInstanceState)
{
return inflater.inflate(R.layout.fragment_connection_bluetooth_device, container, false);
}
Here is my code for exchanging the fragments:
this.fmFragmentExchanger.beginTransaction().replace(R.id.frmlFragmentContainer, this.btConnectorFragment).disallowAddToBackStack().commit();
The class for discovering Bluetooth devices makes use of a BroadcastReceiver which is "connected" with the activity. On stopping the discovery process or when it has finished I unregister this BroadcastReceiver.
However, on exchanging the fragments nothing happens and after some time I get an error caused by SIGABRT:
12-31 15:09:51.621 9790-9795/com.hafnertec.afdbluetooth I/dalvikvm﹕ Wrote stack traces to '/data/anr/traces.txt'
12-31 15:09:53.945 9790-9790/com.hafnertec.afdbluetooth A/libc﹕ Fatal signal 6 (SIGABRT) at 0x000001bd (code=0), thread 9790 (ec.afdbluetooth)
Here you can see the file /data/anr/traces.txt: trace file
I'm running the tests on a Samsung Galaxy S I9000 with Android 4.4.4 (CM SNAPSHOT M12). During the activity's onCreate() method I add the btDiscoveryFragment instance which works fine:
this.fmFragmentExchanger.beginTransaction().add(R.id.frmlFragmentContainer, this.btDiscoveryFragment).disallowAddToBackStack().commit();
Furthermore, adding the instance btConnectorFragment using .add() works. However, it logically causes the btConnectorFragment to be overlayed over the btDiscoveryFragment.
I think you have a typo, causing btDiscoveryFragment to be null:
this.fmFragmentExchanger = this.getSupportFragmentManager();
//add this line
this.btDiscoveryFragment = new BluetoothDiscoveryFragment();
//remove this duplicated line
//this.btConnectorFragment = new BluetoothConnectorFragment();
this.btConnectorFragment = new BluetoothConnectorFragment();
I've seen similar questions but they couldnt solve my problem. I've installed Google Play SDKs, imported as a library to my app. Following Admob instructions, I've written that code below:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/relative"
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.oguz.nfcdatareaderwriter.MainPage$PlaceholderFragment" >
<Button
android:id="#+id/writeNFC"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/openingMessage"
android:layout_centerHorizontal="true"
android:layout_marginTop="116dp"
android:text="Write Custom Data to a Card" />
<TextView
android:id="#+id/openingMessage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="174dp"
android:text=".."
android:textAppearance="?android:attr/textAppearanceLarge" />
</RelativeLayout>
Main Activity:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.fragment_main_page);
// Create an ad.
adView = new AdView(this);
adView.setAdSize(AdSize.BANNER);
adView.setAdUnitId(AD_UNIT_ID);
// Add the AdView to the view hierarchy. The view will have no size
// until the ad is loaded.
RelativeLayout layout = (RelativeLayout) findViewById(R.id.relative);
layout.addView(adView);
// Create an ad request. Check logcat output for the hashed device ID to
// get test ads on a physical device.
AdRequest adRequest = new AdRequest.Builder()
.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
.addTestDevice("4df1dccd39006f0f")
.build();
// Start loading the ad in the background.
adView.loadAd(adRequest);
}
If you are getting NoClassDefFoundError then you have not properly included the GooglePlayServices library, or you have managed to exclude the classes using Proguard or similar. Try redoing the steps.
For me it was quite difficult to use AdMob with Eclipse LUNA and the last SDK and ADT.
What I've found it's that you must order your Java Build Path (Right Click then properties) as folow :
Android Dependecies checked, Android xxx Unchecked, Android Private Librairies Checked
And control that in your libs folder the google-play-services.jar is inside !
setContentView() is giving error in below is my code :
public class LocateUserInMap extends FragmentActivity {
private GoogleMap mMap;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_locate_user_in_map);
mMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
mMap.setMapType(GoogleMap.MAP_TYPE_SATELLITE);
final LatLng CIU = new LatLng(19.111693900000000000,72.911271500000000000);
mMap.addMarker(new MarkerOptions().position(CIU).title("Friend"));
// findDirections(19.111693900000000000,72.911271500000000000,19.128203900000000000,72.928065000000060000, GMapV2Direction.MODE_DRIVING);
}
}
error :
here is my library that I am using :
and activity_locate_user_in_map.xml
<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"
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=".LocateUserInMap" >
<fragment
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.MapFragment" />
</RelativeLayout>
what I am missing...
Please help!!!
Regards,
Sourabh
Your layout file R.layout.activity_locate_user_in_map is missing, maybe it is on another project or it is in correct project but somehow it can't be resolved, try to clean the project
The #SuppressLint("NewApi") really shouldnt be needed for onCreate() so I am going to guess that you have set your project to the something like:
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
And then are trying to use Fragments without using the support library.
You will need to change the imports to something like:
import android.support.v4.app.FragmentActivity;
And change any calls to:
getFragmentManager()
to
getSupportFragmentManager()
You might also like to checkout this question for a good background on Fragment, FragmentActivity and the support lib