- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在开发适用于 Android 的应用程序,但遇到困难,我已经制作了一个可扩展列表,其中的子项是复选框。此 Activity 从 sql 数据库获取信息,唯一的问题是我不知道如何在按下确认按钮后获取选中了哪些复选框。
我的意思是我只想获取选中的每个复选框的文本或 ID,这样我就可以创建一个数组,然后将该信息放在数据库中的一个表中。
这是我的 Activity :
import java.util.ArrayList;
import android.os.Bundle;
import android.app.Activity;
import android.content.DialogInterface;
import android.view.View.OnClickListener;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.graphics.Point;
import android.util.Log;
import android.view.Display;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.ExpandableListView;
import android.widget.Toast;
public class ManualQuestionnerActivity extends Activity implements OnClickListener{
/*Variable de la Base de Datos*/
protected DBHelper _db_helper;
protected SQLiteDatabase _db;
protected ExpandableListView _expandableList_seccion;
protected Button _button_confirm;
protected CheckBox _checkbox_child;
int _id_company, _id_branch, _id_area,_id_subarea,_id_type,_id_questionner;
String _string_timestarter;
/**/
private ExpandListAdapter _expandList_Adapter;
private ArrayList<ExpandListGroup> _expandList_Items;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_manual_questionner);
Intent i = getIntent();
/*inicializando las variables con valores de la base de datos*/
_id_company = i.getIntExtra("company", 0);
_id_branch = i.getIntExtra("branch", 0);
_id_area = i.getIntExtra("area", 0);
_id_subarea = i.getIntExtra("subarea", 0);
_id_type = i.getIntExtra("type", 0);
_id_questionner = i.getIntExtra("questionner", 0);
_string_timestarter = i.getStringExtra("inicio");
_expandableList_seccion = (ExpandableListView) findViewById(R.id.manual_questionner_expandablelistview);
_button_confirm = (Button) findViewById(R.id.manual_questionner_button_confirm);
_button_confirm.setOnClickListener(this);
_checkbox_child = (CheckBox) findViewById(R.id.tvChild);
//Log.w("LLEEEEEGOOOOOO", Integer.toString(seriesId));
/*Creando la BD*/
try
{
_db_helper = new DBHelper(getApplicationContext());
_db_helper.createDataBase();
}
catch (Exception e)
{
Toast.makeText(this, "FAVOR DE CONTACTAR AL ADMINISTRADOR: error_#000", Toast.LENGTH_LONG).show();
}
/*Se abre la Base de Datos*/
try
{
_db_helper.openDataBase();
_db = _db_helper.getReadableDatabase();
}
catch (Exception e)
{
Toast.makeText(this, "FAVOR DE CONTACTAR AL ADMINISTRADOR: error_#001", Toast.LENGTH_LONG).show();
}
_expandList_Items = SetStandardGroups();//llenando la expandable list
_expandList_Adapter = new ExpandListAdapter(ManualQuestionnerActivity.this, _expandList_Items);
_expandableList_seccion.setAdapter(_expandList_Adapter);
}
public ArrayList<ExpandListGroup> SetStandardGroups() {
final String [] ia ={"ia"};
Cursor cursor_seccion = _db.query("i", ia, "ib = '" + _id_questionner + "'", null, null, null, null, null);
cursor_seccion.moveToFirst();
ArrayList<ExpandListGroup> list = new ArrayList<ExpandListGroup>();
do{
ArrayList<ExpandListChild> list2 = new ArrayList<ExpandListChild>();
ExpandListGroup gru1 = new ExpandListGroup();
gru1.setName(cursor_seccion.getString(0));
/*temas*/
final String [] _id = {"_id"};
Cursor cursor_seccion_id = _db.query("i", _id, "ia = '"+cursor_seccion.getString(0)+"'", null,null,null,null,"1");
cursor_seccion_id.moveToFirst();
int value = Integer.parseInt(cursor_seccion_id.getString(0));
/*preguntas*/
final String[] ja = {"ja"};
Cursor cursor_question = _db.query("j",ja,"jb = '"+value+"'",null,null,null,null,null);
cursor_question.moveToFirst();
Log.w("HOLAAAAAA",Integer.toString(cursor_question.getCount()));
Log.w("HOLAAAAAA",cursor_question.getString(0));
do
{
ExpandListChild ch1_1 = new ExpandListChild();
ch1_1.setName(cursor_question.getString(0));//
ch1_1.setTag(null);
list2.add(ch1_1);
}while(cursor_question.moveToNext());
gru1.setItems(list2);
list.add(gru1);
}while(cursor_seccion.moveToNext());
return list;
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.manual_questionner, menu);
return true;
}
/*
public void onCheckboxClicked(View view)
{
if(_checkbox_child.isChecked() == true)
{
Log.w("SE PUSHOOOOO",":D");
}
else
{
Log.w("SE DESPUCHOOOOOOO","D:");
}
}
*/
public void onClick(View v)
{
if(v.getId()== R.id.manual_questionner_button_confirm)
{
Toast.makeText(getApplicationContext(), "Guardando Datos.", Toast.LENGTH_SHORT).show();
Intent home = new Intent(this, HomeActivity.class);
startActivity(home);
}
}
}
这是我的可扩展列表 Activity
import java.util.ArrayList;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.CheckBox;
import android.widget.TextView;
public class ExpandListAdapter extends BaseExpandableListAdapter {
private Context context;
private ArrayList<ExpandListGroup> grupos;
public ExpandListAdapter(Context context, ArrayList<ExpandListGroup> grupos)
{
this.context=context;
this.grupos = grupos;
}
public void addItem(ExpandListChild item, ExpandListGroup group)
{
if(!grupos.contains(group))
{
grupos.add(group);
}
int index = grupos.indexOf(group);
ArrayList<ExpandListChild> ch = grupos.get(index).getItems();
ch.add(item);
grupos.get(index).setItems(ch);
}
@Override
public Object getChild(int groupPosition, int childPosition) {
// TODO Auto-generated method stub
ArrayList<ExpandListChild> chList = grupos.get(groupPosition).getItems();
return chList.get(childPosition);
}
@Override
public long getChildId(int groupPosition, int childPosition) {
// TODO Auto-generated method stub
return childPosition;
}
@Override
public View getChildView(int groupPosition, int childPosition,
boolean isLastChild, View view, ViewGroup parent) {
// TODO Auto-generated method stub
ExpandListChild child = (ExpandListChild) getChild(groupPosition,childPosition);
if(view == null)
{
LayoutInflater infalInflater=(LayoutInflater) context.getSystemService(context.LAYOUT_INFLATER_SERVICE);
view = infalInflater.inflate(R.layout.expandlist_child_item, null);
}
CheckBox tv = (CheckBox) view.findViewById(R.id.tvChild);
tv.setText(child.getName().toString());
tv.setTag(child.getTag());
return view;
}
@Override
public int getChildrenCount(int groupPosition) {
// TODO Auto-generated method stub
ArrayList<ExpandListChild> chList = grupos.get(groupPosition).getItems();
return chList.size();
}
@Override
public Object getGroup(int groupPosition) {
// TODO Auto-generated method stub
return grupos.get(groupPosition);
}
@Override
public int getGroupCount() {
// TODO Auto-generated method stub
return grupos.size();
}
@Override
public long getGroupId(int groupPosition) {
// TODO Auto-generated method stub
return groupPosition;
}
@Override
public View getGroupView(int groupPosition, boolean isExpanded,
View view, ViewGroup parent) {
// TODO Auto-generated method stub
ExpandListGroup group = (ExpandListGroup) getGroup(groupPosition);
if(view == null)
{
LayoutInflater inf = (LayoutInflater) context.getSystemService(context.LAYOUT_INFLATER_SERVICE);
view = inf.inflate(R.layout.expandlist_group_item, null);
}
TextView tv = (TextView) view.findViewById(R.id.tvGroup);
tv.setText(group.getName());
return view;
}
@Override
public boolean hasStableIds() {
// TODO Auto-generated method stub
return true;
}
enter code here
@Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
// TODO Auto-generated method stub
return true;
}
}
最佳答案
您可以将复选框值保存在 HashMap 中。
public class ExpandListAdapter extends BaseExpandableListAdapter {
private Context context;
private ArrayList<ExpandListGroup> grupos;
HashMap<String, Boolean> mCheckBoxData = new HashMap<String, Boolean>();
.....
}
在您的 getChildView 函数中,在复选框上设置一个 CheckedChange 监听器,并将复选框标记及其值放入 HashMap 中。
@Override
public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View view, ViewGroup parent) {
final ExpandListChild child = (ExpandListChild) getChild(groupPosition,childPosition);
if(view == null){
LayoutInflater infalInflater=(LayoutInflater) context.getSystemService(context.LAYOUT_INFLATER_SERVICE);
view = infalInflater.inflate(R.layout.expandlist_child_item, null);
}
CheckBox checkBoxChild = (CheckBox)view.findViewById(R.id.checkbox_child);
checkBoxChild.setText(child.getName().toString() );
checkBoxChild.setTag(child.getTag());
checkBoxChild.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton arg0, boolean value) {
mCheckBoxData.put(child.getTag(), value);
}
});
return view;
}
// ExpandListAdapter's getCheckBoxData method
public HashMap<String, Boolean> getCheckBoxData(){
return mCheckBoxData;
}
确认按钮:
public void onClick(View v)
{
if(v.getId()== R.id.manual_questionner_button_confirm)
{
Toast.makeText(getApplicationContext(), "Guardando Datos.", Toast.LENGTH_SHORT).show();
//Intent home = new Intent(this, HomeActivity.class);
//startActivity(home);
HashMap<String, Boolean> checkBoxData = _expandList_Adapter.getCheckBoxData();
// Get the keys
Set<String> keys = checkBoxData.keySet();
for (String key : keys) {
Log.d("LOG", key + "=" + checkBoxData.get(key));
}
}
}
关于android - 如何知道从可扩展 ListView 中选中了哪个复选框并获取其信息(Android),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16501933/
我在字符串中有一个大词。例子白 Wine 额外优惠。 我想在第一行使用“White”,在第二行使用“wine extra offer”。使用下面的代码: string value="White win
我想在无符号中执行一些算术运算,需要取负整数的绝对值,比如 do_some_arithmetic_in_unsigned_mode(int some_signed_value) { unsign
我正在努力使用 data.table 来总结向量函数的结果,这在 ddply 中很容易。 问题 1:使用带有矢量输出的(昂贵的)函数聚合 dt dt[ , as.list(quantile(x)),
我有两个分数列表; 说 A = [ 1/212, 5/212, 3/212, ... ] 和 B = [ 4/143, 7/143, 2/143, ... ] . 如果我们定义 A' = a[0] *
我已经使用 numpy 从 csv 文件中获取数据。 numpy 数组的尺寸为:100*20。我如何取列的平均值(比如 col 3,5,8)并用包含这 3 个 cols 平均值的新列替换它们 如果
在 Rust 中取任意数的 n 次根的最佳方法是什么?例如,num crate 只允许取整数类型的第 n 个主根,即 floor'ed 或 ceil'ed 值......如何最好地接近实际值? 最佳答
看起来这应该很容易,但我很困惑。我已经掌握了使用 dplyr 进行编程的大致技巧0.7,但为此苦苦挣扎:How do Iprogram in dplyr我想要编程的变量是否是一个字符串? 我正在抓取数
在 Rust 中取任意数的 n 次根的最佳方法是什么?例如,num crate 只允许取整数类型的第 n 个主根,即 floor'ed 或 ceil'ed 值......如何最好地接近实际值? 最佳答
我有一个 pandas 数据框,其中有一列名为“coverage”。对于一系列特定索引值,我想获取前 100 行的平均“覆盖率”值。例如,对于索引位置 1001,我想要第 901-1000 行的平均“
import pandas as pd data = {'date': ['1998-03-01', '2001-04-01','1998-06-01','2001-08-01','2001-05-0
我有一个包含 100 个数字的 NSArray。我想创建一个 5 个数字的 NSArray。第二个数组中的第一个数字是第一个数组中前 20 个数字的平均值。第二个数字是第一个数组中第二组 20 个数字
我该怎么做?我试过 abs() 但它只适用于整数。有内置的方法吗? CGFloat flo = -123; abs(flo) 返回 0 最佳答案 使用 fabs() CGFloat f = -123.
我正在采用以下计算的 log2: tl_out.a.bits.size := log2Ceil(s1_row * s2_column * 4.U) 其中,s1_row 和 s2_column 是 UI
如何从 m 个元素集合中取出 n 个元素,以便在元素用完时从头开始? List list = new List() {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; List newL
我已经完成了研究,但似乎找不到有关该主题的足够文档。 在 Object streams 上尝试一些代码时,我注意到将 BufferedOutputStream 放入 ObjectOutputStrea
我需要计算数据中连续时间组之间的差异,如下所示 from io import StringIO import pandas as pd strio = StringIO("""\
我在 Mongo 数据库中有以下文档: { _id: 1, question: "Blue or red?", __v: 0, votes: [9, 5] } 我想在后
好吧,宇宙中一定有人知道这个问题的答案。 我已经在这里问过这个问题,但仍然没有解决方案。 我需要保留和换行 div 中的文本。到目前为止,我很难想出解决方案。我找到的最佳解决方案并不适用于所有浏览器。
我正在尝试采用 3 个单独的整数输入(年、月、日)并采用这 3 个条目并从中形成一个日期对象,以便我可以使用它来比较其他日期。 这是我目前所拥有的,不知从何而来: public void compar
在我的 IOS 项目中,我有一个包含该函数的自定义 Logger 类(单例) - (void)log:(NSString *)domain logLevel:(int)level logMessage
我是一名优秀的程序员,十分优秀!