我有一个 ListView 和它下面的一些 EditText。列表中的每一行都有一个编辑按钮,单击该按钮应填充 ListView 下方的编辑文本。现在的问题是我为 ListView 定义了一个自定义适配器。由于我正在扩展 Adapter 类中的布局,而我的 EditText 位于另一个类中,因此如何在单击 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)
{
}
}
最佳答案
如果监听器必须附加到按钮,而不是整行,您可以将对这些编辑文本的引用传递给适配器。或者,您可以在应用程序中构建一个 EventBus,通过不同的类发送单击的文本。
关于android - 通过在列表适配器 Android 内单击按钮编辑 EditText,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32434209/