내 REST에서 오는 N 개의 카테고리가 있습니다. 이 모든 카테고리에 대해 탭을 추가하고 싶습니다. 예를 들어 보자. 내 REST 응답에 두 개의 카테고리 만 있다고 가정하면 두 개의 탭 만 생성됩니다. 5 개의 카테고리가 있고 5 개의 탭이있는 경우 등등. 그리고 각 카테고리 탭에서 선택한 탭 (카테고리)에 대한 내 항목의 목록을로드하십시오. 현재 조각을 사용하여 정적 데이터로 구현했습니다. 각 조각은 항목로드에 대한 목록보기를 사용합니다. 그러나 나는 이것이 옳지 않은 방법이라고 생각합니다.Xamarin.Android의 카테고리를 기반으로 탭을 추가하십시오.
당신은 내가에 사용해야 또는 어떻게 내 카테고리에 따라 탭을 추가 할 수 있으며 각 카테고리 내 목록을로드 걸 제안시겠습니까? Xamarin.android에서 TabLayout을 찾지 못했습니다.
내 홈페이지보기 :
여기<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:minWidth="25px"
android:minHeight="25px">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/fragmentContainer" />
</LinearLayout>
내 주요 활동 : 내 조각보기의
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
// Create your application here
SetContentView(Resource.Layout.MainView);
ActionBar.NavigationMode = ActionBarNavigationMode.Tabs;
AddTab(" Favorite", Resource.Drawable.FavoritesIcon, new FavoriteItemFragment());
AddTab(" Ice", Resource.Drawable.IceCreamIcon, new IceCreamFragment());
AddTab(" Shushi", Resource.Drawable.SushiIcon, new ShushiFragment());
AddTab(" Burger", Resource.Drawable.VeggieLoversIcon, new BurgerFragment());
AddTab(" Biriyani", Resource.Drawable.BiriyaniIcon, new BiriyaniFragment());
AddTab(" Pasta", Resource.Drawable.PastaIcon, new PastaFragment());
AddTab(" Pizza", Resource.Drawable.PizzaIcon, new PizzaFragment());
AddTab(" Sandwich", Resource.Drawable.SandwichIcon, new SandwichFragment());
AddTab(" Coffee", Resource.Drawable.CoffeeIcon, new CoffeeFragment());
//no_of_categories = allCategories.Count;
}
private void AddTab(string tabText, int iconResourceId, Fragment view)
{
var tab = this.ActionBar.NewTab();
tab.SetText(tabText);
tab.SetIcon(iconResourceId);
tab.TabSelected += delegate (object sender, ActionBar.TabEventArgs e)
{
var fragment = this.FragmentManager.FindFragmentById(Resource.Id.fragmentContainer);
if (fragment != null)
{
e.FragmentTransaction.Remove(fragment);
}
e.FragmentTransaction.Add(Resource.Id.fragmentContainer, view);
};
tab.TabUnselected += delegate (object sender, ActionBar.TabEventArgs e)
{
e.FragmentTransaction.Remove(view);
};
this.ActionBar.AddTab(tab);
}
하나 :
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:minWidth="25px"
android:background="#FCD972"
android:minHeight="25px">
<ListView
android:minWidth="25px"
android:minHeight="25px"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/itemListView" />
</LinearLayout>
그리고 내 조각 클래스 :
public override void OnActivityCreated(Bundle savedInstanceState)
{
base.OnActivityCreated(savedInstanceState);
FindViews();
HandleEvents();
items = itemDataService.GetItemsForCategory(4);
listView.Adapter = new ItemListAdapter(this.Activity, items);
}
public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
return inflater.Inflate(Resource.Layout.MyFragment, container, false);
}
당신은
귀하의 제안에 감사드립니다. 귀하의 방법을 시도했지만 주요 문제는 내 프로젝트에 Xamarin.Android.Support.Design 구성 요소를 추가 할 수 없습니다. 오류가 발생합니다 : 'Xamarin.Android.Support.Design 26.0.2'패키지를 설치할 수 없습니다. 'MonoAndroid, Version = v6.0'을 대상으로하는 프로젝트에이 패키지를 설치하려고하지만 해당 프레임 워크와 호환되는 어셈블리 참조 또는 내용 파일이 패키지에 포함되어 있지 않습니다. 자세한 내용은 패키지 작성자에게 문의하십시오. TabLayout 대신 탭 이동을위한 다른 방법이 있습니까? – Russell
@ Russell, 프로젝트의 목표 버전은 무엇입니까? –
Android 버전 (타겟 프레임 워크)을 사용하여 컴파일 Android 6.0 (마쉬 멜 로우) 최소 Android 버전 : Android 5.0 (API 레벨 21- 롤리팝) – Russell