tags:

views:

57

answers:

2

Hi,

I currently have a list and would like to display a large amount of text once a list item has been clicked. The amount of text will vary depending on the list item that's been clicked, ranging anything from a paragraph to a number of paragraphs.

I'm still very much an Android noob, so any tutorials that you know of that relate to your answer would be most appreciated.

Thank you.

A: 

The specifics are up to how you want your App to look and feel, but I would say you cant go wrong with a textView with wrap_content for height and width, nested inside a scroll view.

Probably set that inside a custom dialog to pop up when the list is clicked, or make another activity to just show the text.

blindstuff
A: 

Depending on what type of information you are displaying, you might want to just have the ListView item redirect to an activity specifically for displaying this information in a nicely organized manner.

If there is going to be a lot of information (and interactivity such as links), then I recommend the new activity.

Pro: Flow! User can navigate back to your list.

Con: It's a new activity

Otherwise you could use a dialog or similar to show the information on the same activity as the list.

Short sample:

// bind your adapter here from database or wherever
String[] Columns = { "_id", "Name", "Description" };
    int[] ItemIDs = { R.id.lbl_ID, R.id.lbl_Name, R.id.lbl_Description };
    SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, R.layout.item, cursor, Columns, ItemIDs);


ListView list_list= (ListView)findViewById(R.id.list);
list_list.setAdapter(adapter);

list.setOnItemClickListener(new OnItemClickListener(){
            @Override
            public void onItemClick(AdapterView parent, View view, int position, long id)
            {
                try
                {

                    Intent i = new Intent(getBaseContext(), ViewItemDetail.class);

                    i.putExtra("ID", ID);
                            // any other data you need to pass on to your view here.  ID should let you select from a database or however you are pulling data
                    startActivity(i);
                }
                catch(Exception ex)
                {
                    Log.println(1, "item-click-event", ex.getMessage());
                }
            }
        });


 // Then in your activity to get intent data:
 Bundle extras = getIntent().getExtras();
 if(extras !=null)
 {
     string ID = extras.getString("ID");
 }
Bryan Denny
This sounds like just the ticket, the text is simply to inform but could include interactivity at a later stage. Would you have links or anything on how to implement such a thing? Unfortunately my Android knowledge is very limited. Thanks.
mattFllr
@matt I can't find a good tutorial, but I included a short sample in my answer, I hope it helps
Bryan Denny