<bdo id='p3hXg'></bdo><ul id='p3hXg'></ul>

<small id='p3hXg'></small><noframes id='p3hXg'>

    1. <i id='p3hXg'><tr id='p3hXg'><dt id='p3hXg'><q id='p3hXg'><span id='p3hXg'><b id='p3hXg'><form id='p3hXg'><ins id='p3hXg'></ins><ul id='p3hXg'></ul><sub id='p3hXg'></sub></form><legend id='p3hXg'></legend><bdo id='p3hXg'><pre id='p3hXg'><center id='p3hXg'></center></pre></bdo></b><th id='p3hXg'></th></span></q></dt></tr></i><div id='p3hXg'><tfoot id='p3hXg'></tfoot><dl id='p3hXg'><fieldset id='p3hXg'></fieldset></dl></div>

    2. <tfoot id='p3hXg'></tfoot><legend id='p3hXg'><style id='p3hXg'><dir id='p3hXg'><q id='p3hXg'></q></dir></style></legend>

    3. 在对话框列表中设置文本样式

      时间:2023-09-28

        • <bdo id='dd5PA'></bdo><ul id='dd5PA'></ul>

          <legend id='dd5PA'><style id='dd5PA'><dir id='dd5PA'><q id='dd5PA'></q></dir></style></legend>
            <tbody id='dd5PA'></tbody>

        • <small id='dd5PA'></small><noframes id='dd5PA'>

              • <tfoot id='dd5PA'></tfoot>

                <i id='dd5PA'><tr id='dd5PA'><dt id='dd5PA'><q id='dd5PA'><span id='dd5PA'><b id='dd5PA'><form id='dd5PA'><ins id='dd5PA'></ins><ul id='dd5PA'></ul><sub id='dd5PA'></sub></form><legend id='dd5PA'></legend><bdo id='dd5PA'><pre id='dd5PA'><center id='dd5PA'></center></pre></bdo></b><th id='dd5PA'></th></span></q></dt></tr></i><div id='dd5PA'><tfoot id='dd5PA'></tfoot><dl id='dd5PA'><fieldset id='dd5PA'></fieldset></dl></div>

              • 本文介绍了在对话框列表中设置文本样式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                我使用了此处给出的说明:.

                I used the instructions given Here: http://developer.android.com/guide/topics/ui/dialogs.html#AddingAList to create a List in a dialog.

                The problem is I don't seem to find out a way to wrap long text inside the options. [Please see the image below]

                Please tell me how to do the text wrapping. :(

                I am using the following code:

                items= getArrayFromJson(source+"getdetails.php?brand="+bName+"&car="+cName);
                        builder = new AlertDialog.Builder(this);
                        builder.setTitle("Choose Model");
                        builder.setSingleChoiceItems(items, -1, new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int item) {
                                if(items[item].equals("No Options Available")){
                                    dismissDialog(2);
                                }
                                else{
                                    model.setText(items[item]);
                                    mName= items[item].toString();
                
                                    location.setEnabled(true);
                                    dismissDialog(2);
                                }
                
                            }
                        });
                        alert = builder.create();
                
                        return alert;
                

                Any help/direction is highly appreciated :)

                解决方案

                At first I would create a list layout... something like:

                list_layout

                    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:orientation="vertical" >
                
                     <ListView
                        android:id="@+id/list"
                        android:layout_width="fill_parent"
                        android:layout_height="wrap_content"
                        android:divider="#b5b5b5"
                        android:dividerHeight="1dp" />
                 </LinearLayout>
                

                Then a simple TextView like:

                single_item_layout

                 <LinearLayout 
                    xmlns:android="http://schemas.android.com/apk/res/android"
                    android:orientation="horizontal" 
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"> 
                
                     <TextView android:id="@+id/singleItem"
                        android:layout_width="fill_parent"
                        android:layout_height="fill_parent"
                        android:gravity="center_vertical"
                        android:layout_alignParentTop="true"
                        android:layout_alignParentBottom="true"
                        android:textStyle="bold"
                        android:textSize="22dp"
                        android:textColor="#FFFFFF"
                        android:padding="10dp"
                        android:text="blue thingy"
                        android:background="#336699" />
                
                </LinearLayout>
                

                and a simple main layout:

                main

                    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                    xmlns:tools="http://schemas.android.com/tools"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent" >
                
                    <Button
                        android:id="@+id/button1"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_alignParentBottom="true"
                        android:layout_alignParentLeft="true"
                        android:layout_alignParentRight="true"
                        android:onClick="popUp"
                        android:text="pop dialog list" />
                
                </RelativeLayout>
                

                lastly a simple main Activity:

                import java.util.ArrayList;
                import android.app.Activity;
                import android.app.Dialog;
                import android.os.Bundle;
                import android.view.View;
                import android.widget.AdapterView;
                import android.widget.AdapterView.OnItemClickListener;
                import android.widget.ArrayAdapter;
                import android.widget.ListView;
                
                public class MainActivity extends Activity {
                
                    @Override
                    public void onCreate(Bundle savedInstanceState) {
                        super.onCreate(savedInstanceState);
                        setContentView(R.layout.main);
                    }
                
                    public void popUp(View v){
                
                        // Dummy list:
                        ArrayList<String> dummies = new ArrayList<String>();
                
                        dummies.add("dumm1");
                        dummies.add("dumm2");
                        dummies.add("dumm3");
                        dummies.add("dumm4");
                        dummies.add("dumm5");
                
                        final Dialog dialog = new Dialog(MainActivity.this);
                        dialog.setContentView(R.layout.list_layout);
                        dialog.setTitle("List Title");
                        ListView listView = (ListView) dialog.findViewById(R.id.list);
                
                        ArrayAdapter<String> ad = new ArrayAdapter<String>(this, R.layout.single_item_layout , R.id.singleItem, dummies);
                        listView.setAdapter(ad);
                
                        listView.setOnItemClickListener(new OnItemClickListener() {
                            @Override
                            public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
                                //do something on click
                                dialog.dismiss();
                            }
                        });
                
                        dialog.show();
                    }   
                }
                

                and that's all.

                I tried to make that as simple as possible, you can google for ideas to make your list a bit attractive, like here.

                这篇关于在对话框列表中设置文本样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:没有可用于离线模式的 com.android.tools.build:aapt2: 下一篇:Android - 创建进度对话框

                相关文章

                最新文章

                <tfoot id='aArfa'></tfoot>

                <small id='aArfa'></small><noframes id='aArfa'>

                <i id='aArfa'><tr id='aArfa'><dt id='aArfa'><q id='aArfa'><span id='aArfa'><b id='aArfa'><form id='aArfa'><ins id='aArfa'></ins><ul id='aArfa'></ul><sub id='aArfa'></sub></form><legend id='aArfa'></legend><bdo id='aArfa'><pre id='aArfa'><center id='aArfa'></center></pre></bdo></b><th id='aArfa'></th></span></q></dt></tr></i><div id='aArfa'><tfoot id='aArfa'></tfoot><dl id='aArfa'><fieldset id='aArfa'></fieldset></dl></div>
                1. <legend id='aArfa'><style id='aArfa'><dir id='aArfa'><q id='aArfa'></q></dir></style></legend>

                      <bdo id='aArfa'></bdo><ul id='aArfa'></ul>