我有一个包含聊天的应用程序,我能够发送文本但是我想要实现的是每当我点击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;
}
}
答案 0 :(得分:0)
我的声誉不到50,所以现在不能写评论,但你的问题不明确,你想在哪里发送图片?如果你有网格内图像的路径,你可以在任何你想要的地方使用它们
第二,而不是使用BaseAdapter和默认列表,您可以使用名为RecyclerView的新库,它更强大,更轻松
<强>已更新强>
好的,这是你更新后的代码
@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]);
holder.img.settag(String.valueof(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.gettag());
Communicator.getInstance().emit("new chat message",
imageChat);
}
});
return grid;
}
你的问题是你把imageview所以文本实际上不是图像而是图像的地址