【发布时间】:2015-12-02 17:54:34
【问题描述】:
我有一个 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)
{
}
}
【问题讨论】:
-
在适配器中为您的编辑文本设置 onclick() 方法
-
@GaneshGudghe 如何从我的适配器访问 EditText?
-
列表视图中有 2 种不同类型的适配器?或 2 个列表视图?提供一些代码让我们看看。
-
@helloworld 请发布您的适配器代码
-
检查this
标签: android listview android-listview listadapter