如何从gridview显示实际图像

时间:2018-01-01 09:44:08

标签: java android

当我点击gridview中的任何图片时,我正试图在聊天框中显示图像但是,每当我尝试这样做时它会出现一个文本,所以请告知可以做什么来获取图像本身而不是出现的文字,请帮助我,我已经被困了太久

smiles_items_layout.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="wrap_content"
android:layout_height="wrap_content">

<ImageView android:id="@+id/smile_image_view"
android:layout_width="45dp"
android:layout_height="45dp"
android:layout_gravity="center"/>

</LinearLayout>

BottomSheetDialog_Smiles.java

public class ImageAdapter2 extends BaseAdapter {
private Context mContext;
private final int[] mThumbIds;
String[] mThumbIdsString = null;

public ImageAdapter2(Context c, int[] mThumbIds ,  String[] mThumbIdsString) 
{
 mContext = c;
 this.mThumbIds = mThumbIds;
 this.mThumbIdsString = mThumbIdsString;
}

@Override
public int getCount() {
    return mThumbIds.length & mThumbIdsString.length;
}

@Override
public Object getItem(int position) {
    return position;
}

@Override
public long getItemId(int position) {
    return position;
}


public class Holder {
    ImageView img;
}



@Override
public View getView(final int position, final View convertView, 
ViewGroup parent) {

    final Holder holder = new Holder();
    LayoutInflater inflater = (LayoutInflater) 
    getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    grid = inflater.inflate(R.layout.smiles_items_layout, null);
    null);

    holder.img = (ImageView) grid.findViewById(R.id.smile_image_view);
    holder.img.setImageResource(mThumbIds[position]);


    gridView2.setOnItemClickListener(new 
    AdapterView.OnItemClickListener() {
        Drawable drawable;

        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, 
        int i, long l) {
            JSONDictionary imageChat = new JSONDictionary();
            LinearLayout layout= (LinearLayout)view;
            ImageView imageView = (ImageView) layout.getChildAt(0);
            imageView.getDrawable();
            imageChat.put("message", imageView);
            Communicator.getInstance().emit("new chat message", 
            imageChat);
        }
    });

    return grid;

    }

}

这是单击图像时显示的结果

enter image description here

1 个答案:

答案 0 :(得分:2)

inds <- which(df[,-1]!=0,TRUE)
df$newcol <- inds[order(row.names(inds)),][,2]

df[,c(1,11)]
#       user_id newcol
#1 5.444902e+13      3
#2 1.175921e+14      6
#3 1.871455e+14      3
#4 2.450030e+14      6
#5 3.326252e+14      2
#6 3.363368e+14      2