gpt4 book ai didi

java - 2 行 WearableListView 无法正常工作

转载 作者:行者123 更新时间:2023-12-01 06:08:19 26 4
gpt4 key购买 nike

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

ListViewItem androiders = new ListViewItem();

括号之间需要添加一些内容,因为当没有内容时,会返回以下错误。

ListViewItem (String) in ListViewItem cannot be applied to ()

我尝试了一些选项,但没有一个起作用。

选项A

ListViewItem androiders = new ListViewItem("");

enter image description here

选项B

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

enter image description here

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

预期结果 enter image description here

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>

最佳答案

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

关于java - 2 行 WearableListView 无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40327738/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com