我需要我的应用程序来创建一个对话框 Seekbar。但我不能让它工作。我指的是这个stackoverflow问题Android,SeekBar in dialog,这是我的代码。
我正在创建一个菜单,当用户单击 size_config 按钮时,它应该在菜单项上显示搜索栏。
}if(item.getItemId() == R.id.size_config){
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.id.dialog, (ViewGroup)findViewById(R.id.layout));
AlertDialog.Builder builder = new AlertDialog.Builder(this)
.setView(layout);
AlertDialog alertDialog = builder.create();
alertDialog.show();
SeekBar sb = (SeekBar)layout.findViewById(R.id.dialog);
sb.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser){
Log.d("Dialog to change size", "It's working");
}
@Override
public void onStartTrackingTouch(SeekBar arg0) {
// TODO Auto-generated method stub
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}
});
}
这是布局文件。
对话框.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
android:id="@+id/layout">
<SeekBar xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/dialog"
android:layout_width="225dp"
android:layout_height="wrap_content"/>
</LinearLayout>
这是错误代码。
06-24 02:31:30.369: E/AndroidRuntime(379): FATAL EXCEPTION: main
06-24 02:31:30.369: E/AndroidRuntime(379): android.content.res.Resources$NotFoundException: Resource ID #0x7f070001 type #0x12 is not valid
06-24 02:31:30.369: E/AndroidRuntime(379): at android.content.res.Resources.loadXmlResourceParser(Resources.java:1874)
06-24 02:31:30.369: E/AndroidRuntime(379): at android.content.res.Resources.getLayout(Resources.java:731)
06-24 02:31:30.369: E/AndroidRuntime(379): at android.view.LayoutInflater.inflate(LayoutInflater.java:318)
06-24 02:31:30.369: E/AndroidRuntime(379): at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
06-24 02:31:30.369: E/AndroidRuntime(379): at in.isuru.animation.SnowFall.onOptionsItemSelected(SnowFall.java:189)
06-24 02:31:30.369: E/AndroidRuntime(379): at android.app.Activity.onMenuItemSelected(Activity.java:2195)
06-24 02:31:30.369: E/AndroidRuntime(379): at com.android.internal.policy.impl.PhoneWindow.onMenuItemSelected(PhoneWindow.java:730)
06-24 02:31:30.369: E/AndroidRuntime(379): at com.android.internal.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:143)
06-24 02:31:30.369: E/AndroidRuntime(379): at com.android.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:855)
06-24 02:31:30.369: E/AndroidRuntime(379): at com.android.internal.view.menu.MenuDialogHelper.onClick(MenuDialogHelper.java:137)
06-24 02:31:30.369: E/AndroidRuntime(379): at com.android.internal.app.AlertController$AlertParams$3.onItemClick(AlertController.java:874)
06-24 02:31:30.369: E/AndroidRuntime(379): at android.widget.AdapterView.performItemClick(AdapterView.java:284)
06-24 02:31:30.369: E/AndroidRuntime(379): at android.widget.ListView.performItemClick(ListView.java:3382)
06-24 02:31:30.369: E/AndroidRuntime(379): at android.widget.AbsListView$PerformClick.run(AbsListView.java:1696)
06-24 02:31:30.369: E/AndroidRuntime(379): at android.os.Handler.handleCallback(Handler.java:587)
06-24 02:31:30.369: E/AndroidRuntime(379): at android.os.Handler.dispatchMessage(Handler.java:92)
06-24 02:31:30.369: E/AndroidRuntime(379): at android.os.Looper.loop(Looper.java:123)
06-24 02:31:30.369: E/AndroidRuntime(379): at android.app.ActivityThread.main(ActivityThread.java:4627)
06-24 02:31:30.369: E/AndroidRuntime(379): at java.lang.reflect.Method.invokeNative(Native Method)
06-24 02:31:30.369: E/AndroidRuntime(379): at java.lang.reflect.Method.invoke(Method.java:521)
06-24 02:31:30.369: E/AndroidRuntime(379): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
06-24 02:31:30.369: E/AndroidRuntime(379): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
06-24 02:31:30.369: E/AndroidRuntime(379): at dalvik.system.NativeStart.main(Native Method)