I have a crash when add DFP to my app android - android

I try add DFP Banner Ads to my app , All steps have been applied in https://developers.google.com/ad-manager/mobile-ads-sdk/android/banner .
but if I open my app it crash
crash:
java.lang.NullPointerException: Attempt to invoke virtual method 'void com.google.android.gms.ads.doubleclick.PublisherAdView.loadAd(com.google.android.gms.ads.doubleclick.PublisherAdRequest)' on a null object reference
at com.englishprofor.all.fragment.FragmentCategory.onCreateView(FragmentCategory.java:61)
FragmentCategory.class
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import com.englishprofor.all.AppController;
import com.englishprofor.all.Constant;
import com.englishprofor.all.R;
import com.englishprofor.all.activity.MainActivity;
import com.englishprofor.all.activity.SettingActivity;
import com.englishprofor.all.helper.CircleImageView;
import com.englishprofor.all.helper.SettingsPreferences;
import com.englishprofor.all.model.Category;
import com.englishprofor.all.model.SubCategory;
import com.google.android.gms.ads.doubleclick.PublisherAdRequest;
import com.google.android.gms.ads.doubleclick.PublisherAdView;
import com.google.android.gms.ads.doubleclick.*;
import java.util.ArrayList;
public class FragmentCategory extends Fragment {
private static final String TAG = "FragmentCategory";
Context con ;
private RecyclerView recyclerView;
private View view;
ArrayList<Category> mListItem;
//AdView mAdView;
private PublisherAdView mPublisherAdView;
TextView empty_msg, tvTitle;
CoordinatorLayout layout;
ImageView back, setting;
public static ArrayList<Category> categoryList;
public static ArrayList<SubCategory> subCatList;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
view = inflater.inflate(R.layout.fragment_category, container, false);
mPublisherAdView = view.findViewById(R.id.publisherAdView);
PublisherAdRequest adRequest = new PublisherAdRequest.Builder().build();
mPublisherAdView.loadAd(adRequest);
fragment_category.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:ads="http://schemas.android.com/tools"
android:id="#+id/layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/background">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<include layout="#layout/actionbar_layout"/>
<android.support.v7.widget.RecyclerView
android:id="#+id/category_recycleview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/relativeLayout"
android:layout_above="#+id/banner_AdView"/>
<TextView
android:id="#+id/txtblanklist"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:gravity="center"
android:textColor="#color/black"
android:textSize="15dp"
android:textStyle="bold"
android:visibility="gone" />
<com.google.android.gms.ads.doubleclick.PublisherAdView
android:id="#+id/banner_AdView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
ads:adSize="BANNER"
ads:adUnitId="/6499/example/banner">
</com.google.android.gms.ads.doubleclick.PublisherAdView>
</RelativeLayout>
</android.support.design.widget.CoordinatorLayout>
please help me , I want enable DFP in my app
thanks for all

You got a wrong id of view in below LOC, that why mPublisherAdView be NULL
mPublisherAdView = view.findViewById(R.id.publisherAdView);
should be
mPublisherAdView = view.findViewById(R.id.banner_AdView);

Related

Render error Unknown Fragment Android Studio

Hello I am wondering how to clear a render error I am having with a fragment which is saying unknown fragment. I can seem to find what I did wrong to fix it. I have a recycleview in the fragment that is just a test to make sure that is working as well right now.
Here is the Xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="jlfletcher.cpsc4367.ualr.edu.hw2.MainActivity">
<fragment
android:id="#+id/fragmentone"
android:name="layout.FragmentOne"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
Here is the Java of the fragment
package layout;
import android.app.Activity;
import android.content.Context;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import java.util.ArrayList;
import java.util.List;
import jlfletcher.cpsc4367.ualr.edu.hw2.CPSClist;
import jlfletcher.cpsc4367.ualr.edu.hw2.R;
public class FragmentOne extends Fragment
{
public void OnCreate(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
View View = inflater.inflate(R.layout.fragment_fragment_one, container, false);
RecyclerView recyclerView =
(RecyclerView)View.findViewById(R.id.Class_list);
recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
CPSClist textAdapter= new CPSClist();
recyclerView.setAdapter(textAdapter);
List<String> stringList = new ArrayList<>();
stringList.add("This");
stringList.add("is");
stringList.add("a");
stringList.add("of");
stringList.add("the");
stringList.add("recycle");
stringList.add("view");
stringList.add("system");
stringList.add("this");
stringList.add("is");
stringList.add("only");
stringList.add("a");
stringList.add("test.");
List<String> list = new ArrayList<>();
list.addAll(stringList);
list.addAll(stringList);
list.addAll(stringList);
list.addAll(stringList);
list.list(stringList);
list.addAll(stringList);
textAdapter.setItems(list);
}
}
Thanks again for the help on this.

Multiple Recyclerview

I want to create a chatapp. But in the recyclerview i only can receive the messages from the usermsg databasereference. I dont know how I should code it that i shows 2 recyclerviews. Does someone got an idea? Thanks
Chat Activity
package highelo.drivetogether;
import android.app.Activity;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.provider.ContactsContract;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.AttributeSet;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import com.firebase.ui.database.FirebaseRecyclerAdapter;
import com.google.firebase.database.ChildEventListener;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.ValueEventListener;
import com.squareup.picasso.Picasso;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
public class Chat extends AppCompatActivity {
RecyclerView mFriendMsg;
RecyclerView mUserMsg;
private Button SendMsg;
private EditText EditMsg;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_chat);
final Intent s = getIntent();
final String userID = s.getStringExtra("UID");
final Intent i = getIntent();
final String post_UserID = i.getStringExtra("FID");
SendMsg = (Button) findViewById(R.id.send_msg);
EditMsg = (EditText) findViewById(R.id.edit_msg);
mUserMsg = (RecyclerView) findViewById(R.id.chat_conr);
mUserMsg.setHasFixedSize(true);
mUserMsg.setLayoutManager(new LinearLayoutManager(this));
mFriendMsg = (RecyclerView) findViewById(R.id.chat_conr);
mFriendMsg.setHasFixedSize(true);
mFriendMsg.setLayoutManager(new LinearLayoutManager(this));
}
#Override
protected void onStart() {
super.onStart();
final Intent s = getIntent();
final String userID = s.getStringExtra("UID");
final Intent i = getIntent();
final String post_UserID = i.getStringExtra("FID");
DatabaseReference FriendMsg = FirebaseDatabase.getInstance().getReference().child("Users").child(userID).child("Chats").child(post_UserID).child("Chat");
DatabaseReference UserMsg = FirebaseDatabase.getInstance().getReference().child("Users").child(post_UserID).child("Chats").child(userID).child("Chat");
final FirebaseRecyclerAdapter<Blog, BlogViewHolder2> firebaseRecyclerAdapter2 = new FirebaseRecyclerAdapter<Blog, BlogViewHolder2>(
Blog.class,
R.layout.inchat_row2,
BlogViewHolder2.class,
UserMsg) {
#Override
protected void populateViewHolder(BlogViewHolder2 viewHolder, Blog model, int position) {
viewHolder.setNachricht(model.getNachricht());
viewHolder.setImage(Chat.this, model.getFImage());
}
};
mUserMsg.setAdapter(firebaseRecyclerAdapter2);
final FirebaseRecyclerAdapter<Blog, BlogViewHolder> firebaseRecyclerAdapter = new FirebaseRecyclerAdapter<Blog, BlogViewHolder>(
Blog.class,
R.layout.inchat_row,
BlogViewHolder.class,
FriendMsg) {
#Override
public void populateViewHolder(final BlogViewHolder viewHolder, Blog model, int position) {
viewHolder.setNachricht(model.getNachricht());
viewHolder.setImage(Chat.this, model.getFImage());
}
};
mFriendMsg.setAdapter(firebaseRecyclerAdapter);
}
public static class BlogViewHolder2 extends RecyclerView.ViewHolder{
View mView;
public BlogViewHolder2(View itemView) {
super(itemView);
mView = itemView;
}
public void setNachricht(String Nachricht){
TextView post_Nachricht = (TextView)mView.findViewById(R.id.finchat_mess);
post_Nachricht.setText(Nachricht);
}
public void setImage(Context ctx, String FImage){
ImageView post_image = (ImageView)mView.findViewById(R.id.finchat_image);
Picasso.with(ctx).load(FImage).fit().centerCrop().into(post_image);
}
}
public static class BlogViewHolder extends RecyclerView.ViewHolder{
View mView;
public BlogViewHolder(View itemView) {
super(itemView);
mView = itemView;
}
public void setNachricht(String Nachricht){
TextView post_Nachricht = (TextView)mView.findViewById(R.id.uinchat_mess);
post_Nachricht.setText(Nachricht);
}
public void setImage(Context ctx, String FImage){
ImageView post_image = (ImageView)mView.findViewById(R.id.uinchat_image);
Picasso.with(ctx).load(FImage).fit().centerCrop().into(post_image);
}
}
}
chat_activity
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="1">
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="492dp"
android:id="#+id/chat_conr"
android:layout_weight="1.11"
android:layout_alignParentTop="true"
android:layout_alignRight="#+id/send_msg"
android:layout_alignEnd="#+id/send_msg"
android:layout_above="#+id/edit_msg" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/edit_msg"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_toStartOf="#+id/send_msg"
android:layout_toLeftOf="#+id/send_msg" />
<Button
android:layout_width="80dp"
android:layout_height="wrap_content"
android:text="Senden"
android:id="#+id/send_msg"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
</RelativeLayout>
Inchat_row
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_margin="1dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<de.hdodenhof.circleimageview.CircleImageView
android:layout_width="54dp"
android:layout_height="54dp"
android:id="#+id/uinchat_image"
app:civ_border_width="1dp"
app:civ_border_color="#ff0000"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/uinchat_mess"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:paddingLeft="5dp"
android:textSize="13dp"
android:paddingBottom="4dp"
android:singleLine="true"
android:layout_alignParentTop="true"
android:layout_toEndOf="#+id/uinchat_image"
android:layout_alignBottom="#+id/uinchat_image" />
</RelativeLayout>
</android.support.v7.widget.CardView>
Inchat2_row
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_margin="1dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<de.hdodenhof.circleimageview.CircleImageView
android:layout_width="54dp"
android:layout_height="54dp"
android:id="#+id/finchat_image"
app:civ_border_width="1dp"
app:civ_border_color="#ff0000"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/finchat_mess"
android:layout_alignParentEnd="false"
android:paddingLeft="5dp"
android:textSize="13dp"
android:paddingBottom="4dp"
android:singleLine="true"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_toLeftOf="#+id/finchat_image"
android:layout_alignBottom="#+id/finchat_image" />
</RelativeLayout>
</android.support.v7.widget.CardView>
The usual way to have a chat between two people is to model that chat room in your database:
ChatRooms
ChatRoomBetweenUser1AndUser2
-KLM.......24
name: "User One"
uid: "uidOfUser1"
text: "Hello there. This is your friend User One"
-KMN.......35
name: "User Two"
uid: "uidOfUser2"
text: "Hello User One, this is User Two. Over"
That way you only need to load data from one location and need only one RecyclerView.
For more information on how to efficiently model chat rooms names for this scenario, see Best way to manage Chat channels in Firebase.
To get a good start on building a chat app, follow the Firebase Codelab for Android.
For a good introduction into modeling your data as your app needs it, see this article on NoSQL data modeling.

