Skip to content

Instantly share code, notes, and snippets.

View TheBaileyBrew's full-sized avatar
⌨️
Coding

TheBaileyBrew TheBaileyBrew

⌨️
Coding
  • Grand Rapids, MI
View GitHub Profile
@TheBaileyBrew
TheBaileyBrew / fragment.xml
Created June 5, 2018 16:41
Array Adapter Access
public class FragmentName extends Fragment {
ArrayList<songItem> SongItems;
ArrayList<genreItem> GenreItems;
public View onCreateView (LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
final View view = inflater.inflate(R.layout.fragment_name, container, false);
songArrayList songs = new songArrayList();
SongItems = songs.getSongList();
GenreItems = songs.getGenreList();
public class LocationDetailActivity extends AppCompatActivity {
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.location_detail);
//This is where you'll get the Intent extras
//Then you'll want to assign those strings and integer values to your TextViews, ImageViews just like you would with any other activity.
//Okay so this is the basic concept I used in my Now Playing activity.
//Essentially we want to get the current index of the selected song in the Arraylist
//Then create a temporary reference and either add to it or subract from it
//And then refresh the TextViews based on the new position in the ArrayList
//First things first, make sure you have global variables for your TextViews and your ArrayList itself.
ArrayList<songs> SongItems = new ArrayList<>();
//This is called after using .setOnClickListener(this) -- and implementing View.OnClickListener on my public class
@Override
if (mCurrentBookUri == null) {
Toast.makeText(this,getString(R.string.not_save_msg), Toast.LENGTH_SHORT).show();
}
if (TextUtils.isEmpty(nameString)){
Toast.makeText(this, getString(R.string.enter_name_req),Toast.LENGTH_SHORT).show();
return;
}
if (TextUtils.isEmpty(priceString)){
Toast.makeText(this, getString(R.string.enter_price_req),Toast.LENGTH_SHORT).show();
return;
@TheBaileyBrew
TheBaileyBrew / ShellFlyoutCreation
Created June 5, 2019 19:40
Creating FlyoutItems Dynamically in Xamarin.Forms Shell
//I actually have this separated out into a model class, but it could technically be internal like this
internal class NavigationItem {
public string Title { get; set; } ////This pairs with ShellItem.Title
public DataTemplate Template { get; set; } ////This pairs with ShellItem.ContentTemplate
public ImageSource Image { get; set; } ////This pairs with ShellItem.Icon
public string Route { get; set; } ////This pairs with ShellItem.Route
public List<ShellContent> Tabs { get; set; } ////This pairs with ShellItem.Tab
public bool HasImage => Image != null; ////These are optional, and just for validation purpose
public bool HasNavigation => Template != null; ////These are optional, and just for validation purpose
<Shell.ItemTemplate>
<DataTemplate>
<ContentView>
Bindable Properties: Title, Icon
</ContentView>
</DataTemplate>
</Shell.ItemTemplate>
public class NavigationFlyoutItemTemplateSelector : DataTemplateSelector
{
public DataTemplate NavigationHeaderTemplate { get; set; }
public DataTemplate NavigationItemTemplate { get; set; }
protected override DataTemplate OnSelectTemplate(object item, BindableObject container)
{
//Returning null, because at this point I'm not sure how to select the correct template
return null;
}
<Style x:Key="FlyoutHeaderStyle" TargetType="Label">
<Setter Property="FontSize" Value="Default" />
<Setter Property="Margin" Value="15,0" />
<Setter Property="TextColor" Value="Black" />
<Setter Property="FontAttributes" Value="Bold" />
<Setter Property="HorizontalOptions" Value="Start" />
</Style>
<Style x:Key="FlyoutItemStyle" TargetType="Label">
<Setter Property="FontSize" Value="Default" />
<Shell
...
ItemTemplate="{StaticResource FlyoutTemplateSelector}"
... >
protected override DataTemplate OnSelectTemplate(object item, BindableObject container)
{
// Returning something like this will look at the route declaration and determine if it's a header or item
return ((FlyoutItem)item).Route.StartsWith("Header") ? NavigationHeaderTemplate : NavigationItemTemplate;
}