小编kle*_*ver的帖子

应该"android:onOptionsItemSelected"返回true或false

在onOptionsItemSelected中......我看到了一些在switch块中不同的代码.

案例1(通常看到)

public boolean onOptionsItemSelected (MenueItem item)
       switch (item.getItemId()){
             case R.id.item1:
             startActivity (new Intent (this, PrefsActivity.class));
             break;
       }
       return true
Run Code Online (Sandbox Code Playgroud)

案例2(不确定为什么这样设置)

public boolean onOptionsItemSelected(MenuItem item) {
       switch (item.getItemId()) {
               case MENU_NEW_GAME:
               newGame();
               return true;
       }
       return false;
Run Code Online (Sandbox Code Playgroud)

我的问题

案例1和案例2之间有什么区别?

android

50
推荐指数
2
解决办法
6万
查看次数

android RelativeLayout,等间距?

我正在使用相对布局创建一个计算器屏幕,我有一排标记为1,2和3的按钮.我希望它们均匀分布,但我不知道如何使用相对布局

我习惯在LinearLayout中使用android:layout_weight函数,并给它们每个值一个android:layout_width ="fill_parent",以及layout_weight ="1"

任何方式在计算器屏幕上发生这种情况(不指定DP或PX)

这就是我现在设置的内容,它们在TextView(计算器输出屏幕)下按从左到右的顺序排列.任何建议/解决方案均匀空间,填充屏幕的宽度?

    <TextView
android:id="@+id/textView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/edit_text"
android:layout_margin="6px"
/>

<Button
android:id="@+id/button1"
android:text="1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/textView"
/>

<Button
android:id="@+id/button2"
android:text="2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/textView"
android:layout_toRightOf="@+id/button1"/>

<Button
android:id="@+id/button3"
android:text="3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/textView"
android:layout_toRightOf="@+id/button2"
/>
Run Code Online (Sandbox Code Playgroud)

android android-relativelayout

11
推荐指数
1
解决办法
1万
查看次数

simple_spinner_dropdown_item - 视图大小

我正在尝试在我的UI中使用simple_spinner_item和simple_spinner_dropdown_item之间做出决定......所以我把两个都放在屏幕上来连续尝试它们.虽然我更喜欢... dropdown_item的扩展样式,它的未扩展大小比... spinner_item大,我不知道为什么,因为xml定义没有区别......只是执行不同的通过Java查看,

例如

ArrayAdapter<String> adapter1 = new ArrayAdapter(this, android.R.layout.simple_spinner_dropdown_item, arrayOfSomeStrings); //set the adapter to 
Run Code Online (Sandbox Code Playgroud)

spinner1

VS

ArrayAdapter<String adapter2> = new ArrayAdapter(this,android.R.layout.simple_spinner_item, arrayOfSomeMoreStrings);  //set the adapter to spinner2
Run Code Online (Sandbox Code Playgroud)

在我看来,simple_spinner_dropdown_item必须有不同的prefferedHeight/size或者什么......这是真的吗?以及我如何覆盖它并使两个微调器在UI上看起来相同,直到扩展?

android spinner

1
推荐指数
1
解决办法
4753
查看次数

EditText onLongClick(); 隐藏剪切/复制/选择栏

当你长时间点击andriod中的editText时,会出现一个实用工具栏,其中包含剪切/复制/选择所有/选择单词的选项.我正在使用onLongClickListener来调出Dialog-并希望隐藏这些编辑选项.

我不确定它叫什么,所以我无法在任何文档中找到它以找出如何隐藏它.

我想要这样做的东西:

onLongClick(View v){
//hide edit options
myDialogBox.show();
}
Run Code Online (Sandbox Code Playgroud)

android onlongclicklistener android-edittext

1
推荐指数
1
解决办法
3507
查看次数