Question

Stackflowers!

I've a problem with my listview. I load data(text) from a webpage/url and load them in my listview. I have a title and a blog with the text (sometimes more blogs as shown below..).

But the problem is, he loads only 1 time the title, but shows it multiply times. (Shown below).

BBC News:

BBC Newsnight's political editor Emily Maitlis told the programme that she had spoken to the lawyers who are preparing the test case for the female prisoner, who is identified as BGJ and is serving a life sentence.

BBC News:

"She is an epilepsy sufferer, very highly qualified and she has said her life is in despair without access to these books, which have really been taking her through this life sentence that she will serve," she said.

BBC News:

Lawyers for the woman argue that the effects of the policy are particularly hard felt by women who depend on what they receive from the outside world to keep them motivated.

BBC News:

The MoJ said the lawyers had no grounds for their case because they had run out of time to make it.

How can I filter my listview? For only 1 title?

Thanks,

P.S. If somebody need some code, please ask! Thank you.

Update:

Part of code:

public class second_activity extends Activity {
private List<post_second> my_post_second = new ArrayList<post_second>();    

String title[] = new String[counter_title];
String blog[] = new String[counter_blog];

    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], blog[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);
}   

private class my_list_adapter_second extends ArrayAdapter<post_second> {
    public my_list_adapter_second() {
        super(second_activity.this, R.layout.item_view_second, my_post_second); 
    }

        @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        View item_view_second = convertView;
        if (item_view_second == null) {
            item_view_second = getLayoutInflater().inflate(R.layout.item_view_second, parent, false);
        }

        // Find the Post to work with.
        post_second current_post = my_post_second.get(position);

        // Title:
        TextView title_text = (TextView) item_view_second.findViewById(R.id.item_title);
        title_text.setText(Html.fromHtml(current_post.get_title()));

        // Blog:
        TextView blog_text = (TextView) item_view_second.findViewById(R.id.item_blog);
        blog_text.setText(Html.fromHtml(current_post.get_blog()));

        return item_view_second;
    }               
}
Was it helpful?

Solution

Here you have added the title for each and every row.

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]**, blog[j]));
        }
    }

So you can hide the title if the row is not the first one by

 // 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()));
}
else{
        title_text.setVisibility(View.GONE);
}

OTHER TIPS

Its better you can use Expandable ListView for your case. Else you can hide the title layout in your adapter wherever you don't need of it. We can't conclude until you post your code. Better you can post your code.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top