java - Seekbar 为空,即使它存在
问题描述
我的目标是访问搜索栏。我尝试了很多东西,甚至在覆盖之前拉了 Seekbar 搜索栏,但我总是得到空吐司。R.layout.firstLayout
, R.layout.secondLayout
, R.id.seekingbar
, 它们都存在。
这是我的缩写代码
public class MainActivity extends AppCompatActivity {
SeekBar seekingbar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
seekingbar = (SeekBar) findViewById(R.id.seekingbar);
LayoutInflater inflater = getLayoutInflater();
final View firstLayout = inflater.inflate(R.layout.firstLayout, null);
final View secondLayout = inflater.inflate(R.layout.secondLayout, null);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
AlertDialog dialog = new AlertDialog.Builder(MainActivity.this)
.setPositiveButton("Forward", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
AlertDialog dialog2 = new AlertDialog.Builder(MainActivity.this)
.setView(secondLayout)
.setPositiveButton("Okay", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
if (seekingbar == null)
{
Toast.makeText(MainActivity.this,"Null",Toast.LENGTH_LONG).show();
}
}
}).create();
dialog2.show();
}
}).create();
dialog.show();
}
});
}
}
第一个布局.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/seekbarll"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="10dp"
tools:context=".MainActivity">
<SeekBar
android:id="@+id/seekingbar"
style="@style/Widget.AppCompat.SeekBar.Discrete"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:max="10"
android:min="0"
android:progress="3" />
</LinearLayout>
解决方案
声明后尝试在firstLayout中找到seekBar:“firstLayout.findViewById(R.id.seekbar)”
推荐阅读
- cmake - 如何在cmake中打印所有编译选项
- asynchronous - 对 make_service_fn 的调用中的超文档差异与异步
- r - 如何将 dplyr 语句编写为数据表语句?
- python - ValueError: int() 以 10 为底的无效文字:'pippi'
- javascript - 如何格式化子字符串以使用 javascript 链接类似 Twitter 的链接?
- r - 使用 for 循环按列名绘制图形
- gradient-descent - 成本函数的导数如何给出成本下降最快的方向?
- matplotlib - pyplot:在文本框环境中制作图例
- r - 在 r 中使用公式时如何从“htest”对象中提取数据集
- angular - 使用 SCSS 和 angular 的背景 url 问题