【发布时间】:2016-03-21 20:09:06
【问题描述】:
我有一个包含玩家列表的活动。该列表包含所有玩家的姓名。我想为每个名称提供一个微调器,其中包含“删除”、“评价为最佳”等选项。 我已经创建了列表,但无法添加带有特定选项集的微调器。
我的代码是。
public class AddPlayerActivity extends AppCompatActivity {
@InjectView(R.id.players_listView)
ListView playersListView;
// Adapter for playersListView
private ArrayAdapter<String> playersArrayAdapter;
// Array of the players to be loaded in the list view
String[] players = {"ABC", "XYZ", "MNO", "GHI"};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_add_player);
ButterKnife.inject(this);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
// Initializing array adapter
playersArrayAdapter = new ArrayAdapter<>(this, R.layout.players_name, players);
playersListView.setAdapter(playersArrayAdapter);
playersListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
}
});
}
}
activity_add_player.xml 是-
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:showIn="@layout/activity_add_player">
<ListView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="4"
android:id="@+id/players_listView"
android:choiceMode="singleChoice"/>
</LinearLayout>
【问题讨论】:
-
players_name.xml 中有 spinner 组件吗?而不是使用默认适配器编写 customAdapter 并根据需要使用它。
-
在每一行看到这个链接stackoverflow.com/questions/15002821/…你可以添加sipner
-
创建一个布局,它将在 LinearLayout 中包含 TextView 和 Spinner(方向:水平)。然后使用将扩展 BaseAdapter 的自定义适配器。现在在你的适配器中扩展这个布局。查看此示例以了解如何使用自定义适配器:androidadapternotifiydatasetchanged.blogspot.in
-
使用列表视图的自定义适配器为每个列表项添加微调器对您有好处。