简体   繁体   中英

Best way to display a large amount of text?

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.

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.

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");
 }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM