3

我正在运行一个应用程序,它打开一个地图,上面有一个标记。

单击标记时,我试图打开一个对话框,其中包含一些字段。这是我的标记点击代码,

public boolean onMarkerClick(Marker arg0) {

    Log.d("", "here");
    View view = getLayoutInflater().inflate(R.layout.dialogview, null);
    view.setBackgroundColor(Color.LTGRAY);
    edtDate = (TextView) view.findViewById(R.id.edtDate);

    edtTime = (TextView) view.findViewById(R.id.edtTime);

    Dialog dialog = new Dialog(this,
            android.R.style.TextAppearance_Holo_WindowTitle);
    dialog.setTitle("Enter Details");
    LayoutParams lp = dialog.getWindow().getAttributes();
    lp.width = WindowManager.LayoutParams.MATCH_PARENT;
    lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
    lp.gravity = Gravity.TOP | Gravity.LEFT;
    lp.dimAmount = 0;
    lp.flags = LayoutParams.FLAG_LAYOUT_NO_LIMITS
            | LayoutParams.FLAG_NOT_TOUCH_MODAL;

    Spinner ddlspinnerdata = (Spinner) view.findViewById(R.id.ddl);
    ddldata = ddlspinnerdata.getSelectedItem().toString();
    EditText edtname = (EditText) view.findViewById(R.id.personname);
    name = edtname.getText().toString();
    EditText edtLength = (EditText) view.findViewById(R.id.edtlength);
    length = edtLength.getText().toString();
    EditText edtWidth = (EditText) view.findViewById(R.id.edtwidth);
    width = edtWidth.getText().toString();
    EditText edtHeight = (EditText) view.findViewById(R.id.edtheight);
    height = edtHeight.getText().toString();
    date = edtDate.getText().toString();
    time = edtTime.getText().toString();

    dialog.setContentView(view);
    dialog.show();
         }

单击标记时出现此错误。我在 android 4.0.4 版本中运行这个应用程序。这是我的日志猫,

