Ich habe ein Problem mit meiner App. Zuerst machte ich zwei Tabs unter Verwendung von Fragmenten, die eine Aktivität aufblähen. Die implementierten Registerkarten funktionieren einwandfrei. Zweitens habe ich das XAML Recht angezeigt. Es ist jedoch nicht möglich, mit den Schaltflächen zu interagieren, aber es ist möglich, in die Textfelder zu schreiben. Die Textfelder reagieren jedoch nicht, wenn ich versuche, sie mit den Schaltflächen zu aktualisieren.Fragmente reagieren nicht auf Buttonclicks
Die Aktivitäten funktionieren ordnungsgemäß nicht mit den Fragmenten, keine Ahnung, was ich tun kann? Jede Hilfe wird sehr geschätzt! Dank
Hier ist mein Code:
MainActivity Code:
public class TabActivity : AppCompatActivity
{
private DrawerLayout mDrawerLayout;
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
SetContentView(Resource.Layout.Main);
//Toolbar
SupportToolbar toolbar = FindViewById<SupportToolbar>(Resource.Id.toolBar);
SetSupportActionBar(toolbar);
//ActionBar
SupportActionBar actionBar = SupportActionBar;
actionBar.SetHomeAsUpIndicator(Resource.Drawable.ic_menu);
actionBar.SetDisplayHomeAsUpEnabled(true);
//Drawer
mDrawerLayout = FindViewById<DrawerLayout>(Resource.Id.drawer_layout);
NavigationView navigationView = FindViewById<NavigationView>(Resource.Id.nav_view);
if(navigationView != null)
{
setUpDrawerContent(navigationView);
}
//Tabs
TabLayout tabs = FindViewById<TabLayout>(Resource.Id.tabs);
ViewPager viewPager = FindViewById<ViewPager>(Resource.Id.viewpager);
setUpViewPager(viewPager);
tabs.SetupWithViewPager(viewPager);
};
}
// What Actually sets my tabs
private void setUpViewPager(ViewPager viewPager)
{
//====================================
//SET THE FRAGMENTS HERE.
//====================================
TabAdapter adapter = new TabAdapter(SupportFragmentManager);
adapter.AddFragment(new Fragment1(), "Inventar");
adapter.AddFragment(new Fragment2(), "Onskeliste");
viewPager.Adapter = adapter;
}
public override bool OnOptionsItemSelected(IMenuItem item)
{
switch (item.ItemId)
{
//Checks if the drawer is opened all the way up
case Android.Resource.Id.Home:
mDrawerLayout.OpenDrawer((int)GravityFlags.Left);
return true;
default:
return base.OnOptionsItemSelected(item);
}
}
private void setUpDrawerContent(NavigationView navigationView)
{
navigationView.NavigationItemSelected += (object sender, NavigationView.NavigationItemSelectedEventArgs e) =>
{
e.MenuItem.SetChecked(true);
mDrawerLayout.CloseDrawers();
};
}
//===================================
// Creating a tab adapter which inherrit from a fragment adaper, is used to adapt the viewpager and tabs together
//===================================
public class TabAdapter : FragmentPagerAdapter
{
public List<SupportFragment> Fragments { get; set; }
public List<string> FragmentNames { get; set; }
public TabAdapter (SupportoFragmentManager sfm) : base (sfm)
{
Fragments = new List<SupportFragment>();
FragmentNames = new List<string>();
}
public void AddFragment(SupportFragment fragment, string name)
{
Fragments.Add(fragment);
FragmentNames.Add(name);
}
public override int Count
{
get
{
return Fragments.Count;
}
}
//Gets the item of the fragemnt at the specific possition
public override SupportFragment GetItem(int position)
{
return Fragments[position];
}
//Sets the title of the fragment
public override ICharSequence GetPageTitleFormatted(int position)
{
return new Java.Lang.String(FragmentNames[position]);
}
}
}`
Fragment 1
public class Fragment1 : SupportFragment
{
public override void OnInflate(Activity activity, IAttributeSet attrs, Bundle savedInstanceState)
{
base.OnInflate(activity, attrs, savedInstanceState);
}
public override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
}
public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
//Inflates the view under the tabs
View view = inflater.Inflate(Resource.Layout.Inventory, container, false);
return view;
}
}
XML Datei
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/scroll2"
android:padding="16dp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FBC855">
<RelativeLayout
android:id="@+id/activity_my_cellar_page"
android:padding="16dp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:focusable="true"
android:focusableInTouchMode="true">
<android.support.design.widget.TextInputLayout
android:layout_below="@+id/signup_color"
android:id="@+id/signup_number"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="@+id/number"
android:hint="Enter the amount of beer"
android:inputType="textCapWords"
android:maxLines="1"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</android.support.design.widget.TextInputLayout>
<LinearLayout
android:layout_below="@+id/signup_number"
android:id="@+id/registration"
android:gravity="center"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:id="@+id/Btn_lagre"
android:text="Lagre"
android:background="#6C2334"
style="@style/Widget.AppCompat.Button.Colored"
android:layout_width="50dp"
android:layout_height="35dp" />
</LinearLayout>
<ListView
android:id="@+id/list_data"
android:layout_below="@+id/registration"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<ProgressBar
android:layout_below="@+id/list_data"
android:id="@+id/circularProgress"
android:visibility="invisible"
android:layout_centerInParent="true"
android:theme="@style/CircularProgress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@style/Widget.AppCompat.ProgressBar" />
<LinearLayout
android:layout_below="@+id/circularProgress"
android:id="@+id/mycellar_inventory3"
android:gravity="center"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<View
android:layout_width="50dp"
android:layout_height="1dp"
android:background="#6C2334"
android:layout_margin="5dp" />
<Button
android:id="@+id/Btn_inventartilbake"
android:text="Tilbake"
android:background="#6C2334"
style="@style/Widget.AppCompat.Button.Colored"
android:layout_width="150dp"
android:layout_height="50dp" />
<View
android:layout_width="50dp"
android:layout_height="1dp"
android:background="#6C2334"
android:layout_margin="5dp" />
</LinearLayout>
</RelativeLayout>
</ScrollView>
Die XML-Datei ist für Ihre Aktivität? –
Ja, die XML Datei ist für meine Aktivität –