Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/195.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如果选中3个复选框中的任何一个,如何从listview获取数据如何从行获取复选框和文本的值_Android_Listview_Checkbox - Fatal编程技术网

Android 如果选中3个复选框中的任何一个,如何从listview获取数据如何从行获取复选框和文本的值

Android 如果选中3个复选框中的任何一个,如何从listview获取数据如何从行获取复选框和文本的值,android,listview,checkbox,Android,Listview,Checkbox,如何知道选中了哪个复选框,以及如何检索每行的数据并将其保存到文件中 public class MainActivity extends Activity { ArrayList<Inforowdata> rowdata; ArrayList<Inforowdatab> rowdatab; ArrayList<Inforowdatac> rowdatac; ListView l; //String[] data={"Ra

如何知道选中了哪个复选框,以及如何检索每行的数据并将其保存到文件中

public class MainActivity extends Activity {

    ArrayList<Inforowdata> rowdata;
    ArrayList<Inforowdatab> rowdatab;
    ArrayList<Inforowdatac> rowdatac;
    ListView l;
    //String[] data={"Ram", "Shyam", "Deepak", "sabdhs", "dsbndj", "dshg", "dsnd", "dsavg", "dbash", "dbshd", "dshgd", "bsdhgs", "dsgfdsfdgsf", "sda", "sdchb", "AJdfg", "sdfjgh","data" , "sad", "dfax" };;
    String result;
    ArrayList<String> myArray;
    Button b;
    int s;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        l= (ListView)findViewById(R.id.list);

        try {
            File file = new File("/sdcard/report.csv");
            if(!file.exists())
            {

                Toast.makeText(getApplicationContext(), "file Dont Exist", Toast.LENGTH_SHORT).show();
            }
            FileInputStream in = new FileInputStream(file);
            BufferedReader myReader = new BufferedReader(new InputStreamReader(in));
            Toast.makeText(getApplicationContext(), "ok", Toast.LENGTH_SHORT).show();



            l= (ListView)findViewById(R.id.list);
            myArray= new ArrayList<String>();


            try {
                String row;
                while((row= myReader.readLine())!=null)
                {

                    result= Arrays.toString(row.split(",")).replace("[", "").replace("]", "");

                    myArray.add(result);
                    ArrayAdapter<String> a= new ArrayAdapter<String>(getApplicationContext(), R.layout.row,R.id.text,myArray);
                    l.setAdapter(a);

                    //String result=Arrays.toString(row).replace("[", "").replace("]", "").split(",");
                    //resultList.add(data);
                    //resultList.add(result);
                    //myStringArrayList.add(result);
                    //ArrayAdapter<String> adapter= new ArrayAdapter<String>(getApplicationContext(), R.layout.spinner_xml,R.id.name, data);
                    //l.setAdapter(adapter);
                }

                myReader.close();
                //Toast.makeText(getApplicationContext(), s.toString, Toast.LENGTH_SHORT).show();

            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

        } catch (FileNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }


        l.setOnItemClickListener(new OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
                    long arg3) {
                // TODO Auto-generated method stub

            }
        });






    rowdata= new ArrayList<MainActivity.Inforowdata>();
    for(int i=0;i<myArray.size();i++)
    {
        rowdata.add(new Inforowdata(false,i));
    }
    l.setAdapter(new MyAdapter());

    rowdatab= new ArrayList<MainActivity.Inforowdatab>();
    for(int i=0;i<myArray.size();i++)
    {
        rowdatab.add(new Inforowdatab(false,i));
    }
    l.setAdapter(new MyAdapter());

    rowdatac= new ArrayList<MainActivity.Inforowdatac>();
    for(int i=0;i<myArray.size();i++)
    {
        rowdatac.add(new Inforowdatac(false,i));
    }
    l.setAdapter(new MyAdapter())   


}

class Inforowdata{
    public boolean isclicked=false;
    public int index;
    /*public String fanId;
    public String strAmount;*/

    public Inforowdata(boolean isclicked,int index/*,String fanId,String strAmount*/)
    {
        this.index=index;
        this.isclicked=isclicked;
        /*this.fanId=fanId;
        this.strAmount=strAmount;*/
    }
}


class Inforowdatab{
    public boolean isclicked=false;
    public int index;

    public Inforowdatab(boolean isclicked,int index/*,String fanId,String strAmount*/) {
        // TODO Auto-generated constructor stub
        this.index=index;
        this.isclicked=isclicked;
    }
}



class Inforowdatac{
    public boolean isclicked=false;
    public int index;

    public Inforowdatac(boolean isclicked,int index/*,String fanId,String strAmount*/) {
        // TODO Auto-generated constructor stub
        this.index=index;
        this.isclicked=isclicked;
    }
}
cbb.setOnClickListener(新的OnClickListener(){

cbc.setOnClickListener(新的OnClickListener(){


要从列表中获取所有数据

您需要将全局适配器创建为

MyAdapter mAdapter;
onClick
事件按钮,按以下代码获取所有数据

for(Inforowdata row : mAdapter){
              //All rows adata here....
           }


尝试从ListView的监听器获取行值您将获得所选行的所有数据我想在单击按钮时保存所有行的数据。那么如何从每个行获取数据呢row@Ish这里我没有选择任何一行,我试图获取所有行的数据,包括每行中选中的复选框的文本和值每行中的复选框!!我想..当你点击按钮时,你想检索选中复选框的listview..这是你的要求吗?@RiggsFolly但我试图在点击提交按钮时保存所有数据,而不是通过setOnItemClickListener..我没有回答问题,我只是整理了一些Skruff代码布局。请与我联系@Ish@user2589011我编辑了我的答案,检查一下,如果您不想将适配器声明为公共的,那么您可以使用lsitView方法getItemAtPos(pos)设置适配器l.setAdapter(new MyAdapter());在单列表视图中的活动中三次,,,只有最后一次会反映前两次不影响代码,请解释这些行
        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
        if(rowdatac.get(position).isclicked)
        {
            rowdatac.get(position).isclicked=false;
        }
        else
            rowdatac.get(position).isclicked=true;
    }}
    );

    if (rowdatac.get(position).isclicked) {

        cbc.setChecked(true);
    }
    else {
        cbc.setChecked(false);
    }
    b= (Button)findViewById(R.id.button1);

    return row;
    }
}
MyAdapter mAdapter;
for(Inforowdata row : mAdapter){
              //All rows adata here....
           }
for(int pos=0;mAdapter.getItemCount()-1;pos++)
     mAdapter.getItem(pos)//All rows adata here....