简体   繁体   English

显示大量文本的最佳方式?

[英]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. 我仍然是一个Android noob,所以你知道的任何与你的答案有关的教程都会非常感激。

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. 具体取决于你希望你的应用程序的外观和感觉,但我会说你的高度和宽度的wrap_content,嵌套在滚动视图内的textView不能出错。

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. 根据您显示的信息类型,您可能希望将ListView项重定向到专门用于以非常有条理的方式显示此信息的活动。

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 Con:这是一项新活动

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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