My collapsing toolbar is not collapsing - android-coordinatorlayout

I can drag the toolbar manually and toolbar and navigation drawer are not working
together, collapsingtoolbar is collapsing a little but its is not merging into appbar. And why are there so many requirements for posting a question here , just adding these lines to meet the error of mostly code in your body
XML containing collapsing toolbar
<!-- TODO: Update blank fragment layout -->
<android.support.v4.widget.DrawerLayout 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/drawer_layout2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<android.support.design.widget.NavigationView
android:id="#+id/nav_view1"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
app:headerLayout="#layout/nav_header"
app:menu="#menu/drawer_view" />
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_marginTop="320dp"
android:text="What is PMKVY?"
android:textAppearance="#style/TextAppearance.AppCompat.Display1"
android:textSize="30sp"
android:textStyle="bold"
tools:layout_editor_absoluteX="0dp"
tools:layout_editor_absoluteY="217dp" />
<TextView
android:id="#+id/textView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="400dp"
android:fontFamily="serif"
android:text="#string/pmkvy_string"
android:textAppearance="#style/TextAppearance.AppCompat.Body1"
android:textColor="?android:attr/statusBarColor"
android:textSize="18sp"
android:textStyle="bold"
tools:layout_editor_absoluteX="-1dp"
tools:layout_editor_absoluteY="273dp" />
<Button
android:id="#+id/button6"
style="#style/Widget.AppCompat.Button.Colored"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="140dp"
android:layout_marginTop="720dp"
android:background="#android:color/black"
android:drawableRight="#drawable/ic_play_circle"
android:text="Watch Video"
android:textAlignment="center"
android:textColor="#android:color/background_light"
android:textStyle="bold"
tools:layout_editor_absoluteX="141dp"
tools:layout_editor_absoluteY="519dp" />
<TextView
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginTop="840dp"
android:text="How to Enroll?"
android:textAppearance="#style/TextAppearance.AppCompat.Display1"
android:textSize="30sp"
android:textStyle="bold" />
<TextView
android:id="#+id/textView3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="910dp"
android:fontFamily="serif"
android:text="#string/enroll_string"
android:textAppearance="#style/TextAppearance.AppCompat.Body1"
android:textColor="?android:attr/statusBarColor"
android:textSize="18sp"
android:textStyle="bold"
tools:layout_editor_absoluteX="-1dp"
tools:layout_editor_absoluteY="565dp" />
<Button
android:id="#+id/button7"
style="#style/Widget.AppCompat.Button.Colored"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/textView3"
android:layout_centerHorizontal="true"
android:layout_marginTop="150dp"
android:background="#android:color/black"
android:text="Call 1800 102 6000"
android:textAlignment="center"
android:textColor="#android:color/background_light"
android:textStyle="bold" />
<TextView
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginTop="1230dp"
android:gravity="center"
android:text="OR"
android:textAppearance="#style/TextAppearance.AppCompat.Display1"
android:textSize="30sp"
android:textStyle="bold" />
<Button
android:id="#+id/button8"
style="#style/Widget.AppCompat.Button.Colored"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="160dp"
android:layout_marginTop="1170dp"
android:background="#android:color/black"
android:text="Enroll"
android:textAlignment="center"
android:textColor="#android:color/background_light"
android:textStyle="bold" />
</RelativeLayout>
</ScrollView>
<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:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<android.support.design.widget.AppBarLayout
android:id="#+id/appBar"
android:layout_width="match_parent"
android:layout_height="300dp"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
android:fitsSystemWindows="true">
<android.support.design.widget.CollapsingToolbarLayout
android:id="#+id/collapsingToolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_scrollFlags="scroll|enterAlways"
android:minHeight="20dp"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
app:expandedTitleMarginStart="25dp"
app:expandedTitleMarginEnd="30dp"
app:title="PMKVY">
<ImageView
android:id="#+id/toolbarImage"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:fitsSystemWindows="true"
android:src="#drawable/pmkvy_logo"
app:layout_collapseMode="parallax" />
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="250dp"
android:background="#color/colorPrimaryDark"
android:theme="#style/ThemeOverlay.AppCompat.ActionBar" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
</android.support.design.widget.CoordinatorLayout>
</android.support.v4.widget.DrawerLayout>
.java file of xml
package com.example.shrey.myapplication;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.NavigationView;
import android.support.design.widget.Snackbar;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.text.Html;
import android.view.MenuItem;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
public class ScrollingActivity1 extends AppCompatActivity {
private DrawerLayout drawerlayout1;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.layout_activity_scrolling1);
drawerlayout1 = findViewById(R.id.drawer_layout2);
// set status bar color code
if (Build.VERSION.SDK_INT >= 21) {
Window window = this.getWindow();
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
window.setStatusBarColor(this.getResources().getColor(R.color.material_blue_grey_950));
}
Toolbar toolbar = findViewById(R.id.toolbar1);
setSupportActionBar(toolbar);
ActionBar actionbar = getSupportActionBar();
actionbar.setDisplayHomeAsUpEnabled(true);
actionbar.setHomeAsUpIndicator(R.drawable.ic_navdrawer);
// <!-- code to change title and its color. -->
actionbar.setTitle(Html.fromHtml("<font color='#ffffff'>PMKVY</font>"));
NavigationView navigationView = findViewById(R.id.nav_view1);
navigationView.setNavigationItemSelectedListener(
new NavigationView.OnNavigationItemSelectedListener() {
#Override
public boolean onNavigationItemSelected(#NonNull MenuItem menuItem) {
// set item as selected to persist highlight
menuItem.setChecked(true);
// close drawer when item is tapped
drawerlayout1.closeDrawers();
// Add code here to update the UI based on the item selected
// For example, swap UI fragments here
return true;
}
});
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
drawerlayout1.openDrawer(GravityCompat.START);
return true;
}
return super.onOptionsItemSelected(item);
}
}