09-19 10:51:19.302: E/AndroidRuntime(16414): FATAL EXCEPTION: main
09-19 10:51:19.302: E/AndroidRuntime(16414): android.view.InflateException: Binary XML file line #30: Error inflating class <unknown>
09-19 10:51:19.302: E/AndroidRuntime(16414):    at    android.view.LayoutInflater.createView(LayoutInflater.java:608)
09-19 10:51:19.302: E/AndroidRuntime(16414):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:682)
09-19 10:51:19.302: E/AndroidRuntime(16414):    at android.view.LayoutInflater.rInflate(LayoutInflater.java:741)
09-19 10:51:19.302: E/AndroidRuntime(16414):    at android.view.LayoutInflater.rInflate(LayoutInflater.java:744)
09-19 10:51:19.302: E/AndroidRuntime(16414):    at android.view.LayoutInflater.inflate(LayoutInflater.java:491)
09-19 10:51:19.302: E/AndroidRuntime(16414):    at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
09-19 10:51:19.302: E/AndroidRuntime(16414):    at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
09-19 10:51:19.302: E/AndroidRuntime(16414):    at com.android.internal.policy.impl.PhoneWindow.generateLayout(PhoneWindow.java:2725)
09-19 10:51:19.302: E/AndroidRuntime(16414):    at com.android.internal.policy.impl.PhoneWindow.installDecor(PhoneWindow.java:2785)
09-19 10:51:19.302: E/AndroidRuntime(16414):    at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:269)
09-19 10:51:19.302: E/AndroidRuntime(16414):    at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:263)
09-19 10:51:19.302: E/AndroidRuntime(16414):    at android.app.Dialog.setContentView(Dialog.java:480)
09-19 10:51:19.302: E/AndroidRuntime(16414):    at com.example.gm.MainActivity.onMarkerClick(MainActivity.java:157)
09-19 10:51:19.302: E/AndroidRuntime(16414):    at com.google.android.gms.maps.GoogleMap$7.a(Unknown Source)
09-19 10:51:19.302: E/AndroidRuntime(16414):    at com.google.android.gms.internal.da$a.onTransact(Unknown Source)
09-19 10:51:19.302: E/AndroidRuntime(16414):    at android.os.Binder.transact(Binder.java:297)
09-19 10:51:19.302: E/AndroidRuntime(16414):    at bmb.a(SourceFile:84)
09-19 10:51:19.302: E/AndroidRuntime(16414):    at maps.ag.bn.a(Unknown Source)
09-19 10:51:19.302: E/AndroidRuntime(16414):    at maps.ap.d.a(Unknown Source)
09-19 10:51:19.302: E/AndroidRuntime(16414):    at maps.ap.p.c(Unknown Source)
09-19 10:51:19.302: E/AndroidRuntime(16414):    at maps.ap.o.a(Unknown Source)
09-19 10:51:19.302: E/AndroidRuntime(16414):    at maps.ap.bo.b(Unknown Source)
09-19 10:51:19.302: E/AndroidRuntime(16414):    at maps.ap.bk.onSingleTapConfirmed(Unknown Source)
09-19 10:51:19.302: E/AndroidRuntime(16414):    at maps.bt.g.onSingleTapConfirmed(Unknown Source)
09-19 10:51:19.302: E/AndroidRuntime(16414):    at maps.bt.i.handleMessage(Unknown Source)
09-19 10:51:19.302: E/AndroidRuntime(16414):    at android.os.Handler.dispatchMessage(Handler.java:99)
09-19 10:51:19.302: E/AndroidRuntime(16414):    at android.os.Looper.loop(Looper.java:154)
09-19 10:51:19.302: E/AndroidRuntime(16414):    at android.app.ActivityThread.main(ActivityThread.java:4624)
09-19 10:51:19.302: E/AndroidRuntime(16414):    at java.lang.reflect.Method.invokeNative(Native Method)
09-19 10:51:19.302: E/AndroidRuntime(16414):    at java.lang.reflect.Method.invoke(Method.java:511)
09-19 10:51:19.302: E/AndroidRuntime(16414):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:809)
09-19 10:51:19.302: E/AndroidRuntime(16414):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:576)
09-19 10:51:19.302: E/AndroidRuntime(16414):    at dalvik.system.NativeStart.main(Native Method)
09-19 10:51:19.302: E/AndroidRuntime(16414): Caused by: java.lang.reflect.InvocationTargetException
09-19 10:51:19.302: E/AndroidRuntime(16414):    at java.lang.reflect.Constructor.constructNative(Native Method)
09-19 10:51:19.302: E/AndroidRuntime(16414):    at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
09-19 10:51:19.302: E/AndroidRuntime(16414):    at android.view.LayoutInflater.createView(LayoutInflater.java:588)
09-19 10:51:19.302: E/AndroidRuntime(16414):    ... 32 more
09-19 10:51:19.302: E/AndroidRuntime(16414): Caused by: android.view.InflateException: Binary XML file line #36: Error inflating class <unknown>
09-19 10:51:19.302: E/AndroidRuntime(16414):    at android.view.LayoutInflater.createView(LayoutInflater.java:608)
09-19 10:51:19.302: E/AndroidRuntime(16414):    at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:57)
09-19 10:51:19.302: E/AndroidRuntime(16414):    at android.view.LayoutInflater.onCreateView(LayoutInflater.java:655)

这是我的 dialogview.xml,

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/lldialog"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="10dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingTop="30dp" >

<Spinner
    android:id="@+id/ddl"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="14dp"
    android:entries="@array/items"
    android:prompt="@string/ChooseOption"
    android:scrollbarStyle="outsideOverlay"
    android:scrollbars="horizontal|vertical" />

<EditText
    android:id="@+id/personname"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:hint="Full Name"
    android:ems="10"
    android:inputType="textPersonName" >

    <requestFocus android:layout_width="wrap_content" />
</EditText>

<EditText
    android:id="@+id/edtlength"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
   android:hint="Length"
    android:ems="10"
    android:inputType="numberSigned" />

<EditText
    android:id="@+id/edtwidth"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"            
    android:ems="10"
    android:hint="Width"
    android:inputType="numberSigned" />

<EditText
    android:id="@+id/edtheight"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"       
    android:ems="10"
    android:hint="Height"
    android:inputType="numberSigned" />

<TextView
    android:id="@+id/edtDate"
    android:layout_width="match_parent"
    android:layout_height="40dp"
    android:ems="10"
    android:gravity="center|fill"
    android:hint="Pick Date"
    android:inputType="date"
    android:paddingLeft="10dp"
    android:textSize="20sp" />

<TextView
    android:id="@+id/edtTime"
    android:layout_width="match_parent"
    android:layout_height="40dp"
    android:ems="10"
    android:gravity="center|fill"
    android:hint="Pick Time"
    android:inputType="time"
    android:paddingLeft="10dp"
    android:textSize="20sp" />

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal" >

    <Button
        android:id="@+id/btnsave"
        style="?android:attr/buttonStyleSmall"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="2"
        android:text="Save"
        android:textSize="20sp" />

    <Button
        android:id="@+id/btncancel"
        style="?android:attr/buttonStyleSmall"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="2"
        android:text="Cancel"
        android:textSize="20sp" />

  </LinearLayout>

