我有gridview
與3個單元格,每個單元格將具有ImageView和ImageButton以從圖庫或相機添加圖像。當替換單個圖像時,所有其他ImageView在Gridview中被替換
但是,當我試圖設置選定的圖像點擊單元格的網格視圖它取代所有的單元格,而不是一個單一的單元格。
這裏是gridview的
public class Adapter_For_GridView extends RecyclerView.Adapter<Adapter_For_GridView.ViewHolder>{
public static final String TAG="===GridView Pics===";
ViewClickCallback viewClickCallback;
Context context;
List<UserGrid> userGridList;
UserGrid userGridWrapper;
String ImageData;
public Adapter_For_GridView(ViewClickCallback viewClickCallback,Context context) {
this.viewClickCallback=viewClickCallback;
this.context=context;
}
@Override
public Adapter_For_GridView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view= LayoutInflater.from(parent.getContext()).inflate(R.layout.user_profile_photo_single_item,parent,false);
ViewHolder viewHolder=new ViewHolder(view);
Log.d(TAG,"On Create View Holder ");
return viewHolder;
}
@Override
public void onBindViewHolder(Adapter_For_GridView.ViewHolder holder, int position) {
userGridWrapper=userGridList.get(position);
Log.d(TAG,"On Bind View Holder- Value of isUpload "+userGridWrapper.isUpload());
Log.d(TAG,"On Bind View Holder Image Data "+ImageData);
Log.d(TAG,"On Bind View Holder Position "+position+" "+"User Grid Wrapper "+userGridWrapper);
Log.d(TAG,"On Bind View Holder User Grid Wrapper Get Image Path "+userGridWrapper.getImagePath());
if (ImageData!=null){
Log.d(TAG,"Image Data is Not Null "+ImageData);
userGridWrapper.setUpload(true);
if (userGridWrapper.isUpload()){
holder.imageButton.setImageResource(R.drawable.ic_clear_black_24dp);
Picasso.with(context).load(ImageData)
.into(holder.imageView);
}
}
else{
holder.imageButton.setImageResource(R.drawable.ic_add_black_24dp);
}
}
@Override
public int getItemCount() {
Log.d(TAG,"Value at GetItemCount of GridList "+userGridList.size());
if (userGridList!=null){
return userGridList.size();
}
return 2;
}
public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
ImageView imageView;
ImageButton imageButton;
public ViewHolder(View itemView) {
super(itemView);
Log.d(TAG,"On View Holder");
itemView.setOnClickListener(this);
imageView= (ImageView) itemView.findViewById(R.id.User_Pics);
imageButton= (ImageButton) itemView.findViewById(R.id.imageButton);
imageButton.setOnClickListener(this);
}
@Override
public void onClick(View v) {
Log.d(TAG,"Image Button Clicked "+getAdapterPosition()+" Get Layout Position "+getLayoutPosition());
if (viewClickCallback!=null){
Log.d(TAG,"ViewClickcalleback is not null ");
viewClickCallback.viewClicked(getAdapterPosition()+1);
}
}
}
public void setUserGridList(List<UserGrid> userList){
this.userGridList=userList;
}
public void setImagePath(String path,int position){ //GETTING IMAGE HERE FROM ONACTIVITYRESULT TO THIS ADAPTER
this.ImageData=path;
Log.d(TAG,"Position of Grid "+position); //POSITION OF CLICKED ITEM
Log.d(TAG,"Set Image Path "+path); //IMAGE PATH OF SELECTED IMAGE
notifyDataSetChanged();
}
}
從logcat中onactivityresult
01-31 18:13:47.917 9146-9146/com.example.com.pro_working1 D/===User Profile===: User Profile On Activity Result Calling 25 -1
01-31 18:13:47.927 9146-9146/com.example.com.pro_working1 D/===User Profile===: On Activity Result Calling--Request Code 25
01-31 18:13:47.927 9146-9146/com.example.com.pro_working1 D/===User Profile===: Intent Data Intent { dat=content://media/external/images/media/19276 typ=image/jpeg flg=0x1 }
01-31 18:13:47.927 9146-9146/com.example.com.pro_working1 D/===User Profile===: On Activity Result Position 0
01-31 18:13:48.687 9146-9146/com.example.com.pro_working1 D/===User Profile===: Image Name content://media/external/images/media/19276
01-31 18:13:48.687 9146-9146/com.example.com.pro_working1 D/===User Profile===: Image /storage/sdcard0/pictures/Social/1/Spread-Unconditional-Love_www.example.com-101.jpg
01-31 18:13:48.687 9146-9146/com.example.com.pro_working1 D/===GridView Pics===: Position of Grid 0
01-31 18:13:48.687 9146-9146/com.example.com.pro_working1 D/===GridView Pics===: Set Image Path /storage/sdcard0/pictures/Social/1/Spread-Unconditional-Love_www.example.com-101.jpg
01-31 18:13:48.777 9146-9146/com.example.com.pro_working1 D/===GridView Pics===: Value at GetItemCount of GridList 3
01-31 18:13:48.777 9146-9146/com.example.com.pro_working1 D/===GridView Pics===: Value at GetItemCount of GridList 3
01-31 18:13:48.777 9146-9146/com.example.com.pro_working1 D/===GridView Pics===: Value at GetItemCount of GridList 3
01-31 18:13:48.787 9146-9146/com.example.com.pro_working1 D/===GridView Pics===: On Bind View Holder- Value of isUpload false
01-31 18:13:48.787 9146-9146/com.example.com.pro_working1 D/===GridView Pics===: On Bind View Holder Image Data /storage/sdcard0/pictures/Social/1/Spread-Unconditional-Love_www.example.com-101.jpg
01-31 18:13:48.787 9146-9146/com.example.com.pro_working1 D/===GridView Pics===: On Bind View Holder Position 0 User Grid Wrapper [email protected]
01-31 18:13:48.787 9146-9146/com.example.com.pro_working1 D/===GridView Pics===: On Bind View Holder User Grid Wrapper Get Image Path null
01-31 18:13:48.787 9146-9146/com.example.com.pro_working1 D/===GridView Pics===: Image Data is Not Null /storage/sdcard0/pictures/Social/1/Spread-Unconditional-Love_www.example.com-101.jpg
01-31 18:13:49.557 9146-9146/com.example.com.pro_working1 D/===GridView Pics===: Value at GetItemCount of GridList 3
01-31 18:13:49.557 9146-9146/com.example.com.pro_working1 D/===GridView Pics===: On Bind View Holder- Value of isUpload false
01-31 18:13:49.557 9146-9146/com.example.com.pro_working1 D/===GridView Pics===: On Bind View Holder Image Data /storage/sdcard0/pictures/Social/1/Spread-Unconditional-Love_www.example.com-101.jpg
01-31 18:13:49.557 9146-9146/com.example.com.pro_working1 D/===GridView Pics===: On Bind View Holder Position 1 User Grid Wrapper [email protected]
01-31 18:13:49.557 9146-9146/com.example.com.pro_working1 D/===GridView Pics===: On Bind View Holder User Grid Wrapper Get Image Path null
01-31 18:13:49.557 9146-9146/com.example.com.pro_working1 D/===GridView Pics===: Image Data is Not Null /storage/sdcard0/pictures/Social/1/Spread-Unconditional-Love_www.example.com-101.jpg
01-31 18:13:49.557 9146-9146/com.example.com.pro_working1 D/===GridView Pics===: Value at GetItemCount of GridList 3
01-31 18:13:49.557 9146-9146/com.example.com.pro_working1 D/===GridView Pics===: On Bind View Holder- Value of isUpload false
01-31 18:13:49.557 9146-9146/com.example.com.pro_working1 D/===GridView Pics===: On Bind View Holder Image Data /storage/sdcard0/pictures/Social/1/Spread-Unconditional-Love_www.example.com-101.jpg
01-31 18:13:49.557 9146-9146/com.example.com.pro_working1 D/===GridView Pics===: On Bind View Holder Position 2 User Grid Wrapper [email protected]
01-31 18:13:49.557 9146-9146/com.example.com.pro_working1 D/===GridView Pics===: On Bind View Holder User Grid Wrapper Get Image Path null
01-31 18:13:49.557 9146-9146/com.example.com.pro_working1 D/===GridView Pics===: Image Data is Not Null /storage/sdcard0/pictures/Social/1/Spread-Unconditional-Love_www.example.com-101.jpg
那麼我該怎麼做。我也有包裝類與'字符串imageData和布爾isUpload'的setter和getter方法。我能做些什麼,使'的ImageData String'只提供給單擊的單元格 – Ritu
您可以創建**的ImageData ** varibale在包裝類,相同isUpload,然後通過使用位置從列表中得到它的設置varibale到包裝類對象在** setImagePath **方法或使用** isUpload ** boolean falg來區分 – Sanjeet