Unable to reference `fragment` using `R.id.myFirstFragment`

Here is the class of fragment
package com.hfad.chapter7;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
public class WorkoutDetailFragment extends Fragment {
private long workoutID;
public WorkoutDetailFragment() {
// Required empty public constructor
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_workout_detail, container, false);
}
public void setWorkoutID(long workoutID) {
this.workoutID = workoutID;
}
}
And the layout it's using is:
<FrameLayout 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="com.hfad.chapter7.WorkoutDetailFragment">
<!-- TODO: Update blank fragment layout -->
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="#string/hello_blank_fragment" />
</FrameLayout>
My MainActivity is:
package com.hfad.chapter7;
import android.app.Activity;
import android.app.Fragment;
import android.provider.UserDictionary;
import android.support.v4.app.FragmentActivity;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
WokoutDetailFragment workoutDetailFragment;
workoutDetailFragment = (WorkoutDetailFragment)this.getFragmentManager().findFragmentById(R.id.myFirstFragment);
}
}
And layout of MainActivity is:
<?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.hfad.chapter7.MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
/>
<fragment
class="com.hfad.chapter7.WorkoutDetailFragment"
android:id="#+id/myFirstFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</LinearLayout>
Problem is when I use this.getFragmentManager().findFragmentById(R.id.myFirstFragment) in onCreate of AppCompatActivity I get Fragment though I should get WorkoutDetailFragment as stated here in a similar example.
UPDATE:
Also I am unable to cast Fragment to WorkDetailFragment
#user4913383,
Change this line:
workoutDetailFragment = (WorkoutDetailFragment)this.getFragmentManager().findFragmentById(R.id.myFirstFragment);
to
workoutDetailFragment = (WorkoutDetailFragment)this.getSupportFragmentManager().findFragmentById(R.id.myFirstFragment);
What's the problem of getting a fragment? The getFragmentManager().findFragmentById() method returns a Fragment and you have to cast it. Since you are casting the Fragment to a WorkoutDetailFragment you should be able to do what you want with it.
I think it has to be <fragment android:name="com.hfad.chapter7.WorkoutDetailFragment"... instead of class.
=> http://developer.android.com/training/basics/fragments/creating.html#AddInLayout

