我使用textview&创建了一个列表使用holder的edittext ...看起来像
Textview Edittext
---------------------------------
Textview Edittext
---------------------------------
Textview Edittext
---------------------------------
但我无法从每个Edittext获取数据...... 任何人都可以帮助我..如何实现它...协助样本代码...
答案 0 :(得分:13)
我有类似的问题,我做了如下;
View view = listview.getChildAt(position);
EditText text = (EditText)view.findViewById(R.id.myEditBox);
String contents = text.getText().toString();
希望它有所帮助! // Fredrik
答案 1 :(得分:5)
for (int i = 0; i < telefoneListView.getAdapter().getCount(); i++) {
View viewTelefone = telefoneListView.getChildAt(i);
EditText tipoEditText = (EditText) viewTelefone.findViewById(R.id.telefone_form_tipo);
EditText telefoneEditText = (EditText) viewTelefone.findViewById(R.id.telefone_form_telefone);
Log.d(TAG, tipoEditText.getText().toString() + ":" + telefoneEditText.getText().toString());
}
导航到所有项目并获取每个项目的编辑文本。
答案 2 :(得分:1)
您可以尝试以下代码,即可达到您的要求,
public class TestListView extends Activity {
ListView listView,listView2;
String[] titles = {"List 1 title1","List 1 title2","List 1 title3","List 1 title4","List 1 title5","List 1 title6","List 1 title7","List 1 title8","List 1 title9"};
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
listView = new ListView(this);
listView.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));
listView.setAdapter(new CustomListAdapetr(this, titles));
((LinearLayout)findViewById(R.id.mailLayout)).addView(listView);
listView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
CustomView customView= (CustomView) arg0.getChildAt(arg2);
TextView textView = (TextView) customView.getChildAt(0);
Log.v("", ""+textView.getText());
}
});
}
public class CustomListAdapetr extends BaseAdapter{
private Context mContext;
private String[] list;
public CustomListAdapetr(Context context, String[] titles) {
mContext = context;
list = titles;
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return list.length;
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return list[position];
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
CustomView cv;
if (convertView == null) {
cv = new CustomView(mContext,""+list[position]);
}
else {
cv = (CustomView) convertView;
cv.setTitle(list[position]);
}
return cv;
}
}
private class CustomView extends LinearLayout {
public CustomView(Context context, String itemName) {
super(context);
this.setOrientation(HORIZONTAL);
// Here we build the child views in code. They could also have
// been specified in an XML file.
mTitle = new TextView(context);
mTitle.setText(itemName);
mTitle.setTextSize(25);
addView(mTitle, new LinearLayout.LayoutParams(200, LayoutParams.WRAP_CONTENT));
}
/** * Convenience method to set the title of a SpeechView */
public void setTitle(String title) {
mTitle.setText(title);
}
/** * Convenience method to set the dialogue of a SpeechView */
private TextView mTitle;
}
}
答案 3 :(得分:0)
通过
listView.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> arg0, View arg1, int position,
long arg3) {
// TODO Auto-generated method stub
}
});
方法我们可以点击项目位置。使用该位置我们得到适当的edittext值