通过代码添加多个标签

时间:2017-12-20 06:28:09

标签: c# xaml xamarin xamarin.forms

我在Visual Studio中使用Xamarin编写社交网络应用程序,这是一个带有Android和iOS项目的便携式项目。

当MainPage类导航到它时,它会打开一个URL并读取页面并将其保存为字符串。我需要它在每个“
”分开。我想我应该使用for循环,但我不知道接下来该做什么。我希望每个块都有自己的布局框,我还没有学习使用哪种布局以及每种布局最适合的布局。在每个框中,它将有一个标签(内容)和可能的图像(如果帖子附带一个,它将是一个URL,因此它将打开URL并显示该图像)

基本上每个人都希望能够编辑以下内容

for(string chunk : data.split("<br/">){
    <Layout?>
    <label Text="*Content from the current chunk*"/>
    if(*contains image*){
    <image>*Open url and display the image*</image>
    }
    </Layout?>
}

这也都在scrollview中,所以它们都在一起滚动......

1 个答案:

答案 0 :(得分:1)

解析未显示的块字符串。

MainPage.xaml中:

Collection<Optional<T>> source;
// ...
List<T> dst = source.stream()
        .flatMap(optionalPresent())
        .collect(Collectors.toList());

MainPage.xaml.cs中:

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:local="clr-namespace:StackOverflow1"
             x:Class="StackOverflow1.MainPage"
             Appearing="ContentPage_Appearing">    
    <ScrollView>
        <StackLayout x:Name="mainStackLayout" />
    </ScrollView>
</ContentPage>