我有一个包含图片和文字的自定义列表视图。我正在使用Glide库将图像加载到Listview中。有时只有文字会没有图像。现在,我想使用Share intent共享imageview和文本,为此我创建了一个按钮。我为按钮创建了一个Onclick Listener,它与Listview中的每个项目一起显示。当我点击按钮时,它会发送imageview进行处理然后转换为位图,然后它将被共享。 这里的问题是,当我点击按钮时,未选择特定位置的图像视图,而是选择了不同的图像视图。请帮忙。
我在Imageview上有OnItem监听器以全屏和缩放显示它。
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
final descusers du = dusers.get(position);
String username = du.loginname;
String descCrip=du.descCrip;
Limage = du.image;
long Ptime = du.Ptime;
profile = du.profile;
if(convertView==null) {
viewholder = new Viewholder();
convertView = LayoutInflater.from(ds).inflate(R.layout.customlist, null);
viewholder.uname = (TextView) convertView.findViewById(R.id.username);
viewholder.desc = (TextView) convertView.findViewById(R.id.description);
viewholder.time = (TextView)convertView.findViewById(R.id.time);
viewholder.iview = (ImageView) convertView.findViewById(R.id.imageList);
viewholder.civ = (CircleImageView)convertView.findViewById(R.id.profile_image);
viewholder.share = (TextView)convertView.findViewById(R.id.share);
Glide.with(convertView.getContext()).load(du.profile).placeholder(R.drawable.place).dontAnimate()
.centerCrop().signature(new StringSignature(String.valueOf(System.currentTimeMillis())))
.into(viewholder.civ);
convertView.setTag(viewholder);
}else {
viewholder = (Viewholder) convertView.getTag();
}
viewholder.uname.setText(username);
viewholder.desc.setText(descCrip);
if (!Patterns.WEB_URL.matcher(Limage).matches()) {
// viewholder.progress.setVisibility(View.GONE);
viewholder.iview.setVisibility(View.GONE);
} else {
Glide.with(convertView.getContext()).load(Limage).centerCrop().diskCacheStrategy(DiskCacheStrategy.ALL).into(viewholder.iview);
viewholder.iview.setVisibility(View.VISIBLE);
}
final View finalConvertView = convertView;
viewholder.iview.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Dialog builder = new Dialog(listdisplay, android.R.style.Theme_Black_NoTitleBar_Fullscreen);
builder.requestWindowFeature(Window.FEATURE_NO_TITLE);
builder.getWindow().setBackgroundDrawable(
new ColorDrawable(Color.BLACK));
builder.setContentView(R.layout.imager);
ImageView image = (ImageView) builder.findViewById(R.id.image);
Glide.with(finalConvertView.getContext()).load(du.image)
.diskCacheStrategy(DiskCacheStrategy.ALL).into(image);
builder.show();
}
});
viewholder.share.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//onShareItem(v);
Uri bmpUri = getLocalBitmapUri(viewholder.iview);
if (bmpUri != null) {
// Construct a ShareIntent with link to image
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_STREAM, bmpUri);
shareIntent.setType("image/*");
// Launch sharing dialog for image
listdisplay.startActivity(Intent.createChooser(shareIntent, "Share Image"));
} else {
// ...sharing failed, handle error
}
}
});
return convertView;
}
如何从单击按钮的位置获取正确的Imageview。
答案 0 :(得分:1)
使用此代码 @覆盖 public void onClick(查看v){
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
loginButton.onActivityResult(requestCode, resultCode, data);
}
private void setuptwlogin() {
loginButton=(TwitterLoginButton)findViewById(R.id.xtwlogin);
loginButton.setCallback(new Callback<TwitterSession>() {
@Override
public void success(Result<TwitterSession> result) {
Log.w("myApp", result.data.toString());
Toast.makeText(getApplicationContext(),"succueess",Toast.LENGTH_SHORT).show();
composetweet();
}
@Override
public void failure(TwitterException exception) {
Toast.makeText(getApplicationContext(),"failed",Toast.LENGTH_SHORT).show();
}
});
}
private void composetweet() {
TweetComposer.Builder builder=new TweetComposer.Builder(this)
.text("This is made by saptak das")
.image(Uri.parse("http://www.thehealthsync.com/knowhow_res/1.jpg"));
builder.show();
}
}
});
答案 1 :(得分:0)
您可以在
中使用位置 **@Override
public void onClick(View v) {
}**
它给出列表项的正确点击位置。