我使用 arrayAdapter 创建了一个列表视图。它包含
一个文本视图
两个单选按钮(即一个单选组)
- 一个编辑文本
此外,添加了具有提交按钮的页脚。TextView 正在动态设置。单选按钮有 yes 和 no 值。
问题是,在单击提交按钮时,我想从 listview 获取所有值将其发送到某处,但获取单选按钮和 edittext 的空值。
这是我的代码
final Question weather_data[] = new Question[]
{
new Question(str[0], r1, r2, etext, radio_group),
new Question(str[01], r1, r2, etext, radio_group),
new Question(str[02], r1, r2, etext, radio_group),
new Question(str[03], r1, r2, etext, radio_group),
new Question(str[04], r1, r2, etext, radio_group),
};
QuestionAdapter adapter = new QuestionAdapter(this,
R.layout.listview_item_row, weather_data);
listView1 = (ListView)findViewById(R.id.securityListView);
View header = (View)getLayoutInflater().inflate(R.layout.listview_header_row, null);
listView1.addHeaderView(header);
View footer = (View)getLayoutInflater().inflate(R.layout.listview_footer_row, null);
listView1.addFooterView(footer);
Button btnSubmit=(Button)(footer.findViewById(R.id.submit));
listView1.setAdapter(adapter);
Question w1= (Question) listView1.getItemAtPosition(2);
System.out.println(w1);
System.out.println(listView1.getParent().toString());
System.out.println("Child Count is "+listView1.getChildCount());
btnSubmit.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
Toast.makeText(getApplicationContext(), "Footer Toast", Toast.LENGTH_LONG).show();
System.out.println("In Footer OnClick");
Toast.makeText(MainActivity.this,"Footer Toast", Toast.LENGTH_LONG).show();
myQue=(Question) listView1.getItemAtPosition(3);
System.out.println(((Question) listView1.getItemAtPosition(3)).editResponse.getText()+" In Edit Text");
System.out.println(((Question) listView1.getItemAtPosition(3)).radioYes.isChecked());
// I want these 2 lines to print the answer (values entered by user). But showing null or values set by me at runtime.
}
});
}
}