RecyclerView "No Results" TextView findViewById always returns null

I have a RecyclerView with a TextView in it's place as well for when no results are found.
This TextView when calling root.findViewById always returns null, I have tried re-cleaning the project, building the project over again. Nothing has helped.
Here are my imports:
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.Message;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ProgressBar;
import android.widget.TextView;
import com.mypackage.commoncode.R;
Here is the code for the onCreateView:
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View root = inflater.inflate(R.layout.fragment_mail, container, false);
//
mProgressBar = (ProgressBar) root.findViewById(R.id.spinner);
mProgressBar.setVisibility(View.VISIBLE);
final Context context = root.getContext();
mEmptyView = (TextView) root.findViewById(R.id.empty_view);
mEmptyView.setVisibility(View.INVISIBLE);
// set list
float ht = BitmapUtils.convertDpToPixel(8, context);
mLinearLayoutManager = new LinearLayoutManager(context);
mListView = (RecyclerView) root.findViewById(android.R.id.list);
mListView.setLayoutManager(mLinearLayoutManager);
mListView.setVisibility(View.INVISIBLE);
mListView.addItemDecoration(new VerticalSpaceItemDecoration(Float.valueOf(ht).intValue()));
mListAdapter = new InboxListAdapter(context);
mListAdapter.setOnInboxClickListener(this);
mListView.setAdapter(mListAdapter);
if (mBackground == null) {
mBackground = new HandlerThread("background", android.os.Process.THREAD_PRIORITY_BACKGROUND);
mBackground.start();
mBackgroundCallback = new BackgroundCallback(this.getActivity().getApplicationContext(), mCurrentKid);
mBackgroundHandler = new Handler(mBackground.getLooper(), mBackgroundCallback);
}
final Handler displayHandler = new Handler(new HandlerCallback(this));
mBackgroundCallback.setDisplayHandler(displayHandler);
//
retrieveInboxList(context);
return root;
}
Here is the XML for the layout:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ProgressBar
android:id="#+id/spinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center|center_horizontal" />
<android.support.v7.widget.RecyclerView
android:id="#+id/android:list"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<TextView
android:id="#+id/empty_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:visibility="invisible"
android:text="#string/No_Results_found" />
</FrameLayout>
Any ideas as to why the empty_view TextView is always null?
Logcat error:
java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.TextView.setVisibility(int)' on a null object reference
at this line:
mEmptyView.setVisibility(View.INVISIBLE);
The view xml referenced does not have the view with the id your are trying to retrieve. Make sure the xml posted is the correct one or that you have another xml for this resolution that maybe is not containing the view.

