我正在passenger_details_layout
中充气main_passenger_details_layout
。在运行时,我在TextView中设置值。我正在设置pax_id
,对于我在其中充气的每一行都是不可见的。所以,当点击passenger_details_layout时,我想调用一个新活动并将pax_id
传递给新活动。
每次循环运行时Pax_id
都会像1,2,3一样。所以点击1行我想获得我设置的第一行的pax_id
。
请帮助我怎么做才能完全感谢你。
代码要Infalate
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
答案 0 :(得分: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
一切顺利...... !!!!
答案 1 :(得分:0)
使用
TextView paxView = (TextView)v.findViewById(R.id.pax_id);
String pax_value = paxView.getText().toString();
答案 2 :(得分:0)
按钮点击每一行都是这样的
Intent intent=new Intent(this,YOUR_NEXT_ACTIVIY.class);
intent.putExtra("paxid", pax_id.getText());
startActivity(intent);
答案 3 :(得分: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
}
});
}
答案 4 :(得分: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();
}
});
}