我有一个使用回收者视图的Adapter类,其中有卡片视图,每个卡片视图都有2个EditText和一个ImageView。在每个卡视图onTextChanged()上,它将名称和电话保存为模型类作为ArrayList中的对象,但是无法设置图像视图并与其他文本一起添加到对象中。
我真正想要的是我在回收站视图中的ImageViewListener接口打开图库,并在用户选择时将该图像设置为在模型类中单击imageview和setUserimage()。
我尝试了通过适配器类的接口方法在打开画廊的主要活动上实现,但是onactivtyresult不起作用
我不知道一个例子会很有帮助。
public ViewHolder (View itemView) {
super(itemView);
UserName = (EditText) itemView.findViewById(R.id.username);
Phone_No = (EditText) itemView.findViewById(R.id.number);
imageView = (ImageView)itemView.findViewById(R.id.chequeimage);
UserName.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
@Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
UserList add_list = Add_list.get(getAdapterPosition());
add_list.setChequeAmount(charSequence+"");
Add_list.set(getAdapterPosition(),add_list);
//this way i was able to change text and add to model class
}
@Override
public void afterTextChanged(Editable editable) {
}
});
//but problem is how to set the image i have created an interface that on imageview listener opens gallery but does not select image and view it in image view
holder.imageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
// this is the interface method i tried
onImageClickChanged.getPosition(data);
}
});
holder.UserName.setText(add_list.get(position).getUserName());
holder.Number.setText(add_list.get(position).getNumber());