【问题标题】:2-line WearableListView not working properly2 行 WearableListView 无法正常工作
【发布时间】:2016-10-30 09:40:14
【问题描述】:

我正在尝试在我的可穿戴应用程序中显示一个两行列表视图,如下图所示(没有图标),但由于某种原因它没有按预期工作。我认为问题在于以下代码行:

ListViewItem androiders = new ListViewItem();

需要在括号之间插入一些内容,因为如果没有任何内容,则会返回以下错误。

ListViewItem中的ListViewItem(String)不能应用于()

我尝试了一些选项,但都没有奏效。

选项 A

ListViewItem androiders = new ListViewItem("");

选项 B

ListViewItem androiders = new ListViewItem("hello world");

有谁知道括号之间应该放什么来解决这个问题?

预期结果

MainActivity.java

public class MainActivity extends Activity implements WearableListView.ClickListener{


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        initialize();
    }

    List<ListViewItem> list = new ArrayList<>();
    private void initialize() {
        String[] items = getResources().getStringArray(R.array.versions_array);
        String[] itemDescriptions = getResources().getStringArray(R.array.years_array);
        for (int n = 0; n < items.length; n++){
            ListViewItem androiders = new ListViewItem(?);
            androiders.setID();
            androiders.setVersion(items[n]);
            androiders.setYear(itemDescriptions[n]);
            list.add(androiders);
        }

        WearableListView wearableListView = (WearableListView) findViewById(R.id.wearable_list_view);
        ListViewAdapter mAdapter = new ListViewAdapter(this, list);
        wearableListView.setAdapter(mAdapter);
        wearableListView.setClickListener(this);
        wearableListView.addOnScrollListener(mOnScrollListener);
    }
}

ListViewItem.java

public class ListViewItem {

    public String text0;
    public String text1;
    private String version;
    private String year;

    public ListViewItem(String text) {
        this.text0 = text;
        this.text1 = text;
    }

    public String getVersion(){
        return version;
    }

    public void setVersion(String version){
        this.version = version;
    }

    public String getYear(){
        return year;
    }

    public void setYear(String year){
        this.year = year;
    }

    private int _id;
    public void getID(int _id){
        this._id = _id;
    }

    public int setID(){
        return _id;
    }
}

strings.xml

<resources>
    <!--Versions strings-->
    <string name="jellybean">Jelly Bean</string>
    <string name="kitkat">KitKat</string>
    <string name="lollipop">Lollipop</string>
    <string name="marshmallow">Marshmallow</string>
    <string name="nougat">Nougat</string>

    <!--Years strings-->
    <string name="released_2012">Released: 2012</string>
    <string name="released_2013">Released: 2013</string>
    <string name="released_2014">Released: 2014</string>
    <string name="released_2015">Released: 2015</string>
    <string name="released_2016">Released: 2016</string>

    <!--Versions array-->
    <string-array name="versions_array">
        //item 1    <item>@string/jellybean</item>
        //item 2    <item>@string/kitkat</item>
        //item 3    <item>@string/lollipop</item>
        //item 4    <item>@string/marshmallow</item>
        //item 5    <item>@string/nougat</item>
    </string-array>

    <!--Years array-->
    <string-array name="years_array">
        //item 1    <item>@string/released_2012</item>
        //item 2    <item>@string/released_2013</item>
        //item 3    <item>@string/released_2014</item>
        //item 4    <item>@string/released_2015</item>
        //item 5    <item>@string/released_2016</item>
    </string-array>

</resources>

【问题讨论】:

    标签: java android xml listview wear-os


    【解决方案1】:

    查看'ListViewItem.java' 中的构造函数,应该很明显设置了什么。 text0text1 已设置,那么您的列表适配器正在使用列表中的这些值。

    【讨论】:

    • hello world 按预期出现 public ListViewItem(String text) { this.text0 = text; this.text1 = 文本; } hello world 是文本 0 和 1
    • 我已经知道“hello world”,但我不是指那个。我指的是我的数组中的项目,因为它们没有按预期显示。您之前评论中的代码是建议吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-02-20
    • 2012-08-06
    • 2015-02-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多