Related

handling textview's width with screen rotation xamarin android

I have created a Xamarin.android app with listview inside a horizontalScrollView. I added [Activity(Label = "#string/app_name", Theme = "#style/AppTheme", MainLauncher = true, ConfigurationChanges = Android.Content.PM.ConfigChanges.Orientation | Android.Content.PM.ConfigChanges.ScreenSize)] to handle screen rotation. but what I realized is that my horizontalScrollView doesn't expand when screen is rotated horizontally so I added this android:fillViewport="true". it worked. but my textviews' widths remained the same. so I guessed it's because I have fixed width values for my textviews. I looked things up and finally came up with determining a weightsum for my linearlayout and weights for my textviews. this is my code:
<HorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fillViewport="true"
>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="fill_parent"
>
<Toolbar
android:minHeight="?android:attr/actionBarSize"
android:background="?android:attr/colorPrimary"
android:minWidth="25px"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/toolbar1" >
<SearchView
android:minWidth="25px"
android:minHeight="25px"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/searchView1" />
</Toolbar>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/customselector"
android:padding="8dp"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="10"
android:orientation="horizontal"
>
<TextView
android:text="Text"
android:layout_width="fill_parent"
android:layout_weight="1"
android:layout_height="100px"
android:id="#+id/textView1"
android:gravity="center"
android:textColor="#android:color/holo_red_dark"/>
<TextView
android:text="Text"
android:layout_width="fill_parent"
android:layout_weight="1"
android:layout_height="100px"
android:id="#+id/textView2"
android:layout_toRightOf="#id/textView1"
android:textColor="#android:color/holo_red_dark"
android:gravity="center"
android:layout_marginLeft="2dp"/>
<TextView
android:text="Text"
android:layout_width="fill_parent"
android:layout_weight="1"
android:layout_height="100px"
android:id="#+id/textView3"
android:layout_toRightOf="#id/textView2"
android:gravity="center"
android:textColor="#android:color/holo_red_dark"
android:layout_marginLeft="2dp"/>
<TextView
android:text="Text"
android:layout_width="fill_parent"
android:layout_weight="1"
android:layout_height="100px"
android:id="#+id/textView4"
android:layout_toRightOf="#id/textView3"
android:gravity="center"
android:layout_marginLeft="2dp"
android:textColor="#android:color/holo_red_dark"/>
<TextView
android:text="Text"
android:layout_width="fill_parent"
android:layout_weight="1"
android:layout_height="100px"
android:id="#+id/textView5"
android:layout_toRightOf="#id/textView4"
android:gravity="center"
android:layout_marginLeft="2dp"
android:textColor="#android:color/holo_blue_dark"
/>
</LinearLayout>
</RelativeLayout>
<ListView android:id="#+id/List"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:cacheColorHint="#FFDAFF7F"
android:choiceMode="singleChoice"
/>
<TextView
android:text="Text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/textView6"
android:layout_gravity="bottom|end"/>
</LinearLayout>
</HorizontalScrollView>
I chose weightsum=10 because I want my textviews' width to be big enough. so I thought I could view the rest of my textviews by scrolling. but the scrollview stopped working. why is that? what do I do?
thanks in advance.

