I am doing a time management app for android for my project in school. So there is a class called Activity which represents the activities done by the user through the day(Like going to school,listening to music,eating etc). Activity objects have an instant variable called done which is type of boolean and another insant variable Tags which is a Tag array. There is need for boolean done because user can enter activities for the future and later he/she can mark it as done. Tag class is for the user to label their activities(For example an activity can have tags: sport and hobby at the same time).These activities entered by the user to the program are shown in a fragment called Activities fragment. There will be 2 different Listviews in this fragment one for done and the other for undone activities. So I wrote my xml code so that it would have 2 Listviews on top of each other and added this listviews to my fragment. However, when I run my code I only can see one of the Listviews, the other one does not show up.This is how my xml file look like:(here is the picture of the design:http://postimg.org/image/a7u1ynfzb/)
<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:orientation="vertical"
tools:context="com.beter.timehole.fragment.ActivitiesFragment">
<!-- TODO: Update blank fragment layout -->
<ListView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:id="#+id/listView1"
/>
<ListView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:id="#+id/listView2"
/>
</LinearLayout>
Here is my code for fragment class:
public class ActivitiesFragment extends Fragment {
public ActivitiesFragment() {
}
#Nullable
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
ArrayList<Tag> tags1= new ArrayList<Tag>();
tags1.add(new Tag("Tag1"));
ArrayList<Tag> tags2= new ArrayList<Tag>();
tags2.add(new Tag("Tag2"));
com.beter.timehole.core.Activity doneSample = new com.beter.timehole.core.Activity("Work",true,70,"16 50","17 00",tags1,"did it");
com.beter.timehole.core.Activity undoneSample = new com.beter.timehole.core.Activity("Fun",false,30,"13 30","14 00",tags2,"will do it");
View rootView = inflater.inflate(R.layout.activity_fragment, container, false);
ArrayList<com.beter.timehole.core.Activity> doneActivities = new ArrayList<com.beter.timehole.core.Activity>();
doneActivities.add(doneSample);
ListView doneList = (ListView) rootView.findViewById(R.id.listView1);
doneList.setAdapter(new ArrayAdapter<com.beter.timehole.core.Activity>(getActivity(), R.layout.support_simple_spinner_dropdown_item, doneActivities));
ArrayList<com.beter.timehole.core.Activity> undoneActivities = new ArrayList<com.beter.timehole.core.Activity>();
undoneActivities.add(undoneSample);
ListView undoneList = (ListView) rootView.findViewById(R.id.listView2);
undoneList.setAdapter(new ArrayAdapter<com.beter.timehole.core.Activity>(getActivity(),R.layout.support_simple_spinner_dropdown_item,undoneActivities));
return rootView;
}
}
Try to Change layout_height="0dp" .
Try this layout code.
`
<!-- TODO: Update blank fragment layout -->
<ListView
android:id="#+id/listView1"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1" />
<ListView
android:id="#+id/listView2"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1" />
`
If this is not working try to check your code or put your complete code here.
Please try this
<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:orientation="vertical"
tools:context="com.beter.timehole.fragment.ActivitiesFragment">
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:id="#+id/listView1"
/>
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:id="#+id/listView2"
/></LinearLayout>
Related
I have the following DialogFragment
public class DetailItemFragment extends AppCompatDialogFragment {
#BindView(R.id.task_detail_name)
AppCompatTextView taskDetailNameText;
#BindView(R.id.task_detail_description)
AppCompatTextView taskDetailDescriptionText;
#BindView(R.id.task_detail_priority)
AppCompatTextView taskDetailPriorityText;
#BindView(R.id.toolbar)
Toolbar toolbar;
#Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
Dialog dialog = super.onCreateDialog(savedInstanceState);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setCanceledOnTouchOutside(true); //doesn't work
dialog.setCancelable(true); //doesn't work
return dialog;
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_detail_view, container, false);
ButterKnife.bind(this, view);
//Get the Json back and parse it as a Task
Bundle bundle = getArguments();
final String taskAsJson = bundle.getString("task");
Task task = new Gson().fromJson(taskAsJson, Task.class);
((AppCompatActivity) getActivity()).setSupportActionBar(toolbar);
ActionBar actionBar = ((AppCompatActivity) getActivity()).getSupportActionBar();
if (actionBar != null) {
actionBar.setDisplayShowTitleEnabled(false);
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setHomeButtonEnabled(true);
actionBar.setHomeAsUpIndicator(R.drawable.close);
}
setHasOptionsMenu(false);
taskDetailNameText.setText(task.getName());
taskDetailDescriptionText.setText(task.getDescription());
taskDetailPriorityText.setText(task.getPriority().toString());
return view;
}
I perform the Fragment transaction like so
//Put the clicked item into a Bundle for the next fragment to consume
DialogFragment detailItemFragment = new DetailItemFragment();
Bundle args = new Bundle();
args.putString("task", new Gson().toJson(mTaskListAdapter.getItem(position)));
detailItemFragment.setArguments(args);
getActivity().getSupportFragmentManager().beginTransaction()
.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN)
.add(R.id.task_detail_fragment_container, detailItemFragment)
.addToBackStack(null)
.commit();
I'm trying to accomplish the following:
* On a tablet/large screen, this displays as a Dialog popup
* On a phone, it will display a fullscreen dialog (pretty much trying to replicate how Google Calendar handles opening event details)
This is what my xlarge/activity_main.xml looks like
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:id="#+id/task_detail_fragment_container"
android:layout_width="800dp"
android:layout_height="400dp"
android:layout_centerInParent="true"
android:elevation="16dp" />
<android.support.design.widget.AppBarLayout
android:id="#+id/header"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
style="#style/ToolbarStyle"
android:background="#color/colorPrimary"
app:title="#string/app_name"
app:titleTextColor="#color/white" />
</android.support.design.widget.AppBarLayout>
<FrameLayout
android:id="#+id/task_fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/header" />
<android.support.design.widget.FloatingActionButton
android:id="#+id/fab_add"
android:layout_width="#dimen/fab_normal_size"
android:layout_height="#dimen/fab_normal_size"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_marginBottom="#dimen/fab_padding"
android:layout_marginEnd="#dimen/fab_padding"
android:src="#drawable/add_black"
app:elevation="#dimen/fab_elevation"
app:fabSize="normal"
app:layout_anchorGravity="bottom|right|end"
app:pressedTranslationZ="#dimen/fab_pressed_elevation" />
</RelativeLayout>
You'll notice I have a FrameLayout that is centered on the screen for loading the DetailItemFragment into. Maybe this isn't the correct way to do this--but I want to bring it up in case that turns out to be the issue.
This is what the fragment_detail_view.xml layout looks like
<android.support.design.widget.CoordinatorLayout 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/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/task_detail_background"
android:clickable="true"
android:elevation="8dp"
tools:context="io.havoc.todo.view.fragments.DetailItemFragment">
<android.support.design.widget.AppBarLayout
android:id="#+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:elevation="0dp">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="#dimen/toolbar_tall_height"
android:background="?attr/colorPrimary">
<android.support.v7.widget.AppCompatTextView
android:id="#+id/task_detail_name"
style="#style/TextAppearance.Widget.AppCompat.Toolbar.Title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="start|bottom"
android:layout_marginBottom="#dimen/activity_vertical_margin"
android:gravity="start|bottom"
android:padding="8dp"
android:text="Task detail"
android:textColor="#color/white"
android:textSize="24sp" />
</android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="#dimen/activity_vertical_margin"
android:layout_marginStart="86dp"
android:layout_marginTop="#dimen/activity_vertical_margin"
android:orientation="vertical"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<android.support.v7.widget.AppCompatTextView
style="#style/TextAppearance.AppCompat.Body2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/spacing_margin"
android:text="#string/hint_task_description"
android:textColor="#color/colorAccent" />
<android.support.v7.widget.AppCompatTextView
android:id="#+id/task_detail_description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:text="Description text"
android:textColor="#color/text_primary"
android:textSize="18sp" />
<android.support.v7.widget.AppCompatTextView
style="#style/TextAppearance.AppCompat.Body2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/spacing_margin"
android:text="#string/hint_task_priority"
android:textColor="#color/colorAccent" />
<android.support.v7.widget.AppCompatTextView
android:id="#+id/task_detail_priority"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:text="Priority"
android:textColor="#color/text_primary"
android:textSize="18sp" />
</LinearLayout>
</android.support.design.widget.CoordinatorLayout>
The issue
When the DialogFragment is open on a tablet, the Activity in the background still accepts touches (i.e. I can interact with the Activity as if the dialog wasn't even present); furthermore, I have no idea how to get the DialogFragment to dismiss when touching outside of it. I've tried the following:
dialog.setCanceledOnTouchOutside(true); (in the onCreateDialog() method)
dialog.setCancelable(true); (in the onCreateDialog() method)
dialog.setCanceledOnTouchOutside(false); (in the onCreateDialog() method)
getDialog().setCanceledOnTouchOutside(true); setCancelable(true); (leads to NullPointerExceptions--performed in onCreateView() for the DialogFragment)
I've gone through all the other questions like this I could find and nothing has worked for me--so clearly I'm doing something wrong.
I appreciate any and all help.
Change to .dialog.setCancelable(false);.
If it's a dialog with OK and Cancel buttons, you can use:
.setCancelable(closeActivity == true ? false : true)
The FrameLayout (task_detail_fragment_container) you are adding your DetailItemFragment TO has a different size then the parent, which means it will not cover the entire layout:
...
android:layout_width="800dp"
android:layout_height="400dp"
...
To fix this, make task_detail_fragment_container the same size as the parent layout (match_parent) and cap the size of the dialog in the dialog layout by introducing another Layout after your container layout:
<android.support.design.widget.CoordinatorLayout 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/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/transparent"
android:clickable="true"
android:elevation="8dp"
tools:context="io.havoc.todo.view.fragments.DetailItemFragment">
<FrameLayout
andorid:width="800dp"
android:height="400dp"
android:layout_centerInParent="true">
<android.support.design.widget.AppBarLayout ...
//rest of your xlm here
</FrameLayout>
</android.support.design.widget.CoordinatorLayout>
Change this
dialog.setCanceledOnTouchOutside(true);
with
dialog.setCanceledOnTouchOutside(false);
I'm getting an extra icon while adding ImageView in a ListView as shown below. What is this and how can I remove it?
In my content it also shows up and when selected it highlights the ImageView shown here
The xml code is here:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context="anaxin.newshellas.Feed"
tools:showIn="#layout/activity_feed">
<ListView
android:choiceMode="singleChoice"
android:listSelector="#android:color/darker_gray"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/feedView"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:clickable="false" />
<TextView
android:id="#+id/textTop"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="16sp"
android:textStyle="bold"
/>
<TextView
android:id="#+id/textBot"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="12sp"
android:layout_below="#+id/textTop"
/>
<ImageView
android:layout_below="#+id/textTop"
android:layout_alignParentRight="true"
android:id="#+id/image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/image"
/>
</RelativeLayout>
I use a SimpleAdapter with two rows (textTop, TextBot) to populate my listView like this:
final SimpleAdapter adapter = new SimpleAdapter(this, data, R.layout.content_feed,
new String[]{"First Line", "Second Line"},
new int[]{R.id.textTop, R.id.textBot}) {
public View getView(int position, View convertView, ViewGroup parent) {
View view = super.getView(position, convertView, parent);
return view;
}
};
And in method to add items this part
Map<String, String> datum = new HashMap<>(2);
datum.put("First Line", article.getTop());
datum.put("Second Line", article.getBot());
data.add(datum);
First of all Don't mix up ListView and other elements like TextView and ImageView which should be in the single item layout. Because of it you are seeing multiple images in single list.
And another thing to be noticed is your android:layout_below="#+id/textTop" attribute is conflicted in ImageView and TextView as well, so I suggest you to fix that as well.
Rest of the codes are fine enough !!
You have an extra ImageView and 2 extra TextViews in your layout file. These should be in the layout file of your list adapter and not in the layout containing listview itself. Try removing these extra views, that might solve your problem
remove all content in your list view like
<RelativeLayout 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:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context="anaxin.newshellas.Feed"
tools:showIn="#layout/activity_feed">
<ListView
android:choiceMode="singleChoice"
android:listSelector="#android:color/darker_gray"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/feedView"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:clickable="false" />
you don't need them
I have successfully implemented Google's SlidingTabLayout and it is working as expected but my view is showing a black screen below it. Like so:
Here is the my activity main layout folder:
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:elevation= "16dp">
<LinearLayout
android:layout_width="220dp"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_gravity="start"
android:id = "#+id/stickylist">
<ViewFlipper
android:id="#+id/flipper1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:flipInterval="2000"
android:inAnimation="#android:anim/fade_in"
android:outAnimation="#android:anim/fade_out"
>
<ImageView
android:src="#drawable/front"
android:layout_width="220dp"
android:layout_height="180dp"
android:contentDescription="#string/str_img1"
/>
<ImageView
android:src="#drawable/field"
android:layout_width="220dp"
android:layout_height="180dp"
android:contentDescription="#string/str_img2"
/>
<ImageView
android:src="#drawable/cafeteria"
android:layout_width="220dp"
android:layout_height="180dp"
android:contentDescription="#string/str_img3"
/>
</ViewFlipper>
<se.emilsjolander.stickylistheaders.StickyListHeadersListView
android:id="#+id/left_drawer"
android:layout_width="220dp"
android:layout_height="fill_parent"
android:layout_gravity="start"
android:choiceMode="singleChoice"
android:dividerHeight="1dp"
android:divider="#drawable/customdrawershape"
/>
</LinearLayout>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:id="#+id/fragment_container"
android:layout_width="wrap_content"
android:layout_height="fill_parent">
</FrameLayout>
</android.support.v4.widget.DrawerLayout>
Then here is where I implement my PagerAdapter in SlidingTabsBasicFragment:
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
view = inflater.inflate(R.layout.tabs, container, false);
....}
tabs.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<xxx.xxx.xxx.SlidingTabLayout
android:id="#+id/pager_header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:elevation="16dp"/>
<android.support.v4.view.ViewPager
android:id="#+id/pager"
android:layout_width="match_parent"
android:layout_weight ="1"
android:layout_height="0dp"
>
</android.support.v4.view.ViewPager>
</LinearLayout>
Here is where I call on the fragment in my activity class:
android.support.v4.app.FragmentManager manager = getSupportFragmentManager();
FragmentTransaction transaction = manager.beginTransaction();
transaction.addToBackStack(null);
SlidingTabsBasicFragment fragment = new SlidingTabsBasicFragment();
transaction.replace(R.id.fragment_container, fragment);
transaction.commit();
I do have other simultaneous fragments ongoing from the main activity that should be displayed. Is that what is going on? Here is the code for that fragment using a different layout for both what is displayed as well as the frame layout for the fragment container.
manager = getChildFragmentManager();
FragmentTransaction transaction = manager.beginTransaction();
transaction.addToBackStack(null);
EventFragment fragment = new EventFragment();
transaction.add(R.id.fragment_container, fragment);
transaction.commit();
The fragment container for the view I am trying to display that is not showing is:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:id="#+id/fragment_container"
android:layout_width="wrap_content"
android:layout_height="fill_parent">
</FrameLayout>
Here is the layout to the first fragment which uses a custom adapter for each list view tile integrated in from a different layout.
<RelativeLayout
xmlns:ads="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
android:animateLayoutChanges="true"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:baselineAligned="false"
android:background="#drawable/background">
<TextView
android:id= "#+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/string5"
android:layout_centerHorizontal="true"
android:layout_below= "#+id/progressBar"
android:textColor="#FFD600"
android:textSize="20sp"/>
<ProgressBar
android:id="#+id/progressBar"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:color="#42A5F5"
android:indeterminateTint="#42A5F5"
android:indeterminateTintMode="multiply"/>
<com.twotoasters.jazzylistview.JazzyListView
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:id="#+id/listView"
android:divider="#android:color/transparent"
android:dividerHeight="5dp"
android:paddingRight="10dp"
android:paddingLeft="10dp"
android:layout_above="#+id/layout"/>
</RelativeLayout>
EDIT:
Ok now I can get it show the screen by doing the following:
#Override
public Object instantiateItem(ViewGroup container, int position) {
// Inflate a new layout from our resources
switch (position){
case 0:
view = getActivity().getLayoutInflater().inflate(R.layout.eventlistview,
container, false);
new Event();
break;
case 1:
view = getActivity().getLayoutInflater().inflate(R.layout.twitter,
container, false);
new Twitter();
break;
case 2:
view = getActivity().getLayoutInflater().inflate(R.layout.stafflistview,
container, false);
new Staff();
break;
case 3:
view = getActivity().getLayoutInflater().inflate(R.layout.powerschool,
container, false);
new powerschool();
break;
}
// Add the newly created View to the ViewPager
container.addView(view);
// Return the View
return view;
}
But eventually the progress bar for the fragment layout I have code for is supposed to go away and a list view is to be displayed. However, it will just show this layout forever even though there is more going on in the background. Any ideas?
This is so limited if all you can do is a single layout. Seriously? This is bad.
Wild guesses...
in your tabs.xml: your ViewPager has a weight of android:layout_weight ="1" and a height of android:layout_height="0dp" your slidingtablayout has a height of wrap_content and ther father has not weightsum.. Change their father's weightsum to 1 and see..
let me know if it helps
I am trying to make a welcome activity that has header fragment xml and bottom view fragment xml that contains buttons to login. Can anyone help me how I will put this two fragment xml to my activity_main.xml?
This is my header.xml
<?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="220dp">
<ImageView
android:id="#android:id/background"
android:layout_width="match_parent"
android:layout_height="220dp"
android:scaleType="centerCrop"
android:src="#drawable/header_bg" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_gravity="bottom|right|end"
android:layout_marginStart="#dimen/android_spaces_large"
android:layout_marginEnd="#dimen/android_spaces_large"
android:layout_marginLeft="#dimen/android_spaces_large"
android:layout_marginRight="#dimen/android_spaces_large"
android:layout_marginBottom="#dimen/android_spaces">
<TextView
android:id="#+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/header_title"
style="#style/Header.TitleText" />
<TextView
android:id="#+id/subtitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/header_subtitle"
style="#style/Header.SubTitleText" />
</LinearLayout>
<View
android:id="#android:id/title"
android:layout_width="wrap_content"
android:layout_height="?android:actionBarSize"
android:background="#layout/header_ab_shadow" />
</FrameLayout>
And my fragment_bottomview.xml that contains only a single button.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Button"
android:id="#+id/button"
android:layout_gravity="center_horizontal" />
</LinearLayout>
And my activity_main.xml looks like this
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.windows81.welcomingwithheader.MainActivity"
tools:ignore="MergeRootFrame" />
I don't know what I am lacking or I am doing wrong, any tutorial link will really help me.
just make two new classes ,lets call them FragmentA and FragmentB and both should extend fragment
than override onCreateView for both fragmentA and fragmentB and set their view to your xml to the header.xml and fragment_bottomview.xml as shown below
public class FragmentA extends Fragment {
#Override
public View onCreateView(LayoutInflater inflater,ViewGroup container,Bundle
savedInstanceState) {
View view=inflater.inflate(R.layout.header,container,false);
return view;
}
}
public class FragmentB extends Fragment {
#Override
public View onCreateView(LayoutInflater inflater,ViewGroup container,Bundle
savedInstanceState) {
View view;
view=inflater.inflate(R.layout.fragment_bottomview,container,false);
return view;
}
}
and now to add FragmentA and FragmentB into your activity,put this code in your oncreate activity method
FragmentA fragmentA=new FragmentA();
FragmentManager manager=getFragmentManager();
FragmentTransaction trans=manager.beginTransaction();
trans.add(R.id.container,fragmentA,"fragmenta");/*adding fragment into
the
framelayout with id
container*/
FragmentB fragmentB=new FragmentB();
trans.add(R.id.container,fragmentB,"fragmentb");/*adding fragment into
the
framelayout with id
container*/
trans.commit();
and your probably should use relative layout instead of framelayout
I can't seem to get an onClick event on an imageview from a class that extends Fragment. What am i doing wrong here? I'm relatively new to developing for android..
Currently, this code gives me a null pointer exception - when i add the onClickListener code
Here is my code:
ImageView mImageView = (ImageView) v.findViewById(R.id.option_icon);
mImageView.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
}
});
these icons are placed in a listview which is placed on a Dialog:
Dialog's list view and button:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ListView android:id="#+id/preset_list_view"
android:layout_height="wrap_content"
android:layout_width="fill_parent"/>
<Button
android:id="#+id/dialogButtonOK"
android:layout_width="300dp"
android:layout_height="wrap_content"
android:text="#string/ok"
android:layout_marginTop="5dp"
android:layout_marginRight="5dp"
android:layout_below="#+id/image"/>
</LinearLayout>
items within the list view (imageview and textview):
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ImageView
android:id="#+id/option_icon"
android:clickable="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:src="#drawable/ic_launcher"
/>
<TextView
android:id="#+id/option_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="#+id/image"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:textSize="20dp" />
</RelativeLayout>
It must be that the ImageView you're trying to find it outside the scope of whatever v refers to.
If the image view is inside a list view then you should add the onClickListener from within the adapter
The imageView that you are trying to find is not accessible from v. If the imageView is in the main layout then use findViewById without using v else first inflate the view and then use view.findViewById.