FindViewById()没有找到查看 [英] FindViewById() not finding View
问题描述
只是增加了一个新的按钮,我已经-工作精细布局,但findViewById功能似乎生气的东西我不理解。
下面是一个位的布局:
<的LinearLayout
...
>
<的ListView
机器人:ID =@ + ID / my_lovely_list
机器人:layout_width =FILL_PARENT
机器人:layout_weight =1
/>
<按钮
机器人:ID =@ + ID / my_lovely_butt
机器人:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT
机器人:文本=@字符串/ exit_b
机器人:layout_weight =0
机器人:可点击=真
/>
< / LinearLayout中>
和这里的位编码:
@覆盖
公共无效的onCreate(包savedInstanceState){
super.onCreate(savedInstanceState);
的setContentView(R.layout.main);
...
list_o =(ListView控件)findViewById(R.id.my_lovely_list);
butt_o =(按钮)findViewById(R.id.my_lovely_butt);
...
}
所以,大的谜是,没有任何发现问题的ListView的,但按钮将不会以任何方式。我已经尝试过清理Proyect,并期待throught我在这里找到了帖子......但仍然没有得到发现的问题!有什么想法?
进口yourpackagename.R;
而不是 android.R;
进口研究
还有清除
的项目,将刷新您的整个项目,那么你还可以找到 ID
按钮也
Just added a new button to my already-working-fine layout, but the findViewById function seems to be angry with something I don't get to understand.
Here's a bit of the layout:
<LinearLayout
...
>
<ListView
android:id="@+id/my_lovely_list"
android:layout_width="fill_parent"
android:layout_weight="1"
/>
<Button
android:id="@+id/my_lovely_butt"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/exit_b"
android:layout_weight="0"
android:clickable="true"
/>
</LinearLayout>
And here's a bit of the coding:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
...
list_o = (ListView)findViewById(R.id.my_lovely_list);
butt_o = (Button)findViewById(R.id.my_lovely_butt);
...
}
So, the big mistery is that the ListView is found without any problem, but the Button won't by any means. I've already tried cleaning the Proyect, and look throught the posts I've found here... but still don't get to find the problem! Any thoughts?
import yourpackagename.R;
instead of android.R;
import R
of your package
Also Clean
your project that will refresh your entire project then you will also find ID
of button also
这篇关于FindViewById()没有找到查看的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!