【问题标题】:Android - Sorting TextView with another Java classAndroid - 使用另一个 Java 类对 TextView 进行排序
【发布时间】:2014-02-12 09:10:43
【问题描述】:

我想在一个活动中对一些 TextView 进行排序,该活动抽象了一个我已经创建的类,其中有我的排序方法,那么排序的结果必须写入一个新的 TextView .

编辑: 我的 TextViews 的内容是数字,现在我想对这些数字进行排序,排序的结果必须写在一个新的 TextView 中。

例如:

TextView1 内容:23

TextView2 内容:41

TextView3 内容:3

TextView4(将包含排序规则):3、23、41

【问题讨论】:

  • 对不起,您需要对 textView 中的文本进行排序还是重新排列您的 textView
  • 你的问题很模糊。请尝试添加更多详细信息。
  • 请在此处粘贴您的代码。您是否使用 list Array 对文本视图进行排序。你想在 textview 中安排什么文本?它的 wiered 问题
  • 我有一些TextView要排序,这个排序的结果要写在一个新的TextView里面,希望已经清楚了
  • 您不能对 textView 进行排序,而是对里面的整数进行排序。使用 textView.getText()、Integer.parseInt()、ArrayList 存储 textViews 和 Collections.sort() 的值。

标签: java android sorting textview


【解决方案1】:

假设我正确理解了您的问题,这应该对您有用:

List<Integer> data = new ArrayList<Integer>();
data.add(Integer.parseInt(TextView1.getText().toString()));
data.add(Integer.parseInt(TextView2.getText().toString())); 
data.add(Integer.parseInt(TextView3.getText().toString()));
Collections.sort(data);
TextView4.setText(data.toString());

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-14
    • 2015-04-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多