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

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 ) );

Related

how to Create Slide up Menu in 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);
}

My collapsing toolbar is not collapsing

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);
}
}

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?

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