Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/180.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 在自定义列表视图中,无法获取正确的数据_Android_Listview - Fatal编程技术网

Android 在自定义列表视图中,无法获取正确的数据

Android 在自定义列表视图中,无法获取正确的数据,android,listview,Android,Listview,这里我使用的是一个活动,其中有一个列表视图,我正在填充它 形成一个xml字符串,填充就可以了,在listview中有两个按钮 单击no正在增加和减少的按钮。onsubmit按钮我希望所有 修改后的基准将在提交中显示。例如,选择两个座位2 代码片段是: my xml private static String seatXml="<?xml version=\"1.0\" encoding=\"UTF-8\"?><seatlist>" +"<seats

这里我使用的是一个活动,其中有一个列表视图,我正在填充它 形成一个xml字符串,填充就可以了,在listview中有两个按钮

单击no正在增加和减少的按钮。onsubmit按钮我希望所有 修改后的基准将在提交中显示。例如,选择两个座位2

代码片段是:

my xml 
private static String seatXml="<?xml version=\"1.0\" encoding=\"UTF-8\"?><seatlist>"
        +"<seatselection><seater>two</seater></seatselection>"
        +"<seatselection><seater>four</seater></seatselection>"
        +"<seatselection><seater>six</seater></seatselection>"
        +"<seatselection><seater>eight</seater></seatselection>"
        +"<seatselection><seater>ten</seater></seatselection>"
        +"</seatlist>";
我在这里填充listview

private void populateSeatList() {
    // TODO Auto-generated method stub
    seatItems=new ArrayList<HashMap<String,String>>();
    XMLParser parser=new XMLParser();
    Document doc=parser.getDomElement(seatXml);
    NodeList nl=doc.getElementsByTagName(KEY_RECORD);
    String seatName="";

    for (int i = 0; i < nl.getLength(); i++) {
        map=new HashMap<String, String>();
        Element e=(Element)nl.item(i);
        // adding each child node to HashMap key => value
        map.put(KEY_SEAT,parser.getValue(e, KEY_SEAT)); //this will fetch the seater value like 2 seater,3 seater
        map.put(KEY_SEAT_QTY,""+QTY);
        seatItems.add(map);
    }

    adapter=new SeatAdapter(this, seatItems);
    seatListView.setAdapter(adapter);
    //      makeAToast(seatName);

}
适配器类中的getview函数

int i=0;
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
    // TODO Auto-generated method stub
    View view=convertView;
    if(convertView==null)
        view=inflater.inflate(R.layout.seat_desc,null);
    TextView seatName=(TextView)view.findViewById(R.id.textView_seat_no);
    Button buttonMinus=(Button)view.findViewById(R.id.button_minus);
    Button buttonPlus=(Button)view.findViewById(R.id.Button_plus);
    final TextView seatInput=(TextView)view.findViewById(R.id.textView_seat_input);

    seatInfo=new HashMap<String, String>();
    seatInfo=data.get(position);

    seatName.setText(seatInfo.get(SeatSelectionActivity.KEY_SEAT)+" seater:");
    seatInput.setText(""+i);

    //    menuInfo.get(MenuScreenActivity.KEY_MENUNAME)
    buttonPlus.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated i stub
            i=Integer.parseInt(seatInput.getText().toString());
            if(!(i>=10))
                i++;
            seatInput.setText(""+i);
            //              seatInfo.put(SeatSelectionActivity.KEY_SEAT, seatInfo.get(SeatSelectionActivity.KEY_SEAT));
            seatInfo.put(SeatSelectionActivity.KEY_SEAT_QTY,seatInput.getText().toString());
            data.set(position, seatInfo);
            //              notifyDataSetChanged();

        }
    });

    buttonMinus.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO ,goto-generated method stub
            i=Integer.parseInt(seatInput.getText().toString());
            if(!(i<1))
                i--;
            seatInput.setText(""+i);
            //              seatInfo.put(SeatSelectionActivity.KEY_SEAT, seatInfo.get(SeatSelectionActivity.KEY_SEAT));
            seatInfo.put(SeatSelectionActivity.KEY_SEAT_QTY,seatInput.getText().toString());
            data.set(position, seatInfo);
            //              notifyDataSetChanged();
        }
    });

    return view;
}

我用这个代码得到了我选择的所有座位&它起作用了

buttonPlus.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated i stub
            i=Integer.parseInt(seatInput.getText().toString());
            if(!(i>=10))
                i++;
            seatInput.setText(""+i);

            data.get(position).put(SeatSelectionActivity.KEY_SEAT_QTY, seatInput.getText().toString());

        }
    });