public class CustomList extends ArrayAdapter<String> {
private final Activity context;
private final ArrayList<String> web;
public CustomList(Activity context, ArrayList<String> web ) {
super(context, R.layout.list_single,web);
this.context = context;
this.web = web;
}
@Override
public View getView(int position, View view, ViewGroup parent) {
LayoutInflater inflater = context.getLayoutInflater();
View rowView = inflater.inflate(R.layout.list_single, null, true);
EditText txtTitle = (EditText) rowView.findViewById(R.id.txt);
Button btn=(Button)rowView.findViewById(R.id.btn);
ImageView imageView = (ImageView) rowView.findViewById(R.id.img);
txtTitle.setText(web.get(position));
return rowView;
}
}
public class MainActivity extends Activity {
ListView list;
ArrayList<String> web = new ArrayList<String>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
web.add("Dsfsaf");
web.add("xcxc");
web.add("Dsfsafxcxc");
CustomList adapter = new CustomList(MainActivity.this, web);
list = (ListView) findViewById(R.id.list);
list.setAdapter(adapter);
}
}
在上面的示例中,我使用自定义适配器显示列表视图,包括文本视图,TextField和Button。它工作正常,但我需要在单击按钮时获取输入文本字段值
答案 0 :(得分:0)
使用OnItemClickListener!
像这样实现:onItemClick (AdapterView<?> parent, View view, int position, long id)
您的“view”参数将是您的行布局。然后就像这样得到你的编辑文本:
EditText txtTitle = (EditText) view.findViewById(R.id.txt);
然后以通常的方式使用你的字符串:
String yourString = txtTitle.getText().toString();