2012-11-22 57 views

回答

5
private void showPopUp() 
{ 
    final AlertDialog.Builder helpBuilder = new AlertDialog.Builder(this); 
    helpBuilder.setTitle(""); 

    LayoutInflater inflater = getLayoutInflater(); 
    final View PopupLayout = inflater.inflate(R.layout.yourxml, null); 
    helpBuilder.setView(PopupLayout); 

    final AlertDialog helpDialog = helpBuilder.create(); 
    helpDialog.show(); 

    jobList   = (ListView)PopupLayout.findViewById(R.id.list); 

    mylist   = new ArrayList<HashMap<String, String>>(); 

    for(int i=0;i<arraylist.size();i++) 
    { 
     map = new HashMap<String, String>(); 
     map.put("name", arraylist.get(i)); 
     mylist.add(map); 
    } 
    sd = new SimpleAdapter(activity.this,mylist,R.layout.jobslist, 
       new String[]{"name"},new int[]{R.id.jobText}); 
    jobList.setAdapter(sd); 


} 

joblist.xml

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/lin01" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:background="#fff" 
android:padding="10dp" 
android:orientation="horizontal"> 

     <TextView 
      android:id="@+id/jobText" 
      android:layout_width="0dp" 
      android:text="@string/jobtype" 
      android:layout_weight="1" 
      android:gravity="left|center_vertical" 
      android:layout_marginLeft="10dp" 
      android:textSize="25dp" 
      android:textColor="#000" 
      android:layout_height="50dp"/> 

     <CheckBox 
      android:id="@+id/chk" 
      android:layout_width="wrap_content" 
      android:text="" 
      android:gravity="center_vertical|right" 
      android:layout_height="wrap_content"/> 


     </LinearLayout> 

,無論你想顯示與列表視圖的警告對話框中,你可以調用這個函數showPopUp();。請注意,會有數組列表,您可以添加項目以顯示列表中的項目

2
ListView myList = new ListView(Activity.this); 
    myList.setAdapter(adapter); 

    AlertDialog.Builder builder = new AlertDialog.Builder(Activity.this); 
    builder.setView(myList); 
    Dialog d = builder.create(); 
    d.show(); 

您可以指定文本視圖和複選框以及適配器中的其他內容。