Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
266 views
in Technique[技术] by (71.8m points)

android - FindViewById() not finding View

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...