Stackflowers!
Little question.. I load text into a textView who is in a listView. I load the text out of an url. Everything works fine.. But.. Sometimes in the text there is an new url with an image. I can filter the text, and show the url only in a Log or something, no problem. But now.. I have many textView in my listView.. But now, when I detect a new image url, I want to create or show the image in an imageView. (To load the image is not a problem to..) But the problem is, how to hide all the imageViews.. Untill I (or my code..) detects an image url (.jpg)?
But sometimes there is one image.. on the 1st position of my listView.. Sometimes there are maybe 2 or 3 images.. On position 1, 5, 7.. I don't know that of beforehand..
This is my View Class:
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View item_view_second = convertView;
post_second current_post = my_post_second.get(position);
Typeface TF = Typeface.createFromAsset(getAssets(), global.fontType_title);
Typeface tf = Typeface.createFromAsset(getAssets(), global.fontType_text);
if (item_view_second == null) {
item_view_second = getLayoutInflater().inflate(R.layout.item_view_second, parent, false);
}
// Title:
TextView title_text = (TextView) item_view_second.findViewById(R.id.item_title);
if(position == 0) {
title_text.setVisibility(View.VISIBLE);
title_text.setText(Html.fromHtml(current_post.get_title()));
title_text.setTypeface(TF);
} else {
title_text.setVisibility(View.GONE);
}
// Blog:
TextView blog_text = (TextView) item_view_second.findViewById(R.id.item_blog);
blog_text.setText(Html.fromHtml(current_post.get_blog()));
Linkify.addLinks(blog_text, Linkify.WEB_URLS);
blog_text.setTypeface(tf);
// Image:
img_loader = new image_loader(second_activity.this);
img_view = (ImageView) item_view_second.findViewById(R.id.item_image);
// img_view.setTag(current_post.get_image_id());
img_loader.DisplayImage(current_post.get_image(), img_view);
// Log.e("img_view.ID-Tag", "Found:" + img_view.getTag());
return item_view_second;
}
}
This is the part where I detect the url with:
for (int j = 0; j < counter_blog; j++) {
if (s != null) {
s = dis.readLine();
s.substring(s.indexOf("<p>") + 3, s.indexOf("</p>"));
if(s.contains("<p><a href=")) {
image[j] = s.substring(s.indexOf("<a href=") + 9, s.indexOf(".jpg")+ 4);
blog[j] = image[j];
} else {
blog[j] = s;
}
}
counter_blog_stop = j + 1;
}
And over here I use the counter_blog_stop :)
private void populate_post_list() {
for (int i = 0; i < 1; i++) {
for (int j = 0; j < counter_blog_stop; j++) {
my_post_second.add(new post_second(title[i], image[j], blog[j], image_id[j]));
}
}
}
private void populate_list_view() {
ArrayAdapter<post_second> adapter = new my_list_adapter_second();
global.list = (ListView) findViewById(R.id.post_second_list_view);
global.list.setAdapter(adapter);
}
I hope my question was clear enough.. When it is not.. Please make a comment, and I'll answer is so soon as possible!
P.S. When I load my activity now, I see the Title on the first position in my listview.. below, an imageview (with a standard image?!) below the Blog, below again a standard image, blog, the whole listview.. Untill there are no Blogs anymore..
Edit:
If there are urls detected, they shown perfect in my listView.. But every time there is no image url.. He post an standard imageView.. And I use only a textView called id:item_title and a imagrView called item_image in my listView.