如何添加numberpicker值并在toast中显示 [英] How to add numberpicker values and display in toast
问题描述
我有两个号码选择器Numberpicker1和Numberpicker2
Numberpicker 1 => numberpicker1.setminvalue(1)和numberpicker1.setmaxvalue(7)
Numberpicker 2 => numberpicker2.setminvalue(0)和numberpicker2.setmaxvalue(12)
我的设计代码
I have two number pickers Numberpicker1 and Numberpicker2
Numberpicker 1 => numberpicker1.setminvalue(1) and numberpicker1.setmaxvalue(7)
Numberpicker 2 => numberpicker2.setminvalue(0) and numberpicker2.setmaxvalue(12)
My design code
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:id="@+id/layout1"
>
<NumberPicker
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/picker1"
android:layout_marginRight="20dp"
android:layout_marginEnd="20dp"></NumberPicker>
<NumberPicker
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/picker2"
></NumberPicker>
</LinearLayout>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/layout1"
android:text="SUBMIT"
android:layout_centerInParent="true"
android:layout_margin="10dp"
/>
我的主要活动代码
My Mainactivity Code
public class MainActivity extends AppCompatActivity {
NumberPicker pick1,pick2;
Button btnsubmit;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
pick1 = (NumberPicker)findViewById(R.id.picker1);
pick2 = (NumberPicker)findViewById(R.id.picker2);
pick1.setMinValue(1);
pick1.setMaxValue(7);
pick2.setMinValue(0);
pick2.setMaxValue(12);
btnsubmit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v)
{
try
{
}
catch (Exception e)
{
e.getMessage();
}
}
});
}
}
我的尝试:
输出未显示不幸停止的应用程序崩溃
请帮忙。甚至我的onclick按钮代码无法正常运行错误我是无法纠正。我没有太多关于编码的知识请更正我的代码并发送到这里
What I have tried:
The output is not showing displaying unfortunately stopped app gets crashed
pls help out.And even my onclick button code is not working error i am unable to rectify.i dont have much knowledge about coding pls correct my code and send here
推荐答案
为什么你转发这个问题?我昨天在 https://www.codeproject.com上给了你答案。 / Questions / 1258508 /如何添加两个数字选择器值 [ ^ ]
Why have you reposted this question? I gave you the answer yesterday at https://www.codeproject.com/Questions/1258508/How-to-add-two-number-picker-values[^]
这篇关于如何添加numberpicker值并在toast中显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!