我有一个自定义对话框....我需要始终将其方向更改为横向模式

时间:2014-05-07 09:02:01

标签: android android-layout

我有一个扩展Dialog的类。我正在调用它的构造函数并将一个arraylist传递给它。此对话框有一个列表视图,我想将其方向设置为LANDSCAPE模式。

以下是我调用Dialog的构造函数的方法:

itemsList = itemXMLHandler.getItemsList();

 ManagePartListActivity partListActivity = new ManagePartListActivity(mActivity,itemsList);
 Window window = partListActivity.getWindow();
 WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
 lp.copyFrom(window.getAttributes());
 //This makes the dialog take up the full width
 lp.width = WindowManager.LayoutParams.MATCH_PARENT;
 lp.height = WindowManager.LayoutParams.MATCH_PARENT;
 window.setAttributes(lp);
 partListActivity.setTitle("Manage Part");
 partListActivity.show();

这是我的课程,扩展对话

public class ManagePartListActivity extends Dialog{

 static ListView listView;
ArrayList<ManagePartResponse> list = new ArrayList<ManagePartResponse>();
Context context;
BaseBarcodeActivity mContext;
private static CustomAdapter adapter;

public ManagePartListActivity(ManagePartActivity context,
        ArrayList<ManagePartResponse> itemsList) {
    // TODO Auto-generated constructor stub
    super(context);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.activity_managepart_list);
    this.list=itemsList;
    listView = (ListView) findViewById(R.id.list);

            adapter = new CustomAdapter(getContext(), list);
            listView.setAdapter(adapter);
//              listView.setAdapter(new CustomAdapter(getContext(),list));
        adapter.notifyDataSetChanged();
        System.out.println("after notify");
        listView.invalidateViews();
    System.out.println("after invalidate");



    listView.setOnItemClickListener(new OnItemClickListener() {

        public void onItemClick(AdapterView<?> parent, View view, int position,
                long id) {

            Log.d("LIST", "listview clicked");

            ManagePartResponse managePartResponse =  list.get(position);

            //old logic
  //                Intent intent = new Intent(getContext(), MngePrtListClickActivity.class);
//              
//              intent.putExtra("image", managePartResponse.getImage());
//              intent.putExtra("make", managePartResponse.getMake());
//              intent.putExtra("model",managePartResponse.getModel());
//              intent.putExtra("partName", managePartResponse.getPartName());
//              intent.putExtra("year", managePartResponse.getYear());
//              intent.putExtra("partID", managePartResponse.getStockref());
//              getContext().startActivity(intent);
            String stockref = managePartResponse.getStockref();

            //new logic
             new StockIdSearchManage(getContext(), managePartResponse.getStockref(), "");
  //                 new StockIdManage(getContext(), stockref, "");
 //             Intent intent2 = new Intent(getContext(), ShowStockIdManageActivity.class);



        }
    });

}



public static void finishImg() {
    System.out.println("Finisheddddddd");
    adapter.notifyDataSetChanged();
    System.out.println("after notify");
    listView.invalidateViews();
}

2 个答案:

答案 0 :(得分:1)

这里最简单的方法 - 使用Dialog主题创建Activity:

<activity android:name=".ManagePartListActivity"
          android:screenOrientation="landscape"
          android:theme="@android:style/Theme.Dialog">

答案 1 :(得分:0)

setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); 

但它仅适用于Activity。 不要以为你可以为对话设置相同的smthng。

您应该为父Activity设置此参数。

或者您可以在Manifest.xml中设置它