button onclick event dont work in xamarin

i have problem with my code. i have created button "sign up", i want when i click on that button a dialog called "dialog_signup appear.
The problem is it doesnt appear. and i always get this error so far
**2>A numeric comparison was attempted on "$(_DeviceSdkVersion)" that evaluates to "" instead of a number, in condition "$(_DeviceSdkVersion) >= 21".
2>Build FAILED.
2>
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========
========== Deploy: 0 succeeded, 1 failed, 0 skipped ==========**
Here is my code
MainActivity.cs
using System;
using Android.App;
using Android.Content;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS;
using Android.Content.Res;
namespace GameLandPlus
{
[Activity(Label = "GameLandPlus", MainLauncher = true, Icon = "#drawable/icon")]
public class MainActivity : Activity
{
private Button mbtnSignup;
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
SetContentView(Resource.Layout.Main);
mbtnSignup = FindViewById<Button>(Resource.Id.btnsignup);
mbtnSignup.Click += (object sender, EventArgs args) =>
{
FragmentTransaction transaction = FragmentManager.BeginTransaction();
dialog_signup signupDialog = new dialog_signup();
signupDialog.Show(transaction, "dialog fragment");
};
}
}
}
-->
main.axml
<?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"
android:background="#android:color/background_light"
android:weightSum="100"
android:minWidth="25px"
android:minHeight="25px">
<ImageView
android:src="#drawable/images"
android:layout_width="match_parent"
android:layout_weight="20"
android:layout_height="0dp"
android:id="#+id/imageView1" />
<TextView
android:text="Create Account"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_width="match_parent"
android:layout_weight="20"
android:layout_height="0dp"
android:textColor="#000000"
android:id="#+id/createaccount"
android:textSize="35sp"
android:gravity="center"
android:textStyle="bold" />
<Button
android:layout_width="match_parent"
android:layout_weight="10"
android:layout_height="0dp"
android:gravity="center"
android:id="#+id/signin"
android:textColor="#FFFFFF"
android:background="#drawable/butto1"
android:layout_marginLeft="40dp"
android:layout_marginRight="40dp"
android:text="Sign in"
android:shadowColor="#A8A8A8"
android:shadowDx="0"
android:shadowDy="0"
android:shadowRadius="5" />
<TextView
android:text="or"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_width="match_parent"
android:layout_weight="15"
android:layout_height="0dp"
android:id="#+id/or"
android:textColor="#000000"
android:textSize="35sp"
android:gravity="center"
android:textStyle="bold" />
<Button
android:text="Sign Up"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="10"
android:id="#+id/btnsignup"
android:textColor="#FFFFFF"
android:background="#drawable/butto1"
android:layout_marginLeft="40dp"
android:layout_marginRight="40dp"
android:shadowColor="#00ffffff"
android:shadowRadius="5"
android:drawableRight="#drawable/goodmess" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="35"
android:minHeight="15px"
android:minWidth="15px">
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/progressBar1"
android:background="#drawable/progressbar"
android:indeterminate="true"
android:layout_centerInParent="true" />
</RelativeLayout>
</LinearLayout>
-->
the dialog page i want to pop up when i click on the button
dialogSignup.axml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:background="#F1F3F4"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:minHeight="300dp"
android:minWidth="300dp">
<EditText
android:inputType="textPersonName"
android:layout_width="match_parent"
android:layout_height="40dp"
android:id="#+id/Firstname"
android:background="#drawable/editstyle"
android:layout_marginBottom="10dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="25dp"
android:hint="Username"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:textColor="#000" />
<EditText
android:layout_below="#+id/Firstname"
android:inputType="textEmailAddress"
android:layout_width="match_parent"
android:layout_height="40dp"
android:id="#+id/textEmail"
android:background="#drawable/editstyle"
android:layout_marginBottom="10dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:hint="Email/Phone Number"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:textColor="#000" />
<EditText
android:layout_below="#+id/textEmail"
android:inputType="textPassword"
android:layout_width="match_parent"
android:layout_height="40dp"
android:id="#+id/password"
android:background="#drawable/editstyle"
android:layout_marginBottom="10dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:hint="Password"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:textColor="#000" />
<Button
android:layout_below="#+id/password"
android:text="Sign Up"
android:layout_width="match_parent"
android:layout_height="50dp"
android:id="#+id/btnDialogEmail"
android:textColor="#FFFFFF"
android:background="#drawable/butto1"
android:layout_marginLeft="40dp"
android:layout_marginRight="40dp"
android:shadowColor="#00ffffff"
android:shadowRadius="5"
android:drawableRight="#drawable/goodmess" />
</RelativeLayout>
-->
and the dialog_signup.cs
using Android.Views;
using Android.Widget;
namespace GameLandPlus
{
class dialog_signup:DialogFragment
{
public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle saveInstanceState)
{
base.OnCreateView(inflater, container, saveInstanceState);
var view = inflater.Inflate(Resource.Layout.dialogSignup, container, false);
return view;
}
public override void OnActivityCreated(Bundle savedInstanceState)
{
Dialog.Window.RequestFeature(WindowFeatures.NoTitle);//set title
base.OnActivityCreated(savedInstanceState);
Dialog.Window.Attributes.WindowAnimations = Resource.Style.dialog_animation;
}
}
}
-->
i do not include the slideup/slideright/butto1 because is the drawable file.
Please can u check on it.
I already change emulator so far. but i dont know where is the problem.
Any suggestion?

