2015-07-10 74 views

回答

0

你可以使用這樣的事

public class ListPopupWindowAppActivity extends Activity 
implements OnItemClickListener { 
EditText productName; 
ListPopupWindow listPopupWindow; 
String[] products={"Camera", "Laptop", "Watch","Smartphone", 
    "Television"}; 

@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_list_popup_window_app); 
    productName = (EditText) findViewById(
     R.id.product_name); 
    listPopupWindow = new ListPopupWindow(
     ListPopupWindowAppActivity.this); 
    listPopupWindow.setAdapter(new ArrayAdapter(
     ListPopupWindowAppActivity.this, 
     R.layout.list_item, products)); 
    listPopupWindow.setAnchorView(productName); 
    listPopupWindow.setWidth(300); 
    listPopupWindow.setHeight(400); 

    listPopupWindow.setModal(true); 
    listPopupWindow.setOnItemClickListener(
     ListPopupWindowAppActivity.this); 
    productName.setOnClickListener(new OnClickListener() { 
     public void onClick(View v) { 
      listPopupWindow.show(); 
     } 
    }); 
} 

@Override 
public void onItemClick(AdapterView<?> parent, View view, 
    int position, long id) { 
    productName.setText(products[position]); 
    listPopupWindow.dismiss(); 
} 
} 

保持自定義適配器,如果你想用自定義行。希望這有助於某人如果是讓我認識的朋友:)