android layout is not displaying

I know its probably something simple I am missing here, but for some reason I can't seem to get my layout to display when I run my app using the emulator. Any feedback would be great. Thanks
my fragment
package com.pctoolman.planme.app;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
public class PlanMeMainFragment extends Fragment {
private Button mNewButton, mExistingButton;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.planme_main_fragment, container, false);
mNewButton = (Button)v.findViewById(R.id.new_event_button);
mNewButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent myIntent = new Intent(getActivity(), NewEventSetupActivity.class);
getActivity().startActivity(myIntent);
}
});
return v;
}
}
my layout file:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:background="#ff3a0b">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:text="#string/plan_me"
android:textSize="36dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="2"
android:gravity="center|top"
android:textAlignment="center"
android:textColor="#2c58ff"
android:id="#+id/textView">
</TextView>
</LinearLayout>
<Button
android:id="#+id/new_event_button"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_gravity="bottom"
android:padding="5dp"
android:text="#string/new_event"
android:layout_centerHorizontal="true"
android:layout_marginTop="160dp" />
<Button
android:id="#+id/existing_event"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:padding="5dp"
android:text="#string/existing_event"
android:layout_centerHorizontal="true"
android:layout_marginTop="260dp"/>
</RelativeLayout>
here is the activity file
package com.pctoolman.planme.app;
import android.support.v4.app.Fragment;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
public class PlanMeMainActivity extends FragmentActivity {
#Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.planme_main_activity);
}
}
You should make a transatcion via FragmentManager to show your fragment in the activity. Suppose you have container (FrameLayout, for example) with id = fragment_container in your planme_main_activity.xml. If so, you should add the following after setContentView(R.layout.planme_main_activity);:
getSupportFragmentManager()
.beginTransaction()
.replace(R.id.fragment_container, new PlanMeMainFragment())
.commit();
But if you declared fragment directly in XML, please post your planme_main_activity.xml
Maybe it's because you haven't positioned the buttons properly. It's easy to move things around in a relative layout. You don't need to use gravity. You can use:
android:layout_alignParentBottom="true"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_above="#+id/btn"
android:layout_below="#+id/btn"
I'm assuming you cut out the closing tag for the RL.

Categories

Resources