Android TV move focus between RecyclerViews

I am building an Android TV app with the following layout:
Both lists on the left and on the right are RecyclerViews with vertical LinearLayoutManagers, Header view is static. Navigation with D-PAD works fine within one list, but when switching from one list to another there are issues. Focus moves from, say list1's item 5 to list2' item 5. When list 2 is short has less than 5 items, it just loses focus.
I want the last focused item index saved and when the user navigates list1-list2-list1 the item with that index to gain focus again and also prevent the views from losing focus. Is there any good solution to this?
Required behaviour:
user navigates to the top of the list and presses "UP" - focus stays where it was, nothing happens.
user navigates to the bottom of the list and presses "DOWN" - focus stays where it was, nothing happens.
user navigates from list1 to list2 - the item, that previously had focus in list2, gains focus or item0 gains focus if none was focused previously.
main layout:
<?xml version="1.0" encoding="utf-8"?>
<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"
>
<ImageView
android:id="#+id/iv_background"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:focusable="false"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="27dp"
android:layout_marginLeft="48dp"
android:layout_marginRight="48dp"
android:layout_marginTop="27dp"
android:orientation="horizontal"
>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="2"
android:orientation="vertical"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusable="false"
android:orientation="horizontal"
>
<ImageView
android:id="#+id/iv_poster"
android:layout_width="#dimen/episodes_list_item_height"
android:layout_height="#dimen/episodes_list_image_width"
/>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical"
>
<TextView
android:id="#+id/tv_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<TextView
android:id="#+id/tv_release_date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
/>
<TextView
android:id="#+id/tv_rating"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:drawableLeft="#drawable/ic_star_white_24dp"
android:drawablePadding="#dimen/view_padding_small"
/>
</FrameLayout>
<TextView
android:id="#+id/tv_description"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
/>
</LinearLayout>
</LinearLayout>
<android.support.v7.widget.RecyclerView
android:id="#+id/rv_seasons_list"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:focusable="false"
/>
</LinearLayout>
<android.support.v7.widget.RecyclerView
android:id="#+id/rv_episodes_list"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="3"
android:focusable="false"
/>
</LinearLayout>
</FrameLayout>
item layout, used for both lists:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="#dimen/seasons_list_item_height"
android:orientation="horizontal"
android:focusable="true"
>
<TextView
android:id="#+id/tv_title"
android:layout_width="0dp"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:layout_weight="1"
/>
<TextView
android:id="#+id/tv_episodes_count"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:ems="10"
/>
</LinearLayout>
Digging through Google's Leanback library sources answered my payers.
If you face the same trouble, just wrap your RecyclerViews with this and don't forget to set
private boolean mPersistFocusVertical = false;
if you want the focus to be persisted when searching horizontally, like in my layout.
Modify your main layout as below.
For directional navigation we can add properties like nextFocusDown, nextFocusLeft, nextFocusRight, nextFocusUp to focus relevant items as per our requirements.
<?xml version="1.0" encoding="utf-8"?>
<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"
>
<ImageView
android:id="#+id/iv_background"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:focusable="false"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="27dp"
android:layout_marginLeft="48dp"
android:layout_marginRight="48dp"
android:layout_marginTop="27dp"
android:orientation="horizontal"
>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="2"
android:orientation="vertical"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusable="false"
android:orientation="horizontal"
>
<ImageView
android:id="#+id/iv_poster"
android:layout_width="#dimen/episodes_list_item_height"
android:layout_height="#dimen/episodes_list_image_width"
/>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical"
>
<TextView
android:id="#+id/tv_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<TextView
android:id="#+id/tv_release_date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
/>
<TextView
android:id="#+id/tv_rating"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:drawableLeft="#drawable/ic_star_white_24dp"
android:drawablePadding="#dimen/view_padding_small"
/>
</FrameLayout>
<TextView
android:id="#+id/tv_description"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
/>
</LinearLayout>
</LinearLayout>
<android.support.v7.widget.RecyclerView
android:id="#+id/rv_seasons_list"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:focusable="false"
android:nextFocusDown="#+id/rv_episodes_list"
/>
</LinearLayout>
<android.support.v7.widget.RecyclerView
android:id="#+id/rv_episodes_list"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="3"
android:focusable="false"
android:nextFocusUp="#+id/rv_seasons_list"
/>
</LinearLayout>
Hope this will solve your problem !!

