【问题标题】:C# Xamarin android Intents and readLine()C# Xamarin android Intents 和 readLine()
【发布时间】:2017-06-03 11:37:42
【问题描述】:

我正在构建琐事应用程序并创建了表单活动问题。

因此,当用户按下右键时,它会重新打开活动。 我希望它会读取下一行而不是相同的行怎么办?

private void ShowQuestion()
{
    string content;
    AssetManager assets = this.Assets;
    StreamReader txt = new StreamReader(assets.Open("Test12.txt"), Encoding.GetEncoding("Windows-1255"));
    StreamReader csv = new StreamReader(assets.Open("Ans12.csv"), Encoding.GetEncoding("Windows-1255"));
    QuestionText.Text = txt.ReadLine();
    Button1.Text = txt.ReadLine();
    Button2.Text = txt.ReadLine();
    Button3.Text = txt.ReadLine();
    Button4.Text = txt.ReadLine();
    answer = csv.ReadLine();
}

private void Button1_Click(object sender, EventArgs e)
{
    if(answer == "א")
    {
        var intent = new Intent(this, typeof(Questions));
        StartActivity(intent);
    }
}

【问题讨论】:

  • 你能解释清楚吗?您有一个读取第一行的活动 A 并使用“右”按钮打开读取第二行的“问题”活动?
  • 活动 A 与活动“问题”是相同的活动,我喜欢打开相同的活动..(最后我只想要与另一个问题相同的活动,我用读取线得到,但现在它只是阅读相同的行)
  • 我认为您不必重新打开相同的活动。如果 A 已打开并且您必须更改“控件”中的值,请设置此值。
  • 怎么样?将函数拆分为仅 readLines 并在每次按下“右”按钮时调用它?

标签: c# android android-intent xamarin xamarin.forms


【解决方案1】:

我认为你可以做类似的事情

    StreamReader txt = new StreamReader(assets.Open("Test12.txt"), Encoding.GetEncoding("Windows-1255"));

    protected override void OnCreate(Bundle bundle)
    {

        // ...

        // First line
        Button1.Text = txt.ReadLine();

    }

    private void Button1_Click(object sender, EventArgs e)
    {

        // other lines
        Button1.Text = txt.ReadLine();

    }

告诉我...

【讨论】:

  • 它太简单了......它是一个琐事应用程序,我有文本视图和 4 个按钮答案......而且我需要从正确的答案文件中读取行,所以我需要所有这些 Button1.Text = txt.ReadLine(); Button2.Text = txt.ReadLine(); Button3.Text = txt.ReadLine(); Button4.Text = txt.ReadLine(); answer = csv.ReadLine(); 需要更新
  • 也是这样,我失去了后退按钮功能,所以我不能回到上一个问题。也许我需要一个滑块......我搜索了很多,它就像 android 在互联网上没有很多信息,比如基本的 c# 和其他语言:(
猜你喜欢
  • 1970-01-01
  • 2011-09-04
  • 1970-01-01
  • 2012-03-17
  • 1970-01-01
  • 1970-01-01
  • 2012-11-29
  • 2011-09-05
  • 1970-01-01
相关资源
最近更新 更多