I want to insert images into dynamic buttons, I can get everything other than images. I want my button to display as text+image, but instead I am getting text + androidgraphics.drawable.bitmapdrawable#416e5 etc. Can anyone tell what the mistake is in my code, any help appreciated.
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);
Drawable image = getResources().getDrawable(resId);
You are trying to print the image which is a drawable object, So it will only display the address information as you see androidgraphics.drawable.bitmapdrawable#416e5
try
OutputData = Name;
you are setting background for button as
button.setBackgroundResource(R.drawable.button_color); are you sure that the image you expect is same as button_color, It sounds like a color.
you should do something as the following :
OutputData = Name;
then to add the text to the button do the following :
button.setText(OutputData);
and to add the image to the button do the following :
btn.setBackgroundResource(resId);
and give me some feedback
Hope that helps .
Related
This question already has answers here:
What is a NullPointerException, and how do I fix it?
(12 answers)
Closed 4 years ago.
I am trying to select the first index in listview on first load onCreate. I've try the listView.setSelection(0) but some error occur. this is my code...
public class QandAPractice extends AppCompatActivity {
String qsid;
ListView listView;
ArrayList<String> myqid;
RadioButton r1,r2,r3,r4;
String txtcontent, txtTimer,txtAnskey,txtImg, txtA, txtB, txtC, txtD, txtID;
private static final String TAG_QID = "id";
private static final String TAG_TITLE = "content";
private static final String TAG_TIMER = "timer";
private static final String TAG_IMAGE = "images";
private static final String TAG_QSID = "qsid";
private static final String TAG_KEY = "key";
private static final String TAG_A = "A";
private static final String TAG_B = "B";
private static final String TAG_C = "C";
private static final String TAG_D = "D";
ArrayList<HashMap<String, String>> questions;
Dialog quizDialog;
public int i = 60;
public int loadindex = 0;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_qand_apractice);
questions = new ArrayList<>();
myqid = new ArrayList<>();
Bundle b = getIntent().getExtras();
setTitle(b.getString("subject"));
qsid = b.getString("qsid");
quizDialog = new Dialog(this,android.R.style.Theme_Black_NoTitleBar_Fullscreen);
listView = findViewById(R.id.lvquestions);
getJSON(Constants.ROOT_URL+"mobile_question_index.php?qsid="+qsid);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
txtID = ((TextView) view.findViewById(R.id.quiz_id)).getText()
.toString();
txtcontent = ((TextView) view.findViewById(R.id.quiz_content)).getText()
.toString();
txtTimer = ((TextView) view.findViewById(R.id.quiz_timer)).getText()
.toString();
txtAnskey = ((TextView) view.findViewById(R.id.quiz_key)).getText()
.toString();
txtA = ((TextView) view.findViewById(R.id.quiz_A)).getText()
.toString();
txtB = ((TextView) view.findViewById(R.id.quiz_B)).getText()
.toString();
txtC = ((TextView) view.findViewById(R.id.quiz_C)).getText()
.toString();
txtD = ((TextView) view.findViewById(R.id.quiz_D)).getText()
.toString();
txtImg = ((TextView) view.findViewById(R.id.quiz_image)).getText()
.toString();
showQuiz();
}
});
listView.setSelection(0);
listView.getSelectedView().setSelected(true);
}
private void getJSON(final String urlWebService) {
class GetJSON extends AsyncTask<Void, Void, String> {
#Override
protected void onPreExecute() {
super.onPreExecute();
}
#Override
protected void onPostExecute(String s) {
super.onPostExecute(s);
try {
loadIntoListView(s);
} catch (JSONException e) {
e.printStackTrace();
}
}
#Override
protected String doInBackground(Void... voids) {
try {
URL url = new URL(urlWebService);
HttpURLConnection con = (HttpURLConnection) url.openConnection();
StringBuilder sb = new StringBuilder();
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(con.getInputStream()));
String json;
while ((json = bufferedReader.readLine()) != null) {
sb.append(json + "\n");
}
return sb.toString().trim();
} catch (Exception e) {
return null;
}
}
}
GetJSON getJSON = new GetJSON();
getJSON.execute();
}
private void loadIntoListView(String json) throws JSONException {
JSONArray jsonArray = new JSONArray(json);
//String[] question = new String[jsonArray.length()];
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject obj = jsonArray.getJSONObject(i);
String id = obj.getString(TAG_QID);
String content = obj.getString(TAG_TITLE);
String image = obj.getString(TAG_IMAGE);
String a = obj.getString(TAG_A);
String b = obj.getString(TAG_B);
String c = obj.getString(TAG_C);
String d = obj.getString(TAG_D);
String key = obj.getString(TAG_KEY);
String timer = obj.getString(TAG_TIMER);
HashMap<String, String> map = new HashMap<String, String>();
map.put(TAG_QID,id);
map.put(TAG_TITLE,content);
map.put(TAG_IMAGE,image);
map.put(TAG_A,a);
map.put(TAG_B,b);
map.put(TAG_C,c);
map.put(TAG_D,d);
map.put(TAG_KEY,key);
map.put(TAG_TIMER,timer);
myqid.add(id);
questions.add(map);
}
// ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, question);
SimpleAdapter adapter = new SimpleAdapter(
QandAPractice.this, questions,
R.layout.quizlayout, new String[]{TAG_QID,
TAG_TITLE, TAG_IMAGE,TAG_A,TAG_B,TAG_C,TAG_D,TAG_KEY,TAG_TIMER},
new int[]{R.id.quiz_id, R.id.quiz_content, R.id.quiz_image,R.id.quiz_A,R.id.quiz_B,
R.id.quiz_C,R.id.quiz_D,R.id.quiz_key,R.id.quiz_timer});
/* AtomicReference<ListAdapter> la =
new AtomicReference<>(new ListAdapter(getApplicationContext(), questions));*/
listView.setAdapter(adapter);
}
this is the Error fetch in debug logcat..
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.view.View.setSelected(boolean)' on a null object reference
at com.example.jhan08.engineeringexclusivereviewer.QandAPractice.onCreate(QandAPractice.java:90)
at android.app.Activity.performCreate(Activity.java:6351)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1114)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2470)
I've read some thread that has the same issue like mine. They use adapter to fix the issue but still in my case this error still occur. Any help is much appreciated.
Do Your Selection after you set Your Adapter to the Listview
private void loadIntoListView(String json) throws JSONException {
JSONArray jsonArray = new JSONArray(json);
//String[] question = new String[jsonArray.length()];
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject obj = jsonArray.getJSONObject(i);
String id = obj.getString(TAG_QID);
String content = obj.getString(TAG_TITLE);
String image = obj.getString(TAG_IMAGE);
String a = obj.getString(TAG_A);
String b = obj.getString(TAG_B);
String c = obj.getString(TAG_C);
String d = obj.getString(TAG_D);
String key = obj.getString(TAG_KEY);
String timer = obj.getString(TAG_TIMER);
HashMap<String, String> map = new HashMap<String, String>();
map.put(TAG_QID,id);
map.put(TAG_TITLE,content);
map.put(TAG_IMAGE,image);
map.put(TAG_A,a);
map.put(TAG_B,b);
map.put(TAG_C,c);
map.put(TAG_D,d);
map.put(TAG_KEY,key);
map.put(TAG_TIMER,timer);
myqid.add(id);
questions.add(map);
}
// ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, question);
SimpleAdapter adapter = new SimpleAdapter(
QandAPractice.this, questions,
R.layout.quizlayout, new String[]{TAG_QID,
TAG_TITLE, TAG_IMAGE,TAG_A,TAG_B,TAG_C,TAG_D,TAG_KEY,TAG_TIMER},
new int[]{R.id.quiz_id, R.id.quiz_content, R.id.quiz_image,R.id.quiz_A,R.id.quiz_B,
R.id.quiz_C,R.id.quiz_D,R.id.quiz_key,R.id.quiz_timer});
/* AtomicReference<ListAdapter> la =
new AtomicReference<>(new ListAdapter(getApplicationContext(), questions));*/
listView.setAdapter(adapter);
listView.setSelection(0);
listView.getSelectedView().setSelected(true);
}
I think I got the main issue you have faced. You try to select an item before populating the list view. You need to set this after adapter added on the listview.
Add this lines after adding the adapter.
listView.setAdapter(adapter);
listView.setSelection(0);
listView.getSelectedView().setSelected(true);
or use
listView.setAdapter(adapter);
listView.setItemChecked(0, true)
This will show a toast message for first opening. This should be added after the adapter set.
Iterator myVeryOwnIterator = questions.get(0).keySet().iterator();
while(myVeryOwnIterator.hasNext()) {
String key=(String)myVeryOwnIterator.next();
String value=(String)meMap.get(key);
Toast.makeText(ctx, "Key: "+key+" Value: "+value, Toast.LENGTH_LONG).show();
}
I am trying to understand why a click on a listview item from activity1 takes a log time (around 1 second) to open the second activity.
It seems that my code has an implementation or a performance problem ..
The first activity (Main) displayed a listview.
The second activity (Detail_annonce) displayed details of a listview item.
Here is extract of code of my first activity (Main) for bind click on listview item :
list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Annonce currentAnnonce = (Annonce) list.getAdapter().getItem(position);
String titre = currentAnnonce.getTitle();
String cat = currentAnnonce.getCategorie();
String desc = currentAnnonce.getDescription();
String etat = currentAnnonce.getEtat();
String img = currentAnnonce.getImage();
String prix = currentAnnonce.getPrix();
String villeObj = currentAnnonce.getVilleObjet();
String codePostal = currentAnnonce.getCode_postal();
String departement = currentAnnonce.getDepartement();
String avatarUser = currentAnnonce.getImageUser();
String pseudoUser = currentAnnonce.getPseudoUser();
String dateDebut = currentAnnonce.getDate_debut();
String idAnnonce = currentAnnonce.getId();
String emailUser = currentAnnonce.getEmailUser();
String partel = currentAnnonce.getPartel();
String parmail = currentAnnonce.getParmail();
Intent myIntent = new Intent(Main_All_Annonces.this, Detail_annonce.class);
myIntent.putExtra("titre", titre);
myIntent.putExtra("cat", cat);
myIntent.putExtra("desc", desc);
myIntent.putExtra("etat", etat);
myIntent.putExtra("img", img);
myIntent.putExtra("prix", prix);
myIntent.putExtra("villeObj", villeObj);
myIntent.putExtra("codePostal", codePostal);
myIntent.putExtra("departement", departement);
myIntent.putExtra("avatarUser", avatarUser);
myIntent.putExtra("pseudoUser", pseudoUser);
myIntent.putExtra("dateDebut", dateDebut);
myIntent.putExtra("idAnnonce", idAnnonce);
myIntent.putExtra("emailUser", emailUser);
myIntent.putExtra("partel", partel);
myIntent.putExtra("parmail", parmail);
myIntent.putExtra("parentAct", "AllAnnonces");
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
// get the common element for the transition in this activity
final View image_view = findViewById(R.id.allannonces_image);
//String transitionName = (String) view.getTag(R.id.allannonces_image);
ActivityOptionsCompat options =
ActivityOptionsCompat.makeSceneTransitionAnimation(
Main_All_Annonces.this,
view, // The view which starts the transition
"transitionImg" // The transitionName of the view we’re transitioning to
);
// put more extras in the intent if you want, like the object clicked
myIntent.putExtra("EXTRA_IMAGE_TRANSITION_NAME", "transitionImg");
ActivityCompat.startActivity(Main_All_Annonces.this, myIntent, options.toBundle());
}
else {
// Code to run on older devices
startActivity(myIntent);
overridePendingTransition(R.anim.left_to_right, R.anim.right_to_left);
}
}
});
Here is the code on my Detail_annonce activity :
public class Detail_annonce extends Activity {
HttpPost httppost;
StringBuffer buffer;
HttpClient httpclient;
List<NameValuePair> nameValuePairs;
ProgressDialog dialog = null;
DisplayImageOptions options;
LinearLayout btn_mail, btn_tel, btn_share;
View bar1, bar2;
String partel, parmail;
TextView nbAnnonceActionBar ;
#SuppressWarnings("unused")
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.detail_layout);
Typeface robotolight = Typeface.createFromAsset(getApplicationContext().getAssets(), "fonts/Roboto/Roboto-Light.ttf");
Typeface robotoBold = Typeface.createFromAsset(getApplicationContext().getAssets(), "fonts/Roboto/Roboto-Bold.ttf");
Typeface robotoRegular = Typeface.createFromAsset(getApplicationContext().getAssets(), "fonts/Roboto/Roboto-Regular.ttf");
bar1 = (View) findViewById(R.id.detail_view1);
bar2 = (View) findViewById(R.id.detail_view2);
options = new DisplayImageOptions.Builder()
.displayer(new RoundedBitmapDisplayer(2000))
.cacheOnDisc(true)
.build();
Intent previous = getIntent();
Bundle extras = previous.getExtras();
final String titre = extras.getString("titre");
String cat = extras.getString("cat");
String desc = extras.getString("desc");
String img = extras.getString("img");
final String prix = extras.getString("prix");
final String villeObj = extras.getString("villeObj");
final String codePostal = extras.getString("codePostal");
String avatarUser = extras.getString("avatarUser");
final String pseudoUser = extras.getString("pseudoUser");
String dateDebut = extras.getString("dateDebut");
final String idAnnonce = extras.getString("idAnnonce");
final String emailUser = extras.getString("emailUser");
partel = extras.getString("partel");
parmail = extras.getString("parmail");
String parentAct = extras.getString("parentAct");
ImageView image_txt = (ImageView) findViewById(R.id.detail_annonce_image);
TextView titre_txt = (TextView) findViewById(R.id.detail_annonce_titre);
TextView prix_txt = (TextView) findViewById(R.id.detail_annonce_prix);
TextView dateDebut_txt = (TextView) findViewById(R.id.detail_annonce_date_debut);
TextView villeAndCodePostal = (TextView) findViewById(R.id.detail_annonce_ville_and_codePos);
ImageLoader imageLoader = ImageLoader.getInstance();
Double latitude = null, longitude = null;
Geocoder geo = new Geocoder(getBaseContext(), Locale.getDefault());
try {
List<Address> addresses = geo.getFromLocationName(villeObj, 10);
Address currentFound = addresses.get(0);
if (currentFound.hasLatitude() && currentFound.hasLongitude()) {
latitude = currentFound.getLatitude();
longitude = currentFound.getLongitude();
}
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
ViewCompat.setTransitionName(image_txt, getIntent().getStringExtra("EXTRA_IMAGE_TRANSITION_NAME"));
imageLoader.displayImage(img, image_txt);
titre_txt.setText(titre);
titre_txt.setTypeface(robotoRegular);
prix_txt.setText("€" + prix + ",00 EUR");
prix_txt.setTypeface(robotolight);
villeAndCodePostal.setText("Disponible à " +villeObj);
villeAndCodePostal.setTypeface(robotolight);
////////////////
/// DATE
////////////////
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault());
Date pDate;
try {
pDate = df.parse(dateDebut);
dateDebut = DateUtils.getDateDifference(pDate);
dateDebut = dateDebut.replace("-", "");
} catch (ParseException e) {
Log.e("DATE PARSING", "Error parsing date..");
}
dateDebut_txt.setText("Posté il y a " + dateDebut + "dans la catégorie " +cat);
dateDebut_txt.setTypeface(robotolight);
if (latitude != null && longitude != null ) {
// Get a handle to the Map Fragment
GoogleMap map = ((MapFragment) getFragmentManager() .findFragmentById(R.id.map)).getMap();
LatLng ville = new LatLng(latitude, longitude);
map.setMyLocationEnabled(true);
map.moveCamera(CameraUpdateFactory.newLatLngZoom(ville, 9));
map.addMarker(new MarkerOptions()
.title(villeObj)
.visible(true)
.snippet("La vente se fait à cet adresse.")
.position(ville));
}
}
When Android starts your new Activity, it executes all of the code in onCreate() before it displays anything.
Typically what I do (as a professional Android developer) is only grab the Views I keep as class variables in the onCreateView() and then put all of my populating code in onStart(). If it takes time for your Activity to show data after switching Activities, you can put a ProgressSpinner view in front so your user knows that data is still being processed.
In your case, absolutely take ALL of your Google Maps code out of onCreate(). Google Maps is extremely popular and sometimes the server takes a while to serve your request.
Side Notes:
I agree with the commenter about transmitting your Object as an extra. To do this, you have to mark your Object as Serializable. See this SO question. Look at the most highly-voted answer, not the "accepted" one.
Modularize your code! Separate some of that stuff into helper methods which then get called in your onCreateView() and onStart() methods. It'll make moving code around a lot easier.
You should look into using a single Actvitity and just using Fragments for all of your separate screens (excluding popups). Fragments can help keep your code more Object-Oriented and keep you from repeating so much code. Google also seems to be pushing the Fragment-Decorator design pattern pretty hard. This, however, ultimately comes down to personal preference.
Edit: More info about Activity lifecycle methods here. Notice how the onCreate() is called before the diagram states that the Activity is "created".
Use GSON library. This is will be good for you.
Am getting the results as in dynamic buttons, but i want to display that in gridview.here is my code
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 resName = jsonChildNode.getString("image_url");
OutputData = Name;
str_id = Pid;
// OutputData += "pid : "+ Pid +" "+ "content : "+ Name+" ";
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.setLayoutParams(params);
//Button new width
params.width = 64;
params.height = 64;
button.setText(OutputData);
int resId = getResources().getIdentifier(resName, "drawable", getPackageName());
button.setBackgroundResource(resId);
button.setGravity(Gravity.BOTTOM|Gravity.CENTER_HORIZONTAL);
button.setTextSize(13);
}
button.setTag(Refid);
button.setTextColor(Color.parseColor("#FF0000"));
buttonContainer.addView(button);
button.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
LinearLayout buttonContainer = (LinearLayout)findViewById(R.id.btn_container);
buttonContainer.removeAllViews();
What is the amount of data in json?
Parse json and Get your data into a model class using Gson, refer:
Unable to Loop through dynamic json string recursively in android
And pass the ArrayList of the class objects to a custom adapter for the gridview, refer:
http://www.learn-android-easily.com/2013/09/android-custom-gridview-example.html
http://www.mkyong.com/android/android-gridview-example/
http://www.technotalkative.com/android-gridview-example/
I am able to send selected listview text to another activity using xml parsing, but not able to fetch selected image to next activity, here I am placing my code, please find out the reason why I am not getting image to another activity:-
MainActivity Code:-
list.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
HashMap<String, String> map = pizzaList.get(position);
Intent in = new Intent(MainActivity.this, SecondActivity.class);
in.putExtra(KEY_TITLE, map.get(KEY_TITLE));
in.putExtra(KEY_DESCRIPTION, map.get(KEY_DESCRIPTION));
in.putExtra(KEY_THUMB_URL, map.get(KEY_THUMB_URL));
in.putExtra(KEY_COST, map.get(KEY_COST));
startActivity(in);
}
});
SecondActivity Code:-
Intent in = getIntent();
final String title = in.getStringExtra(KEY_TITLE);
final String description = in.getStringExtra(KEY_DESCRIPTION);
final String thumb_url = in.getStringExtra(KEY_THUMBURL);
final String cost = in.getStringExtra(KEY_COST);
TextView title = (TextView) findViewById(R.id.single_title);
TextView description = (TextView) findViewById(R.id.single_description);
TextView cost = (TextView) findViewById(R.id.single_cost);
ImageLoader imageLoader = new ImageLoader(getApplicationContext());
ImageView thumb = (ImageView) findViewById(R.id.single_image);
title.setText(title);
description.setText(description);
cost.setText(cost);
imageLoader.DisplayImage(thumb_url, thumb);
I think your KEY_THUMB_URL is your url just call this method in your second Activity this is return a bitmap then this bitmap set you on your image view
public static Bitmap loadBitmap(String imgPath) {
String imgUrlStr = imgPath ;
Bitmap bitmap = null;
try {
bitmap = BitmapFactory.decodeStream((InputStream)new URL(imgUrlStr).getContent());
}
catch (MalformedURLException e) {
e.printStackTrace();
}
catch (IOException e) {
e.printStackTrace();
}
return bitmap;
}
final String title = in.getStringExtra(KEY_TITLE);
final String description = in.getStringExtra(KEY_DESCRIPTION);
final String thumb_url = in.getStringExtra(KEY_THUMBURL);
log.i("log_tag","Image URl:"+thumb_url);
final String cost = in.getStringExtra(KEY_COST);
TextView title = (TextView) findViewById(R.id.single_title);
TextView description = (TextView) findViewById(R.id.single_description);
TextView cost = (TextView) findViewById(R.id.single_cost);
ImageView thumb = (ImageView) findViewById(R.id.single_image);
title.setText(title);
description.setText(description);
cost.setText(cost);
Drawable d = LoadImageFromWebOperations(ImageUrl);
imageView.setImageDrawable(d);
public static Drawable LoadImageFromWebOperations(String url) {
try {
InputStream is = (InputStream) new URL(url).getContent();
Drawable d = Drawable.createFromStream(is, "src name");
return d;
} catch (Exception e) {
return null;
}
}
I found the reason why I was not getting an image into next activity.
I did very small mistake, see line below, which I was using earlier :
final String thumb_url = in.getStringExtra(KEY_THUMBURL);
And now I have tried with:
final String imageUri = in.getStringExtra(KEY_THUMBURL);
Because I am using this variable:
static final String KEY_THUMBURL = "imageUri";
for(int i=0;i<StoreparsrData.title.size();i++){
HashMap<String,String> temp = new HashMap<String,String>();
Bitmap bt=Utility.getBitmapFile(StoreparsrData.url.get(i).toString());
ImageView img=(ImageView)findviewbyid(R.id.img);
img.setImageBitmap(bt);
but iwant to convert this img.setImageBitmap(bt); to string so its input for
temp.put("image",image );
temp.put("title",StoreparsrData.title.get(i).toString());
temp.put("description", StoreparsrData.description.get(i).toString());
temp.put("lastbuilddate", StoreparsrData.lastBuildDate.get(0).toString());
list.add(temp);
}
so its show image
Pls Reply me
If I'm understanding your question, why not use:
temp.put("image",StoreparsrData.url.get(i).toString());
Then perform the ImageView lookup when you read from the list
EDIT
Here's another approach:
public class ParseBean {
private ImageView image;
private String title;
private String description;
private String lastBuildDate;
// add getters and setters here
}
...
for(int i=0;i<StoreparsrData.title.size();i++){
HashMap<String,ParseBean> temp = new HashMap<String,ParseBean>();
Bitmap bt=Utility.getBitmapFile(StoreparsrData.url.get(i).toString());
ImageView img=(ImageView)findviewbyid(R.id.img);
img.setImageBitmap(bt);
ParseBean bean = new ParseBean();
bean.setImage(img);
bean.setTitle(StoreparsrData.title.get(i).toString());
bean.setDescription(StoreparsrData.description.get(i).toString());
bean.setLastBuildDate(StoreparsrData.lastBuildDate.get(0).toString());
list.add(bean);
}