Я хочу вставлять изображения в динамические кнопки, я могу получить все, кроме изображений. Я хочу, чтобы моя кнопка отображалась как текст + изображение, но вместо этого я получаю текст + [email protected] и т. Д. Может ли кто-нибудь сказать, что ошибка в моем коде, любая помощь оценивается.add drawable image To Button
private class LongOperation extends AsyncTask<String, Void, Void> {
private final HttpClient Client = new DefaultHttpClient();
private String Content;
private String Error = null;
private ProgressDialog Dialog = new ProgressDialog(MainActivity.this);
String data ="";
int sizeData = 0;
private View addButton;
protected Bitmap myBitmap;
private String image;
protected void onPreExecute() {
Dialog.setMessage("Please wait..");
Dialog.show();
}
// Call after onPreExecute method
protected Void doInBackground(String... urls) {
/************ Make Post Call To Web Server ***********/
BufferedReader reader=null;
// Send data
try
{
// Defined URL where to send data
URL url = new URL(urls[0]);
JSONArray jsonMainNode1 = jsonResponse.getJSONArray("menu");
// JSONObject e = jsonMainNode1.getJSONObject(position);
int lengthJsonArr = jsonMainNode1.length();
for(int i=0; i <lengthJsonArr; i++)
{
JSONObject jsonChildNode = jsonMainNode1.getJSONObject(i);
String Pid = jsonChildNode.optString("pid".toString());
String Name = jsonChildNode.optString("name").toString();
String Refid=jsonChildNode.optString("refid".toString());
String imagefile = jsonChildNode.getString("image_url");
String resName = imagefile.split("\\.")[2];
int resId = getResources().getIdentifier(resName, "drawable", getPackageName());
Drawable image = getResources().getDrawable(resId);
OutputData = Name+image;
str_id = Pid;
LinearLayout buttonContainer=(LinearLayout)findViewById(R.id.btn_container);
Button button = new Button(buttonContainer.getContext());
button.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
ViewGroup.LayoutParams params = button.getLayoutParams();
//Button new width
params.width = 150;
params.height = 150;
button.setLayoutParams(params);
button.setText(OutputData);
// button.setBackground(itemImage);
button.setTag(Refid);
button.setTextColor(Color.parseColor("#FEFCFF"));
button.setBackgroundResource(R.drawable.button_color);
buttonContainer.addView(button);
любые другие методы ?? – ammu
вы имеете в виду OutputData = Name + image; должен помещать текст + изображение в кнопку? –
@Amrola yes.i хочу кнопку с текстом и изображением – ammu