我在android上使用listView小部件,并在预览列表内容中选择了“检查列表”项目 基本上它是一个项目列表,我应该能够检查一些项目,当我做的项目旁边的复选标记变得可见(这不是一个复选框,这是许多其他可检查列表之间的区别) 我不知道如何使用它,我想知道至少我怎么能检查一些项目,也就是使复选标记可见,因为当我点击一个项目,它是可以点击,但没有任何反应......如何在android上设置检查列表项目列表视图
image of listview in simulator
这里是我的xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:rsb="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context=".MainActivity"
android:background="#fffefdff">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="540dp"
android:weightSum="1"
android:id="@+id/linearLayoutPreferences"
android:layout_alignParentBottom="true"
android:layout_alignParentStart="true"
android:focusableInTouchMode="false"
android:divider="#ff080808"
android:dividerPadding="@dimen/activity_horizontal_margin"
android:showDividers="middle|beginning|end">
<ListView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/listView"
tools:listitem="@android:layout/simple_list_item_checked"
android:clickable="true"
android:fastScrollAlwaysVisible="false"
android:choiceMode="multipleChoice"
android:contextClickable="false" />
</LinearLayout>
这里是我的java文件
public class Popneighbourhood extends AppCompatActivity {
ListView listNeighbourhood;
String[] neighbourhood = new String[]{
"Alamo Square/NOPA", "Castro/Upper Market", "Central Richmond", "Cole Valley/Ashbury Heights", "Downtown/Civic/Van Ness", "Duboce Triangle",
"Financial District", "Glen Park", "Haight Ashbury", "Hayes Vallez", "Ingleside/SFSU/CCSF", "Inner Richmond",
"Inner Sunset/UCSF", "Jordan Park/Laurel Heights", "Laurel Heights/Presidio", "Lower Haight", "Lower Nob Hill", "Lower Pac Heights",
"Marina/Cow Hollow", "Mission Bay", "Mission District", "Nob Hill", "Noe Valley", "North Beach/Telegraph Hill",
"Oakland North/Temescal", "Pacific Heights"
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_popneighbourhood);
ActionBar actionBar=getSupportActionBar();
actionBar.setDisplayShowHomeEnabled(true);
actionBar.setIcon(R.mipmap.logofrontdoor);
listNeighbourhood = (ListView) findViewById(R.id.listView);
//android.R.layout.simple_list_item_1 est une vue disponible de base dans le SDK android,
//Contenant une TextView avec comme identifiant "@android:id/text1"
ArrayAdapter<String> adapter = new ArrayAdapter<String>(Popneighbourhood.this,
android.R.layout.simple_list_item_1, neighbourhood);
listNeighbourhood.setAdapter(adapter);
谢谢你,我已经改变了属性,在模拟器上,我现在可以选择不同的项目,我该如何处理这些项目,我想知道如何获得所选项目的计数......函数getCheckedItemCount不会返回任何东西,看起来好像检查标记只是图像的存在,但它们不被识别......我对此很新,而且我很难用这个列表视图 – Arthur
I'好吧,没关系:)谢谢你的帮助 – Arthur