0

我正在膨胀passenger_details_layoutin 。在main_passenger_details_layout运行时,我正在设置 TextView 中的值。我正在设置pax_id对于我在其中充气的每一行都是不可见的。因此,在单击乘客详细信息布局时,我想调用一个新活动并将其传递pax_id给新活动。 Pax_id每次 for 循环运行时都会像 1,2,3。所以点击 1 行我想获得pax_id我设置的第一行。

请帮助我怎么能做到这一点将非常感谢你。

充气代码

ItinResponse data = obj.parseXMLData(fXmlFile);
        List<SectorRecords> sectorList = data.getSectorRecordsDetails();
        int items = 0;
        List<PassengerDetails> listdata = data.getPaxDetails();
        int i = 0;
        for (PassengerDetails elements : listdata) {
            inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            RelativeLayout layout = (RelativeLayout) inflater.inflate(
                    R.layout.passenger_details_layout, main, false);
            firstName = (TextView) layout.findViewById(R.id.first_pax_name);
            pax_id = (TextView) layout.findViewById(R.id.pax_id);
            firstName.setText(elements.getFirstName() + " "
                    + elements.getLastName());
            pax_id.setText(elements.getPaxId());
            main.addView(layout, i);
            i++;


 layout.setOnClickListener(new OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        Toast.makeText(getApplicationContext(), "this is my Toast message!!! =)"+pax_id.getText(), Toast.LENGTH_LONG).show();

                    }
                });

在每一行上都显示最后一个 pax id

4

5 回答 5

1

你不必做任何你正在尝试的事情

替换这个

pax_id.setText(elements.getPaxId());

layout.setId(Integer.parseInt(elements.getPaxId()));

并在您的布局中单击

layout.setOnClickListener(new OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        Toast.makeText(getApplicationContext(), "this is my Toast message!!! =)"+layout.getId(), Toast.LENGTH_LONG).show();
                    }
                });

每次你都会得到你想要设置的唯一 ID

一切顺利...!!!!

于 2013-09-20T12:00:35.720 回答
0
// try this
        ItinResponse data = obj.parseXMLData(fXmlFile);
        List<SectorRecords> sectorList = data.getSectorRecordsDetails();
        int items = 0;
        List<PassengerDetails> listdata = data.getPaxDetails();
        int i = 0;
        for (PassengerDetails elements : listdata) {
            inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            RelativeLayout layout = (RelativeLayout) inflater.inflate(
                    R.layout.passenger_details_layout, main, false);
            firstName = (TextView) layout.findViewById(R.id.first_pax_name);
            pax_id = (TextView) layout.findViewById(R.id.pax_id);
            firstName.setText(elements.getFirstName() + " "
                    + elements.getLastName());
            pax_id.setText(elements.getPaxId());
            layout.setTag(elements);
            main.addView(layout, i);
            i++;


            layout.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    PassengerDetails elements = (PassengerDetails) v.getTag();
                    Toast.makeText(getApplicationContext(), "this is my Toast message!!! =)"+elements.getPaxId(), Toast.LENGTH_LONG).show();

                }
            });
        }
于 2013-09-20T09:50:00.290 回答
0

利用

TextView paxView = (TextView)v.findViewById(R.id.pax_id);
String pax_value = paxView.getText().toString();
于 2013-09-20T09:41:04.090 回答
0

在每一行的按钮单击上都这样做

Intent intent=new Intent(this,YOUR_NEXT_ACTIVIY.class);
                intent.putExtra("paxid",  pax_id.getText());
                startActivity(intent);
于 2013-09-20T09:41:51.057 回答
0
ItinResponse data = obj.parseXMLData(fXmlFile);
        List<SectorRecords> sectorList = data.getSectorRecordsDetails();
        int items = 0;
        List<PassengerDetails> listdata = data.getPaxDetails();
        int i = 0;
        for (PassengerDetails elements : listdata) {
            inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            RelativeLayout layout = (RelativeLayout) inflater.inflate(
                    R.layout.passenger_details_layout, main, false);
            firstName = (TextView) layout.findViewById(R.id.first_pax_name);
            pax_id = (TextView) layout.findViewById(R.id.pax_id);
            firstName.setText(elements.getFirstName() + " "
                    + elements.getLastName());
            pax_id.setText(elements.getPaxId());
            layout.setTag(elements.getPaxId());
            main.addView(layout, i);
            i++;
layout.setOnClickListener(new OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        String paxId = v.getTag().toString();
                        // do some staff
                    }
                });
        }
于 2013-09-20T09:47:19.567 回答