</LinearLayout>

这是我的清单文件,

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.gm"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="18" />

<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="com.example.gm.permission.MAPS_RECEIVE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_INTERNAL_STORAGE"/>
  <uses-feature
    android:glEsVersion="0x00020000"
    android:required="true" />


<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name="com.example.gm.MainActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

     <meta-data
        android:name="com.google.android.maps.v2.API_KEY"
        android:value="MY_API_KEY" />

  <uses-library android:name="com.google.android.maps" />
 </application>

</manifest>

我在这里使用地图片段。

 <fragment
    android:id="@+id/map"
    android:name="com.google.android.gms.maps.SupportMapFragment"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_alignParentTop="true"
    android:clickable="true" />

在主要活动中,我正在扩展 FragmentActivity。这会导致异常吗?请澄清一下。请帮我弄清楚为什么我会收到这个错误。

任何帮助表示赞赏。谢谢!!

4

3 回答 3

1

你为什么要为请求焦点设置包装内容我认为这给了你例外

<requestFocus android:layout_width="wrap_content" />  

只需添加 <requestFocus/> 如果不尝试删除此行并检查某些样式是否会给您充气异常..

style="?android:attr/buttonStyleSmall"
于 2013-09-19T05:39:27.937 回答
0
// try this code
        final Dialog dialog = new Dialog(this);
        dialog.setTitle("Enter Details");
        dialog.setContentView(R.layout.main);

        Button btnsave = (Button) dialog.findViewById(R.id.btnsave);
        Button btncancel = (Button) dialog.findViewById(R.id.btncancel);
        final Spinner ddlspinnerdata = (Spinner) dialog.findViewById(R.id.ddl);
        final EditText edtname = (EditText) dialog.findViewById(R.id.personname);
        final EditText edtLength = (EditText) dialog.findViewById(R.id.edtlength);
        final EditText edtWidth = (EditText) dialog.findViewById(R.id.edtwidth);
        final EditText edtHeight = (EditText) dialog.findViewById(R.id.edtheight);
        final TextView edtDate = (TextView) dialog.findViewById(R.id.edtDate);
        final TextView edtTime = (TextView) dialog.findViewById(R.id.edtTime);

        btncancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dialog.dismiss();
            }
        });

        btnsave.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                ddldata = ddlspinnerdata.getSelectedItem().toString();
                name = edtname.getText().toString();
                length = edtLength.getText().toString();
                width = edtWidth.getText().toString();
                height = edtHeight.getText().toString();
                date = edtDate.getText().toString();
                time = edtTime.getText().toString();
                dialog.dismiss();
            }
        });
        dialog.show();
于 2013-09-19T06:13:47.670 回答
-1

而不是打电话

     View view = getLayoutInflater().inflate(R.layout.dialogview, null);
     view.setBackgroundColor(Color.LTGRAY);
     dialog.setContentView(view);

删除上面的行并尝试将其添加到您的代码中

  dialog.setContentView(R.layout.dialogview);

  public boolean onMarkerClick(Marker arg0) {

  Log.d("", "here");
  dialog.setContentView(R.layout.dialogview);
  edtDate = (TextView) findViewById(R.id.edtDate);

  edtTime = (TextView) findViewById(R.id.edtTime);

  Dialog dialog = new Dialog(this,
        android.R.style.TextAppearance_Holo_WindowTitle);
  dialog.setTitle("Enter Details");
  LayoutParams lp = dialog.getWindow().getAttributes();
  lp.width = WindowManager.LayoutParams.MATCH_PARENT;
  lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
  lp.gravity = Gravity.TOP | Gravity.LEFT;
  lp.dimAmount = 0;
  lp.flags = LayoutParams.FLAG_LAYOUT_NO_LIMITS
        | LayoutParams.FLAG_NOT_TOUCH_MODAL;

  Spinner ddlspinnerdata = (Spinner) view.findViewById(R.id.ddl);
  ddldata = ddlspinnerdata.getSelectedItem().toString();
  EditText edtname = (EditText) view.findViewById(R.id.personname);
  name = edtname.getText().toString();
  EditText edtLength = (EditText) view.findViewById(R.id.edtlength);
  length = edtLength.getText().toString();
  EditText edtWidth = (EditText) view.findViewById(R.id.edtwidth);
  width = edtWidth.getText().toString();
  EditText edtHeight = (EditText) view.findViewById(R.id.edtheight);
  height = edtHeight.getText().toString();
  date = edtDate.getText().toString();
  time = edtTime.getText().toString();


dialog.show();
     }
于 2013-09-19T06:08:44.597 回答