0

在这里,我正在使用一个包含列表视图的活动,我正在从一个 xml 字符串填充它,填充很好,在列表视图中有两个按钮

单击 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>";

在这里我正在填充列表视图

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;
}

如果需要我的示例项目

4

1 回答 1

0

我使用此代码获取所有我选择的座位并且它有效

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());

        }
    });
于 2012-06-08T08:13:14.763 回答