how to Create Slide up Menu in Xamarin.Android - xamarin.android

how to Create Slide up Menu in Xamarin.Android

Firstly , create a bottom_dialog.xml layout:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/bottom_sheet"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#000"
android:orientation="vertical"
android:padding="16dp"
app:behavior_hideable="false"
app:behavior_peekHeight="90dp"
app:layout_behavior="android.support.design.widget.BottomSheetBehavior">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:textColor="#fff"
android:textSize="18"
android:textAlignment="center"
android:drawablePadding="20dp"
android:text="Menu" />
<TextView
android:id="#+id/action1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:textColor="#fff"
android:drawablePadding="16dp"
android:text="111111111" />
<TextView
android:id="#+id/action2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:textColor="#fff"
android:drawablePadding="16dp"
android:text="222222222" />
<TextView
android:id="#+id/action3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:textColor="#fff"
android:drawablePadding="16dp"
android:text="333333333" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:background="#aaa"
android:text="Start"
android:textColor="#fff" />
</LinearLayout>
And in the activiy
private void FabOnClick(object sender, EventArgs eventArgs)
{
View dialogView = LayoutInflater.Inflate(Resource.Layout.bottom_dialog, null);
BottomSheetDialog dialog = new BottomSheetDialog(this);
dialog.SetContentView(dialogView);
dialog.Show();
}
Update
You could override the method OnTouchEvent in the activity .
float x1 = 0;
float x2 = 0;
float y1 = 0;
float y2 = 0;
public override bool OnTouchEvent(MotionEvent e)
{
if (e.Action==MotionEventActions.Down)
{
x1 = e.GetX();
y1 = e.GetY();
}
if(e.Action == MotionEventActions.Up)
{
x2 = e.GetX();
y2 = e.GetY();
if(y1-y2>50)
{
View dialogView = LayoutInflater.Inflate(Resource.Layout.bottom_dialog, null);
BottomSheetDialog dialog = new BottomSheetDialog(this);
dialog.SetContentView(dialogView);
dialog.Show();
}
}
return base.OnTouchEvent(e);
}

Related

How to create view in Xamarin.Android

enter image description here
How do I make a view like this in Xamarin.Android?
You can use LinearLayout and GridLayout to achieve it. Use two LinearLayout, set the android:layout_weight=1 both of them, It could divide the entire screen equally, then use GridLayout, add all of Awards, use Textview to show the awards name, use ImageView to show the awards image. You can set the android:background="#drawable/back" as the background(award shelf image) in the outside LinearLayout
<?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"
android:background="#drawable/back"
>
<GridLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:rowCount="2"
android:columnCount="6"
android:orientation="vertical"
>
<LinearLayout
android:layout_margin="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_row="0"
android:layout_column="0">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hamberguer1"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/myicon"/>
</LinearLayout>
<LinearLayout
android:layout_margin="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_row="0"
android:layout_column="1">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hamberguer1"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/myicon"/>
</LinearLayout>
<LinearLayout
android:layout_margin="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_row="0"
android:layout_column="2">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hamberguer1"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/myicon"/>
</LinearLayout>
<LinearLayout
android:layout_margin="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_row="0"
android:layout_column="3">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hamberguer1"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/myicon"/>
</LinearLayout>
<LinearLayout
android:layout_margin="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_row="0"
android:layout_column="4">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hamberguer1"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/myicon"/>
</LinearLayout>
<LinearLayout
android:layout_margin="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_row="0"
android:layout_column="5">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hamberguer1"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/myicon"/>
</LinearLayout>
</GridLayout>
<GridLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:rowCount="4"
android:columnCount="6"
android:orientation="vertical"
>
<LinearLayout
android:layout_margin="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_row="0"
android:layout_column="0">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hamberguer1"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/myicon"/>
</LinearLayout>
<LinearLayout
android:layout_margin="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_row="0"
android:layout_column="1">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hamberguer1"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/myicon"/>
</LinearLayout>
<LinearLayout
android:layout_margin="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_row="0"
android:layout_column="2">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hamberguer1"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/myicon"/>
</LinearLayout>
<LinearLayout
android:layout_margin="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_row="0"
android:layout_column="3">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hamberguer1"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/myicon"/>
</LinearLayout>
<LinearLayout
android:layout_margin="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_row="0"
android:layout_column="4">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hamberguer1"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/myicon"/>
</LinearLayout>
<LinearLayout
android:layout_margin="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_row="0"
android:layout_column="5">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hamberguer1"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/myicon"/>
</LinearLayout>
</GridLayout>
</LinearLayout>
Here is running gif.
You need to write a new GridView for shelves. Here is code.
public class BookGridView: Android.Widget.GridView
{
Context context;
private Bitmap background;
public BookGridView(Context context, Android.Util.IAttributeSet attributeSet):base(context, attributeSet)
{
this.context = context;
background = null;
}
protected override void DispatchDraw(Canvas canvas)
{
int count = ChildCount;
int top = count > 0 ? GetChildAt(0).Top : 0;
int width = Width;
int height = Height;
int totalCount = this.Count;
//If the total is 0, there is no need to calculate the height and draw the picture
if (totalCount > 0)
{
//get Columns
int numColumns = 3;
// Calculate the row height by calculating the number of rows and height
int rowCount = totalCount / numColumns;
if (totalCount % numColumns != 0)
{
rowCount++;
}
int rowHeight = height / rowCount;
if (background == null)
{
background = BitmapFactory.DecodeResource(Resources,
Resource.Drawable.bookshelf_layer_center);
background = Bitmap.CreateScaledBitmap(background, width, rowHeight, true);
}
int backgroundWidth = background.Width;
int backgroundHeight = background.Height;
for (int y = top; y < height; y += backgroundHeight)
{
for (int x = 0; x < width; x += backgroundWidth)
{
canvas.DrawBitmap(background, x, y, null);
}
}
}
base.DispatchDraw(canvas);
}
}
}
Here is running screenshot. shelves will increase by the number of awards.
I upload my demo, you can set columns of shelves by yourself.
https://github.com/851265601/Xamarin.Android_ListviewSelect/blob/master/App17.zip

