----------------------------------------------------------------------
public class AdapterActivity extends RecyclerView.Adapter<AdapterActivity.ViewHolder> {
private Context context;
private List<Chat_room> items;
private int item_layout;
private String name;
private boolean check = true;
public AdapterActivity(Context context, List<Chat_room> items, int item_layout, String value) {
this.context=context;
this.items=items;
this.item_layout=item_layout;
this.name = value;
}
public int getItemViewType(int position)
{
if(items.get(position).getName().equals(name))
{
//check = true;
return 1;
}
else
{
// check = true;
return 2;
}
}
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view;
if(viewType == 1)
{
view = LayoutInflater.from(parent.getContext()).inflate(R.layout.chat_items, parent, false);
}
else
{
view = LayoutInflater.from(parent.getContext()).inflate(R.layout.chat_items_user, parent, false);
}
return new ViewHolder(view);
}
//@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
if(imageCheck == true)
{
holder.imageBitmapView.setImageBitmap(items.get(position).getBitmap()); <-- 여기서 getBitmap을 호출하면
imageCheck = false;
}
else
{
holder.msg.setText(items.get(position).getMsg());
}
}
@Override
public int getItemCount() {
return this.items.size();
}
public class ViewHolder extends RecyclerView.ViewHolder {
TextView msg;
ImageView imageBitmapView;
public ViewHolder(View itemView) {
super(itemView);
msg = (TextView)itemView.findViewById(R.id.chat_name);
imageBitmapView = (ImageView)itemView.findViewById(R.id.imageBitmapView);
}
}
}
-----------------------------
public class Chat_room {
public String name ;
public String msg ;
public byte[] bytes ;
public Bitmap bitmap = null ;
public String path;
private int num = 0;
public String test;
public static boolean imageCheck;
public Chat_room() {
// Default constructor required for calls to DataSnapshot.getValue(Comment.class)
}
public Chat_room(String name, String msg) {
this.name = name;
this.msg = msg;
}
public Chat_room(String name, String mCurrentPhotoPath, int num) {
this.name = name;
this.path = mCurrentPhotoPath;
this.num = num;
BitmapFactory.Options bmOptions = new BitmapFactory.Options();
bmOptions.inJustDecodeBounds = true;
BitmapFactory.decodeFile(path, bmOptions);
bmOptions.inJustDecodeBounds = false;
bmOptions.inSampleSize = 4;
bmOptions.inPurgeable = true;
bitmap = BitmapFactory.decodeFile(path, bmOptions);
Log.i("bitmap-Chat_room", String.valueOf(bitmap)); <-- 여기서는 bitmap 값이 제대로 들어오는데,
imageCheck = true;
test = "Free";
}
public String getName() {
return name;
}
public String getMsg() {
return msg;
}
public Bitmap getBitmap()
{
Log.i("bitmap-Chat_room-return", String.valueOf(bitmap)); <-- 여기서는 null을 반환합니다.
Log.i("bitmap-TEST", test); <-- 혹시나 싶어서 test 변수도 멤버변수로 선언하고 찍어봤더니 여기서는
java.lang.NullPointerException: println needs a message 이런 에러가 나면서 앱이 죽어버리네요
return bitmap;
}
}
멤버변수는 메소드에서 변수값을 변경했을때, 그 메소드에서 나오더라도 값이 유지되는거 아닌가요??