gpt4 book ai didi

android - 使用按钮 onClick 获取图像

转载 作者:行者123 更新时间:2023-11-29 21:43:29 25 4
gpt4 key购买 nike

我正在尝试获取图像并希望使用`Button.onClickListener()

将其放入HashMap

我确定我在这里做错了:

   String s_image = imgv.toString();

我想在这里我应该使用 ImageView 代替 String,但怀疑需要编写什么代码以及如何编写代码

Logcat 说:

    05-11 10:56:51.760: D/dalvikvm(299): GC_EXTERNAL_ALLOC freed 2253 objects / 144464 bytes in 48ms
05-11 10:57:16.500: D/Single(299): ImageURL :: http://2.imimg.com/data2/EE/RJ/MY-932393/children-suits-250x250.jpg
05-11 10:57:17.920: D/Single(299): Title :: Kids
05-11 10:57:17.920: D/Single(299): Image :: android.widget.ImageView@46092008

Single.java代码:

public class Single extends Activity {

public static final String LOG_TAG = "Single";

public static final String TAG_TITLE = "title";
public static final String TAG_IMAGE = "image";

String s_title, s_image;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.information_product);

Intent in = getIntent();
String title = in.getStringExtra(TAG_TITLE);
String image = in.getStringExtra(TAG_IMAGE);
Log.d(Single.LOG_TAG, "ImageURL :: " + image);


final ImageLoader imageLoader = new ImageLoader(getApplicationContext());

final ImageView imgv = (ImageView) findViewById(R.id.single_thumb);
final TextView txttitle = (TextView) findViewById(R.id.single_title);

txttitle.setText(title);
imageLoader.DisplayImage(image, imgv);

Button mImgAddCart = (Button) findViewById(R.id.button_add);
mImgAddCart.setOnClickListener(new OnClickListener() {

public void onClick(View v) {
// TODO Auto-generated method stub

s_title = txttitle.getText().toString();
Log.d(Single.LOG_TAG, "Title :: " + s_title);
s_image = imgv.toString();
Log.d(Single.LOG_TAG, "Image :: " + s_image);

if (Session.item_data.size() <= 0) {
HashMap<String, String> h_obj = new HashMap<String, String>();
h_obj.put(TAG_TITLE, s_title);
h_obj.put(TAG_IMAGE, s_image);
Session.item_data.add(h_obj);
}
}
});

最佳答案

Button mImgAddCart = (Button) findViewById(R.id.button_add); 
mImgAddCart.setOnClickListener(new OnClickListener() {

public void onClick(View v) {
// TODO Auto-generated method stub

s_title = txttitle.getText().toString();
Log.d(Single.LOG_TAG, "Title :: " + s_title);
image = in.getStringExtra(TAG_IMAGE);
if (Session.item_data.size() <= 0) {
HashMap<String, String> h_obj = new HashMap<String, String>();
h_obj.put(TAG_TITLE, s_title);
h_obj.put(TAG_IMAGE, image);
Session.item_data.add(h_obj);
}
}
});

关于android - 使用按钮 onClick 获取图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16493973/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com