Oxyplot graph takes up whole screen for display

I just started using using oxyplot library for my project. I successfully added a donut chart in my project but the problem with this is that it takes up the whole screen to show the graph. Is tried so many way to solve this but none of them worked.
Here is my axml:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
local:layout_behavior="#string/appbar_scrolling_view_behavior" >
<OxyPlot.Xamarin.Android.PlotView
android:id="#+id/plot_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
local:MvxBind="Model DonutChart"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="16dp"
local:MvxBind="Text TestText1" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="16dp"
local:MvxBind="Text TestText2" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="16dp"
local:MvxBind="Text TestText3" />
</LinearLayout>
Here is the graph method:
private void GeneratePlotModel()
{
var plotmodel = new PlotModel();
var seriesP1 = new PieSeries
{
Stroke = OxyColors.Transparent,
StrokeThickness = 2.0,
InsideLabelPosition = 0.0,
AngleSpan = 360,
StartAngle = 0,
InnerDiameter = 0.7,
OutsideLabelFormat = null,
InsideLabelFormat = null,
TickHorizontalLength = 0.0,
TickRadialLength = 0.0
};
seriesP1.Slices.Add(new PieSlice("Test 1", test1) { IsExploded = false, Fill = OxyColors.Blue });
seriesP1.Slices.Add(new PieSlice("Test 2", test2) { IsExploded = false, Fill = OxyColors.Green });
seriesP1.Slices.Add(new PieSlice("Test 3", test3) { IsExploded = false, Fill = OxyColors.Red });
plotmodel.Series.Add(seriesP1);
DonutChart = plotmodel;
}
Here is my plotmodel property:
private PlotModel _donutChart ;
public PlotModel DonutChart
{
get => _donutChart ;
set
{
if (_donutChart == value)
return;
_donutChart = value;
RaisePropertyChanged(nameof(DonutChart ));
}
}
It takes up the whole screen to show the graph because you set
android:layout_width="match_parent"
android:layout_height="match_parent"
And you can make it only takes patial space by adding
android:layout_weight="1"
So the layout is like this:
<OxyPlot.Xamarin.Android.PlotView
android:id="#+id/plot_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
local:MvxBind="Model DonutChart"/>

how do i get the text from edittext in in inflated layout

I have a Button that, when click on it, displays 6 TextEdits. This happens trhough a inflated layout, that contains the TextEdits. That means, that everytime you click on the Button you get 6 new TextEdit. Now, how can i collect the Values of all of them?
Inflated Layout XML:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="368dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginTop="8dp"
android:orientation="horizontal">
<EditText
android:id="#+id/nombrePuntaje"
android:layout_width="54dp"
android:layout_height="42dp"
android:layout_weight="1"
android:ems="10"
android:inputType="textPersonName"
android:hint="Nombre"
/>
<EditText
android:id="#+id/j1"
android:layout_width="54dp"
android:layout_height="42dp"
android:layout_weight="1"
android:ems="10"
android:inputType="textPersonName"
android:hint="00"
/>
<EditText
android:id="#+id/j2"
android:layout_width="54dp"
android:layout_height="42dp"
android:layout_weight="1"
android:ems="10"
android:inputType="textPersonName"
android:hint="00"
/>
<EditText
android:id="#+id/j3"
android:layout_width="54dp"
android:layout_height="42dp"
android:layout_weight="1"
android:ems="10"
android:inputType="textPersonName"
android:hint="00"
/>
<EditText
android:id="#+id/j4"
android:layout_width="wrap_content"
android:layout_height="42dp"
android:layout_weight="1"
android:ems="2"
android:inputType="textPersonName"
android:hint="00"
/>
<EditText
android:id="#+id/j5"
android:layout_width="wrap_content"
android:layout_height="42dp"
android:layout_weight="1"
android:ems="2"
android:inputType="textPersonName"
android:hint="00"
/>
Here int the activity, when inflates:
agregarPuntajes = (Button) findViewById(R.id.cargarPuntajes);
agregarPuntajes.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
//https://stackoverflow.com/questions/29673613/remove-and-add-layout-dynamically-by-click-button-in-android
LayoutInflater ltInflater = getLayoutInflater();
final LinearLayout subLayoutFields = (LinearLayout) findViewById(R.id.contenedorPuntajes);
final View view1 = ltInflater.inflate(R.layout.puntos, subLayoutFields, true);
}
});
Thank you :)
To gather all the edit texts
LinearLayout myLayout = get the layout of edit-texts
ArrayList<EditText> myEditTextList = new ArrayList<EditText>();
for( int i = 0; i < myLayout.getChildCount(); i++ )
if( myLayout.getChildAt( i ) instanceof EditText )
myEditTextList.add( (EditText) myLayout.getChildAt( i ) );

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