如何在列表视图项中添加复选框?
在我的应用程序中,我在一个活动中使用两个列表视图,一个仅用于项目,一个列表视图我在每一行中添加复选框。 我的要求是在下面的列表视图中,如果选中项目,我必须在主要活动的文本视图上显示(如果不需要显示其他活动)。
我没有为此使用 ListActivity 我只是从 Activity 创建
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:orientation="vertical"
android:layout_weight="0.5"
android:layout_width="fill_parent"
android:layout_height="60px">
<ListView
android:id="@+id/list1"
android:layout_width="fill_parent"
android:layout_weight="0.5"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_weight="0.5"
android:layout_width="fill_parent"
android:layout_height="60px">
<ListView android:id="@+id/list2"
android:layout_width="fill_parent"
android:layout_weight="0.5"
android:layout_height="wrap_content" />
</LinearLayout>
上面的列表视图仅适用于下面的列表视图的项目,我必须添加复选框。我怎样才能做到这一点。
我的活动是..
public class Settings extends Activity {
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.settings);
ListView list1 = (ListView) findViewById(R.id.list1);
ListView list2 = (ListView) findViewById(R.id.list2);
list2.setAdapter(new ArrayAdapter(this,
android.R.layout.simple_expandable_list_item_1, Display));
list2.setTextFilterEnabled(true);
list2.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v,int position, long id) {
}
});
list1.setAdapter(new ArrayAdapter(this, android.R.layout.simple_expandable_list_item_1, Categories));
list1.setTextFilterEnabled(true);
list1.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v,int position, long id) {
}
});
}
static final String[] Categories = new String[] {
"Alarm1","Alarm2","Alarm3","Alarm4","Alarm5"
};
static final String[] Display = new String[] {
"24 Hours","Display Seconds"
};
}
In My application i am using two list view's in one activity, one for only items and one list view i am have add check box in every row.
My requirement is in below list view if item is checked i have to display on text view in the main activity if not have to display another activity .
i was not used ListActivity for this i just created from Activity
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:orientation="vertical"
android:layout_weight="0.5"
android:layout_width="fill_parent"
android:layout_height="60px">
<ListView
android:id="@+id/list1"
android:layout_width="fill_parent"
android:layout_weight="0.5"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_weight="0.5"
android:layout_width="fill_parent"
android:layout_height="60px">
<ListView android:id="@+id/list2"
android:layout_width="fill_parent"
android:layout_weight="0.5"
android:layout_height="wrap_content" />
</LinearLayout>
above list view for only items for below list view i have to add check box. how can i achieve this.
my activity is..
public class Settings extends Activity {
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.settings);
ListView list1 = (ListView) findViewById(R.id.list1);
ListView list2 = (ListView) findViewById(R.id.list2);
list2.setAdapter(new ArrayAdapter(this,
android.R.layout.simple_expandable_list_item_1, Display));
list2.setTextFilterEnabled(true);
list2.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v,int position, long id) {
}
});
list1.setAdapter(new ArrayAdapter(this, android.R.layout.simple_expandable_list_item_1, Categories));
list1.setTextFilterEnabled(true);
list1.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v,int position, long id) {
}
});
}
static final String[] Categories = new String[] {
"Alarm1","Alarm2","Alarm3","Alarm4","Alarm5"
};
static final String[] Display = new String[] {
"24 Hours","Display Seconds"
};
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
那么这里是如何在列表中包含复选框的完整教程。这是关于
ListView
的最佳教程列表活动
。Well here is the Complete Tutorial how you can include CheckBox in a List. Its the Best Tutorial Regarding the
ListView
&ListActivity
.