我有一个ListView和一些EditTexts。列表中的每一行都有一个“编辑”按钮,单击该按钮将填充Listview下方的EditTexts。现在的问题是我有一个为ListView定义的自定义适配器。当我在Adapter类中扩展布局并且我的EditTexts在另一个中时,如何在ListView行内单击按钮时填充EditText?
修改
这是我的适配器代码
public class CompleteCommentsAdapter : BaseAdapter
{
private Activities.CommentListActivity commentListActivity;
private List<Comments> dummyCommentList;
private TextView txtUserName;
private TextView txtCommentTime;
private ImageView imgUserImage;
private TextView txtCommentText;
private ImageButton ibtnEdit;
private ImageButton itbtnDelete;
public CompleteCommentsAdapter(Activities.CommentListActivity commentListActivity, List<Comments> dummyCommentList)
{
// TODO: Complete member initialization
this.commentListActivity = commentListActivity;
this.dummyCommentList = dummyCommentList;
}
public override int Count
{
get { return dummyCommentList.Count(); }
}
public override Java.Lang.Object GetItem(int position)
{
return position;
}
public override long GetItemId(int position)
{
return position;
}
public override View GetView(int position, View convertView, ViewGroup parent)
{
if (convertView == null)
{
convertView = commentListActivity.LayoutInflater.Inflate(Resource.Layout.comment_list_row, null);
txtUserName = convertView.FindViewById<TextView>(Resource.Id.txtCommenterName);
txtCommentTime = convertView.FindViewById<TextView>(Resource.Id.txtCommenterTime);
imgUserImage = convertView.FindViewById<ImageView>(Resource.Id.imgProfileUserImage);
txtCommentText = convertView.FindViewById<TextView>(Resource.Id.txtCommentText);
ibtnEdit = convertView.FindViewById<ImageButton>(Resource.Id.imgBtnEdit);
itbtnDelete = convertView.FindViewById<ImageButton>(Resource.Id.imgBtnDelete);
}
Comments mComments = dummyCommentList.ElementAt(position);
txtUserName.Text = mComments.UserName;
txtCommentTime.Text = mComments.CommentTime;
txtCommentText.Text = mComments.CommentText;
ibtnEdit.Click += ibtnEdit_Click;
return convertView;
}
void ibtnEdit_Click(object sender, EventArgs e)
{
}
}
答案 0 :(得分:2)
如果必须将监听器连接到按钮而不是整行,您只需将对这些编辑文本的引用附加到适配器即可。或者,您可以在应用程序中构建EventBus,通过不同的类发送Clicked Text。
答案 1 :(得分:1)
var str = Windows.System.Profile.AnalyticsInfo.VersionInfo.DeviceFamily;
if (str == "Windows.Desktop")
{
//...
}
else if (str == "Windows.Mobile")
{
//...
}
答案 2 :(得分:-1)
编辑按钮:
ibtnEdit.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
txtUserName.setText("");
txtCommentTime.setText("");
txtCommentText.setText("");
}
});