Adding tabs dynamically in tabhost from database

I try to add tabs in tabhost dynamically from data which I extract from database. But usually I get exceptions. I want to use this tabhost in activity.
This is my code :
Main.cs
[Activity (Label = "Main",Theme = "#style/Theme.Splash")]
public class Main : Activity
{
TabHost tabHost;
protected override void OnCreate (Bundle bundle)
{
base.OnCreate (bundle);
SetContentView (Resource.Layout.activity_main);
tabHost = FindViewById<TabHost>(Resource.Id.tabHost1);
LocalActivityManager localActMgr = new LocalActivityManager(this, false);
localActMgr.DispatchCreate(bundle);
CSList<CategoriesArticlesConfig> categories = CategoriesArticlesConfig.List();
tabHost.Setup(localActMgr);
foreach (CategoriesArticlesConfig categorie in categories)
{
Intent i = new Intent();
i.SetFlags(ActivityFlags.NewTask);
i.PutExtra("CategorieID", categorie.CategorieArticlesConfigID);
i.SetClass(this, typeof(AfficheArticlesTab));
TabHost.TabSpec tab = tabHost.NewTabSpec("tab_"+categorie.CategorieArticlesConfigID);
tab.SetIndicator(""+categorie.Nom, Resources.GetDrawable(Android.Resource.Drawable.IcInputAdd));
tab.SetContent(i);
tabHost.AddTab(tab);
}
}
}
AfficheArticlesTab.cs
class AfficheArticlesTab : Activity
{
public AfficheArticlesTab() { }
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
SetContentView(Resource.Layout.activity_configuration);
GridView gridView = FindViewById<GridView>(Resource.Id.gv_item_articles_gridview_articles_tab_main_activity);
LayoutInflater layoutInflater = (LayoutInflater)GetSystemService(Context.LayoutInflaterService);
View view = layoutInflater.Inflate(Resource.Layout.gridview_articles_tab, null);
int CategorieID = Intent.Extras.GetInt("CategorieID");
CategoriesArticlesConfig categorie = CategoriesArticlesConfig.ReadFirst("CategorieArticlesID="+CategorieID);
gridView.Adapter = new ListArticleConfigAdapter(this,categorie.ArticlesConfig.ToList<ArticlesConfig>());
}
}
activity_main.axml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:minWidth="25px"
android:minHeight="25px"
android:background="#drawable/background_simple"
android:padding="5dp">
<FrameLayout
android:minWidth="25px"
android:minHeight="25px"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/frameLayout1"
android:layout_margin="5dp"
android:layout_weight="0.5">
<LinearLayout
android:orientation="vertical"
android:minWidth="25px"
android:minHeight="25px"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/linearLayout11">
<LinearLayout
android:orientation="horizontal"
android:minWidth="25px"
android:minHeight="25px"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/linearLayout12"
android:layout_weight="4">
<LinearLayout
android:orientation="vertical"
android:minWidth="25px"
android:minHeight="25px"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/linearLayout13"
android:layout_marginTop="14.0dp"
android:layout_marginLeft="8.0dp">
<LinearLayout
android:orientation="horizontal"
android:minWidth="25px"
android:minHeight="25px"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/linearLayout18">
<TextView
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:id="#+id/tv_num_ticket_activity_main" />
<TextView
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:id="#+id/tv_num_caissier_activity_main"
android:layout_marginLeft="10dp" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:minWidth="25px"
android:minHeight="25px"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/linearLayout14">
<LinearLayout
android:orientation="horizontal"
android:minWidth="25px"
android:minHeight="25px"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/linearLayout15"
android:layout_weight="0.1">
<EditText
android:inputType="numberDecimal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/ed_zone_main_activity"
android:layout_weight="0.16"
android:layout_marginTop="0.0dp" />
<TextView
android:text="#string/qte_value"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/tv_qte_value_main_activity"
android:layout_weight="0.3"
android:layout_marginRight="2.5dp"
android:layout_marginLeft="13.3dp"
android:layout_gravity="center_vertical"
android:gravity="right"
android:layout_marginTop="0.0dp"
android:textSize="20sp" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
<ListView
android:minWidth="25px"
android:minHeight="25px"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/listView1"
android:layout_weight="1"
android:layout_marginTop="8.0dp" />
</LinearLayout>
</FrameLayout>
<LinearLayout
android:orientation="vertical"
android:minWidth="25px"
android:minHeight="25px"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:id="#+id/linearLayout17"
android:layout_weight="0.3">
<FrameLayout
android:minWidth="25px"
android:minHeight="25px"
android:id="#+id/frameLayout2"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_weight="0.15">
<LinearLayout
android:orientation="vertical"
android:minWidth="25px"
android:minHeight="25px"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/linearLayout5">
<TabHost
android:minWidth="25px"
android:minHeight="25px"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/tabHost1">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:id="#+id/linearLayout19">
<TabWidget
android:id="#android:id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
</TabHost>
</LinearLayout>
</FrameLayout>
<LinearLayout
android:orientation="horizontal"
android:minWidth="25px"
android:minHeight="25px"
android:id="#+id/linearLayout16"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_weight="0.85">
<Button
android:text="#string/total"
android:id="#+id/bt_total_activity_main"
android:textSize="16sp"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="#drawable/button_selector_rouge" />
<Button
android:text="#string/quantitee"
android:id="#+id/bt_quantitee_activity_main"
android:textSize="16sp"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="#drawable/button_selector_enter" />
<Button
android:text="#string/code_barre"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:id="#+id/bt_code_barre_activity_main"
android:layout_weight="1"
android:textSize="16sp"
android:background="#drawable/button_selector_enter" />
<Button
android:text="#string/annuler"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:id="#+id/bt_annuler_activity_main"
android:layout_weight="1"
android:textSize="16sp"
android:background="#drawable/button_selector_enter" />
<Button
android:text="#string/remise"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:id="#+id/bt_remise_activity_main"
android:layout_weight="1"
android:textSize="16sp"
android:background="#drawable/button_selector_enter" />
<Button
android:text="#string/attente"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:id="#+id/bt_attente_activity_main"
android:layout_weight="1"
android:textSize="16sp"
android:background="#drawable/button_selector_enter" />
</LinearLayout>
</LinearLayout>
03-03 13:19:08.004 E/mono ( 7331): Unhandled Exception:
03-03 13:19:08.004 E/mono ( 7331): Java.Lang.NullPointerException: Exception of type 'Java.Lang.NullPointerException' was thrown.
03-03 13:19:08.004 E/mono ( 7331): at Android.Runtime.JNIEnv.CallVoidMethod (intptr,intptr,Android.Runtime.JValue[]) [0x00023] in /Users/builder/data/lanes/monodroid-lion-monodroid-4.6.6-branch/6d7480e9/source/monodroid/src/Mono.Android/src/Runtime/JNIEnv.g.cs:368
03-03 13:19:08.004 E/mono ( 7331): at Android.Widget.TabHost.AddTab (Android.Widget.TabHost/TabSpec) [0x0003e] in /Users/builder/data/lanes/monodroid-lion-monodroid-4.6.6-branch/6d7480e9/source/monodroid/src/Mono.Android/platforms/android-14/src/generated/Android.Widget.TabHost.cs:762
03-03 13:19:08.004 E/mono ( 7331): at SymaMobile.Droid.Main.OnCreate (Android.OS.Bundle) [0x000e8] in f:\PFE\VS2012\SymaMobile\SymaMobile\SymaMobile.Droid\Activities\Main.cs:41
03-03 13:19:08.004 E/mono ( 7331): at Android.App.Activity.n_OnCreate_Landroid_os_Bundle_ (intptr,intptr,intptr) [0x00010] in /Users/builder/data/lanes/monodroid-lion-monodroid-4.6.6-branch/6d7480e9/source/monodroid/src/Mono.Android/platforms/android-14/src/generated/Android.App.Activity.cs:1859
03-03 13:19:08.004 E/mono ( 7331): at (wrapper dynamic-m
I find it :)
Firstly, you should extends TabHost.ITabContentFactory
public class Main : Activity, TabHost.ITabContentFactory
Secondly, you should add a NewTabSpec in my tabhost.
tabHost.AddTab(tabHost.NewTabSpec("tab_" + categorie.CategorieArticlesConfigID).SetIndicator(createTabView(tabHost.Context, categorie.Nom)).SetContent(this));
And finally, you use the implemented method CreateTabContent like this:
public View CreateTabContent(string tag)
{
LayoutInflater layoutInflater = (LayoutInflater)GetSystemService(Context.LayoutInflaterService);
View view1 = layoutInflater.Inflate(Resource.Layout.gridview_articles_tab, null);
View view2 = layoutInflater.Inflate(Resource.Layout.list_item_article_configuration, null);
View view3 = layoutInflater.Inflate(Resource.Layout.tab_item, null);
GridView gridView = view1.FindViewById<GridView>(Resource.Id.gv_item_articles_gridview_articles_tab_main_activity);
CategoriesArticlesConfig categorie = CategoriesArticlesConfig.ReadFirst("CategorieArticlesConfigID=" + tabCatID[tabHost.CurrentTab]);
gridView.Adapter = new ListArticleTabAdapter(this, categorie.ArticlesConfig.ToList());
gridView.ItemClick += gridView_ItemClick;
return view1;
}
Thanks,

