我正在尝试在我的可穿戴应用程序中显示一个2行列表视图,如下图中的那个(没有图标),但由于某种原因,它没有按预期工作。我认为问题在于以下代码行:
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>
答案 0 :(得分:-1)
在ListViewItem.java&#39;中查看你的构造函数,应该很明显已经设置了什么。已设置text0
和text1
,然后您的列表适配器正在使用列表中的这些值。