我正在处理一个应用程序。我正在为用户输入创建动态布局,如(姓名,年龄,出生日期),我试图通过listview创建此布局。 我能够创建布局,但是当我试图获取用户输入值时,没有任何东西出现,即使用户选择他们的出生日期,也没有在listview的textview中显示。即使我试图显示这个布局超过2时间没有发生。
请帮助我。我可以检索用户输入的listview值并多次添加布局。 下面是我的适配器类:
@Override
public View getView(int position, View convertView, ViewGroup parent) {
holder=null;
LayoutInflater inflater=(LayoutInflater) context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
if(convertView==null){
convertView=inflater.inflate(R.layout.test_travller,null);
holder=new ViewHolder();
holder.passengerType=(TextView) convertView.findViewById (R.id.Adult_Detail);
holder.Title=(Spinner) convertView.findViewById (R.id.Adult_Title);
holder.Adult_firstName=(EditText) convertView.findViewById (R.id.Adult_FirstName);
holder.MiddleName=(EditText) convertView.findViewById (R.id.Adult_Middlename);
holder.Lastname=(EditText) convertView.findViewById (R.id.Adult_Lastname);
holder.DOB=(TextView) convertView.findViewById (R.id.Adult_DOB);
holder.saveButton = (Button) convertView.findViewById (R.id.saveButton);
convertView.setTag(holder);
}else {
holder = (ViewHolder) convertView.getTag();
}
holder.DOB.setText(new StringBuilder().append(year).append (month).append(date));
// holder.passengerType.setText(Details.get (position).getPassengerType());
// holder.Title.setAdapter(holder.spinneradapter.getTitle_adapter ());
holder.Adult_firstName.setTag(position);
/* holder.Adult_firstName.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String firstName = holder.Adult_firstName.getText().toString ();
Log.i("onclick",firstName);
}
});*/
/* holder.Title.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
holder.spinneradapter.setAdult_Title(position);
}
});*/
holder.DOB.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
DatePickerDialog datepickerdialog=new DatePickerDialog (context,datepicker,year,month,date);
datepickerdialog.show();
}
});
holder.saveButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String firstName = holder.Adult_firstName.getText ().toString();
String middleName=holder.MiddleName.getText().toString();
String lastName= holder.Lastname.getText().toString();
String spinner_value=holder.Title.getSelectedItem ().toString();
passengerDetails.add(new PassengerDetails (spinner_value,firstName,middleName,lastName,""));
Log.i("values",""+firstName+middleName+lastName +spinner_value);
}
});
return convertView;
}
private DatePickerDialog.OnDateSetListener datepicker=new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int selectedyear, int monthOfYear, int dayOfMonth) {
calendar.set(Calendar.YEAR,selectedyear);
calendar.set(Calendar.MONTH,monthOfYear);
calendar.set(Calendar.DATE,dayOfMonth);
year=calendar.get(Calendar.YEAR);
month=calendar.get(Calendar.MONTH);
date=calendar.get(Calendar.DATE);
}
};
public class ViewHolder{
// PassengerDetails spinneradapter;
TextView passengerType,DOB;
Spinner Title;
EditText Adult_firstName,Lastname,MiddleName;
Button saveButton;
}
和我的主要班级
public class Traveller_Details extends AppCompatActivity {
Toolbar traveller_toolbar;
Context context=this;
AlertDialog dialog;
EditText Adult_EDText,Child_EDText,Mobile_EDText,EmailEDText;
String Firstname;
Button call,ConfirmBooking;
List<String> Child;
Search_flights search_flights=Search_flights.getSearch_flights();
int Num_of_Passengers;
PassengerDetails passeneger;
ListView Passengers;
List<String> passengerDetails;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.traveller_details);
Num_of_Passengers=search_flights.getAdult()+search_flights.getChild()+search_flights.getInfant();
Passengers=(ListView) findViewById(R.id.Passenger_Detail_List);
passengerDetails = new ArrayList<>();
for(int i=0;i<4;i++) {
passengerDetails.add("traveller1");
}
Passenger_DetailAdapter pdAdapter = new Passenger_DetailAdapter(this, passengerDetails);
Passengers.setAdapter(pdAdapter);
}