Custom adapter does not called getVIew

Here is the code of my custom adapter... it doesn't call my get view... returns only white blank page without nothing. I don't know what is the problem. Does anybody can help. Thanks a lot previously!
public class ProductShopsAdapter extends ArrayAdapter<ProductShop> {
private Context cntx;
private ArrayList<ProductShop> shopValues;
ProductShopsHolder holder = null;
public ProductShopsAdapter(Context context, int textViewResourceId, ArrayList<ProductShop> stringValues) {
super(context,textViewResourceId);
shopValues = stringValues;
cntx = context;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
holder = new ProductShopsHolder();
LayoutInflater layoutInflater = (LayoutInflater)cntx.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = layoutInflater.inflate(R.layout.shops_list, null);
//Holder Elements initialization
holder.setShopName((TextView)convertView.findViewById(R.id.shop_name));
holder.setPrice((TextView)convertView.findViewById(R.id.shop_part_price));
convertView.setTag(holder);
} else {
holder = (ProductShopsHolder) convertView.getTag();
}
holder.getShopName().setText(getItem(position).getShopName());
holder.getPrice().setText(getItem(position).getPrice());
return convertView;
}
}
and here is my 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=".ProductShopsActivity" >
<ListView
android:id="#android:id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/footer"
android:padding="0dp" >
</ListView>
<include
android:id="#+id/footer"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="#android:id/list"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
layout="#layout/footer_menu" />
</RelativeLayout>
and single view :
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/layout_item"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#f2f2f2"
android:orientation="horizontal"
android:padding="10dp" >
<TextView
android:id="#+id/shop_name"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="Technomarket"
android:textSize="14sp" />
<TextView
android:id="#+id/shop_part_price"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="30 лв."
android:textSize="18sp" />
<TextView
android:id="#+id/details_button"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:drawableRight="#drawable/rightarrow"
android:gravity="center"
android:text="Детайли"
android:textColor="#289bd6"
android:textSize="14sp" />
You don't need ArrayList inside your ArrayAdapter - ArrayAdapter can store items itself. And that's why getView() doesn't get called - default implementation of getCount() returns the number of items in ArrayAdapter itself. If you keep your items in your own ArrayList, at least override getCount() to return shopValues.getCount(). Otherwise it is always 0 and the ListView to which your adapter is bound doesn't even know there are any items to dsplay at all.

Resources