首页 新闻 赞助 找找看

(LinearLayout)findViewById得到的是空值,无法监听点击事件

0
悬赏园豆:10 [已关闭问题] 关闭于 2015-07-15 08:43

本来的打算是,点击输入框以外,软键盘能隐藏

就像QQ的登陆界面

但是debug发现,findViewById得到的是空值

求各位大大帮忙看看

 

主要代码如下:

 1 protected void onCreate(Bundle savedInstanceState) {
 2         super.onCreate(savedInstanceState);
 3         requestWindowFeature(Window.FEATURE_NO_TITLE);
 4         setContentView(R.layout.activity_login);
 5         context = this;
 6                 ll_login = (LinearLayout)findViewById(R.id.ll_activity_login);//这里ll_login的值便是null
 7                ll_login.setOnClickListener(new View.OnClickListener(){
 8             @Override
 9             public void onClick(View v) {
10                 switch (v.getId()) {
11                 case R.id.ll_login:
12                      InputMethodManager imm = (InputMethodManager)
13                      getSystemService(Context.INPUT_METHOD_SERVICE);
14                      imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
15                     break;
16                 }
17 
18             }
19         });     
20     }

xml中LinearLayout是根布局:

1 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
2     xmlns:tools="http://schemas.android.com/tools"
3     android:id="@+id/ll_activity_login"
4     android:layout_width="match_parent"
5     android:layout_height="match_parent"
6     android:clickable="true"
7     android:background="@color/white_color"
8     android:orientation="vertical" >
菊草叶与圆企鹅的主页 菊草叶与圆企鹅 | 菜鸟二级 | 园豆:233
提问于:2015-07-14 14:25
< >
分享
所有回答(1)
0

才发现land和port用了不同布局,我只改了port的xml,没改land的,而我用的是横屏测试……这问题太白痴了

菊草叶与圆企鹅 | 园豆:233 (菜鸟二级) | 2015-07-15 08:43

是啊  白痴

 

支持(0) 反对(0) 斯塔克罗斯 | 园豆:200 (初学一级) | 2017-04-13 09:32
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册