如何在软键盘中使用gridview中的Share Intent?

时间:2016-11-17 09:23:25

标签: android keyboard ime soft-keyboard

我在键盘视图中有一个由图像组成的网格视图。我想让该gridview中的每个图像都可以通过意图共享来共享。我怎样才能做到这一点?

提前致谢

这是keyboard.class中的代码:

    public View buatQuoteView(){
    buatInputView(R.layout.quoteview, R.id.emptyKbd, R.xml.empty);

    final GridView gridView = (GridView) root.findViewById(R.id.quote_grid);
    gridView.setAdapter(new QuoteGrid(this));

    gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            // what should i put here????????
        }
    });
    return root;
}

这是QuoteGrid.class中的代码:

public class QuoteGrid extends BaseAdapter {
public Context mContext;

public Integer[] mThumbIds = {
        R.drawable.quote1, R.drawable.quote2, R.drawable.quote3, R.drawable.quote4, R.drawable.quote5};

// Constructor
public QuoteGrid(Context c){
    mContext = c;
}

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

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

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

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    ImageView imageView = new ImageView(mContext);
    imageView.setImageResource(mThumbIds[position]);
    imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
    imageView.setLayoutParams(new GridView.LayoutParams(250, 250));
    return imageView;
}

}

2 个答案:

答案 0 :(得分:0)

Girdview有setOnItemClickListener(view,.. postion)方法

 public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
        Toast.makeText(MainActivity.this, "" + position, Toast.LENGTH_SHORT).show();
    }

你可以获得图像的位置然后你可以分享图像

答案 1 :(得分:0)

您可以在UI元素的任何点击事件中使用此功能。

BitmapDrawable bm = (BitmapDrawable) yourImageView.getDrawable();
Bitmap mysharebmp = bm.getBitmap();
String path = Images.Media.insertImage(getContentResolver(),
                    mysharebmp, "MyImage", null);
Uri uri = Uri.parse(path);
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
sharingIntent.setType("image/png");
sharingIntent.putExtra(Intent.EXTRA_STREAM, uri);
startActivity(Intent.createChooser(sharingIntent,
                    "Share image using"));