Android - pass additional information to ListView without displaying it to an RSS reader?

I am parsing an RSS feed using SAX

messages = parser.parse();
List<String> titles = new ArrayList<String>(messages.size());
for (Message msg : messages){
    titles.add(msg.getTitle() + "\n" +msg.getDate() + "\n\n" + msg.getDescription());
 }
ArrayAdapter<String> adapter = 
                new ArrayAdapter<String>(this, R.layout.row,titles);
this.setListAdapter(adapter);

This creates a good list with the whole message included, but I would just like to show the name and date in the list.

Here is my onListItemClick right now

protected void onListItemClick(ListView l, View v, int position, long id) {
        super.onListItemClick(l, v, position, id);
        String selection = l.getItemAtPosition(position).toString();
        Dialog dialog = new Dialog(this);
            dialog.setContentView(R.layout.single);
            dialog.setTitle("Blog");
            dialog.setCancelable(true);
            TextView text = (TextView) dialog.findViewById(R.id.SinglePost);
            text.setText(selection);
            dialog.show();

    }

but it just pops up what is on the list.

Is there a way to pass a description to a list without showing it, so when they click on a list item, is there only a description in the dialog box? Thank!

+3
source share
1 answer

create a separate array containing only descriptions:

List<String> descriptions = new ArrayList<String>();
for(Message msg : messages){
    descriptions.add(msg.getDescription());
    titles.add(msg.getTitle() + "\n" +msg.getDate());
}

protected void onListItemClick(ListView l, View v, int position, long id) {
        super.onListItemClick(l, v, position, id);
        String description = descriptions.get(position);
        Dialog dialog = new Dialog(this);
            dialog.setContentView(R.layout.single);
            dialog.setTitle("Blog");
            dialog.setCancelable(true);
            TextView text = (TextView) dialog.findViewById(R.id.SinglePost);
            text.setText(description);
            dialog.show();

    }
+2
source

Source: https://habr.com/ru/post/1782512/


All Articles