我有:
popUp.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
....
<Button
android:id="@+id/ok_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ok"
android:gravity="left"
/>
</LinearLayout>
main.java
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ListView listView = (ListView)findViewById(R.id.list);
listView.setOnItemClickListener(new OnItemClickListener()
{
public void onItemClick(AdapterView<?> parent, View v,
int position, long id)
{
popUp();
}
});
我在这里得到力量
public void popUp(){
LayoutInflater inflater = (LayoutInflater) project.this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
final PopupWindow pw = new PopupWindow(inflater.inflate(R.layout.popup,null, false),300,400,true);
ok_button = (Button) findViewById(R.id.ok_button);
pw.showAtLocation(findViewById(R.id.list), Gravity.BOTTOM, 0,10);
ok_button.setOnClickListener(new OnClickListener() { //here I get FC
@Override
public void onClick(View v) {
pw.dismiss();
}
});
}
}
当我使用 main.xml 中的按钮(在 popUp(); 中)而不是 popUp.xml 时,一切正常。使用 not main.xml 中的按钮有什么问题