问题描述
我使用Xamarin Studio和C#。
我已经加入的EditText 在列表视图适配器控制。而这个列表是动态填充的。
现在我想的活动类来获得所有的EditText值。我怎样才能做到这一点?
`公共类PRDeptHeadApprovalDetailAdapter:BaseAdapter
{
列表项;
活动背景;
公共PRDeptHeadApprovalDetailAdapter(Activity上下文,列表< PRDeptHeadApprovalDetailAdapterInformation>的项目)
:基地()
{
this.context =背景;
this.items =物品;
} 公众覆盖长GetItemId(INT位置)
{
返回的位置;
}
公共重写字符串这个[INT位置]
{
{返回项目[位置]的ToString(); }
}
公众覆盖诠释计数
{
{返回items.Count; }
} 公众覆盖查看GetView(INT位置,查看convertView,父母的ViewGroup)
{
VAR项目=项目[位置]
查看查看= convertView; //重新使用现有的观点,如果一个供应
如果(查看== NULL)//没有以再利用,创造新的
鉴于= context.LayoutInflater.Inflate(Resource.Layout.PRDeptHeadApprovalDetailAdapter,NULL);
//设置视图属性,以反映给定的行数据
view.FindViewById<&TextView的GT;(Resource.Id.lbltdPermNo)。文本= item.lbltdPermNo;
view.FindViewById<&TextView的GT;(Resource.Id.lbltdItemName)。文本= item.lbltdItemName;
view.FindViewById<&TextView的GT;(Resource.Id.lbltdJustification)。文本= item.lbltdJustification;
view.FindViewById<&TextView的GT;(Resource.Id.lbltdSrce)。文本= item.lbltdSrce;
view.FindViewById<&TextView的GT;(Resource.Id.lbltdQuantity)。文本= item.lbltdQuantity;
的EditText txtApproveQuantity = view.FindViewById<&的EditText GT;(Resource.Id.lbltdApproveQuantity);
txtApproveQuantity.Text = item.lbltdApproveQuantity;
//返回视图,填充数据,显示
返回视图。
}
}`
在第一次创建的对象的的ListView适配器
titleAdapter =新TitleAdapter();
然后你就能获得列表视图中的每一个位置的EditText
的位置
列表视图中值
查看= titleAdapter .getView(位置,NULL,NULL);
EditText上的EditText =(EditText上)view.findViewById(R.id.edittext_id_here);
edittext.getText();
I am using Xamarin Studio with C#.
I have added EditText control in listview adapter. And this list is dynamically populated.
Now I want to get value of all EditText in activity class. How I can achieve this?
`public class PRDeptHeadApprovalDetailAdapter : BaseAdapter { List items; Activity context;
public PRDeptHeadApprovalDetailAdapter(Activity context, List<PRDeptHeadApprovalDetailAdapterInformation> items)
: base()
{
this.context = context;
this.items = items;
}
public override long GetItemId(int position)
{
return position;
}
public override string this[int position]
{
get { return items[position].ToString(); }
}
public override int Count
{
get { return items.Count; }
}
public override View GetView(int position, View convertView, ViewGroup parent)
{
var item = items[position];
View view = convertView; // re-use an existing view, if one is supplied
if (view == null) // no view to re-use, create new
view = context.LayoutInflater.Inflate(Resource.Layout.PRDeptHeadApprovalDetailAdapter, null);
// set view properties to reflect data for the given row
view.FindViewById<TextView>(Resource.Id.lbltdPermNo).Text = item.lbltdPermNo;
view.FindViewById<TextView>(Resource.Id.lbltdItemName).Text = item.lbltdItemName;
view.FindViewById<TextView>(Resource.Id.lbltdJustification).Text = item.lbltdJustification;
view.FindViewById<TextView>(Resource.Id.lbltdSrce).Text = item.lbltdSrce;
view.FindViewById<TextView>(Resource.Id.lbltdQuantity).Text = item.lbltdQuantity;
EditText txtApproveQuantity = view.FindViewById<EditText>(Resource.Id.lbltdApproveQuantity);
txtApproveQuantity.Text = item.lbltdApproveQuantity;
// return the view, populated with data, for display
return view;
}
}`
At First Create Object of your ListView Adapter
titleAdapter = new TitleAdapter();
Then you able to get Each position of the listview EditText
Value by the position
of the list-view
View view = titleAdapter .getView(position, null, null);
EditText edittext= (EditText ) view.findViewById(R.id.edittext_id_here);
edittext.getText();
这篇关于从ListView中获取的EditText控制Xamarin Studio和C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!