请教大神,LayoutInflater和View.linflate出来的Layout不能操作

onlymiaomiao 2013-07-23 10:36:36
3天前已经发过一个帖子了。
http://www.eoeandroid.com/thread-295192-1-1.html


没有获得解决办法,故此继续过来询问

问题描述:此APP模仿微信底部用的OnPageChangeLisenter实现的。并没有采用TABHOST的方式。但是底部的界面做出来的,上面的4个界面给4界面立面的控件设置点击事件或者其他操作都是没有作用,但是如果把上面部分的四个界面单独分开出来呢,设置4界面里面控件的点击事件又有用。

目的:想保存底部的样式和,针对上面部分的控件进行点击操作可以切换到更多的二级子VIEW。


下面是底部界面的源码加载4个界面的方式。和第4个界面ACTIVITY内设置点击事件的源码


?代码片段,双击复制 010203040506070809101112131415 LayoutInflater mLi = LayoutInflater.from(this); View view1 = mLi.inflate(R.layout.top, null); View view2 = mLi.inflate(R.layout.main_data, null); View view3 = mLi.inflate(R.layout.main_collect, null); View view4 = mLi.inflate(R.layout.main_more, null); // Intent localIntent1 = new Intent(this, MoreActivity.class); // startActivity(localIntent1); // 每个页面的view数据 final ArrayList<View> views = new ArrayList<View>(); views.add(view1); views.add(view2); views.add(view3); views.add(view4);

上面代码是四个界面加载的LAYOUT代码,但是这4个Layout内部的控件设置点击事件是没有反应的。



如果把注释代码去掉,单独只看一个LAYOUT,采用了ACTIVITY启动的方式,是可以对控件点击事件设置成功的。

?代码片段,双击复制 0102 Intent localIntent1 = new Intent(this, MoreActivity.class); startActivity(localIntent1);





并且如果直接采用XML方面的点击OnClick方法呢,同样会在对应界面直接报错的。

?代码片段,双击复制 0102030405060708091011121314151617181920212223242526272829 <!-- 第一部分************************************************ --><RelativeLayoutandroid:id="@id/BattleDore_more_ly_howtouse"android:layout_width="fill_parent"android:layout_height="wrap_content"android:layout_marginTop="14dp"android:background="@drawable/more_list_touch_item"android:clickable="true"android:onClick="onStartActivity"android:gravity="center_horizontal|center_vertical" > <TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_centerVertical="true"android:layout_toRightOf="@id/BattleDore_more_list_ruheshiyong"android:padding="8dp"android:text="@string/earth_more_howtouse"android:textColor="#000"android:textSize="17sp" /> <ImageViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_alignParentRight="true"android:layout_centerVertical="true"android:scaleType="matrix"android:src="@drawable/earth_more_listmore" /> </RelativeLayout>



?代码片段,双击复制 0102030405 public void onStartActivity(View v) { Intent intent = new Intent(); intent.setClass(MoreActivity.this,LauchActivity.class); startActivity(intent); }




这是点击按钮后报错的LOGCAT
07-23 02:28:56.389: E/WifiHW(421): wifi_send_command : DRIVER SETSUSPENDMODE 1 ; interface index=0;
07-23 02:28:56.479: E/WeatherApp(15033): KillProcess
07-23 02:28:58.969: E/dalvikvm(421): GC_EXPLICIT freed 839K, 42% free 15274K/26055K, paused 3ms+8ms, total 125ms
07-23 02:29:00.369: E/WindowManager(421): getkey down, keyCode =true, 26
07-23 02:29:00.499: E/WifiHW(421): wifi_send_command : SIGNAL_POLL ; interface index=0;
07-23 02:29:00.499: E/WifiHW(421): wifi_send_command : DRIVER SETSUSPENDMODE 0 ; interface index=0;
07-23 02:29:00.539: E/WindowManager(421): getkey down, keyCode =false, 26
07-23 02:29:03.509: E/WifiHW(421): wifi_send_command : SIGNAL_POLL ; interface index=0;
07-23 02:29:03.739: E/dalvikvm(15137): GC_CONCURRENT freed 180K, 7% free 8435K/9031K, paused 11ms+2ms, total 30ms
07-23 02:29:03.849: E/copybit(15137): Error opening frame buffer errno=13 (Permission denied)
07-23 02:29:06.509: E/WifiHW(421): wifi_send_command : SIGNAL_POLL ; interface index=0;
07-23 02:29:09.529: E/WifiHW(421): wifi_send_command : SIGNAL_POLL ; interface index=0;
07-23 02:29:12.539: E/WifiHW(421): wifi_send_command : SIGNAL_POLL ; interface index=0;
07-23 02:29:15.219: E/dalvikvm(1592): GC_CONCURRENT freed 1350K, 38% free 9989K/16007K, paused 12ms+13ms, total 89ms
07-23 02:29:15.539: E/WifiHW(421): wifi_send_command : SIGNAL_POLL ; interface index=0;
07-23 02:29:16.319: E/DhcpStateMachine(421): DHCP failed on eth0: Timed out waiting for DHCP to finish
07-23 02:29:16.519: E/WifiHW(421): wifi_send_command : SET ps 1 ; interface index=0;
07-23 02:29:16.519: E/WifiHW(421): wifi_send_command : DRIVER BTCOEXMODE 2 ; interface index=0;
07-23 02:29:16.519: E/WifiStateMachine(421): IP configuration failed
07-23 02:29:20.079: E/WeatherApp(15464): WeatherApp onCreate







再贴个TABHOST的使用效果,说实话,不怎么想使用TABHOST,因为具体的调节按下的字体变化很麻烦,而且TABHOST继承tabactivity太呆板了。但是TABHOST作用下的上半部分4个界面是可以进行任何操作点击的,因为我直接加的是ACTIVITY,但是上面那种OnPageListener的方法只是加载的View view1 = mLi.inflate(R.layout.top, null);我一直怀疑问题就出现在这里,这个inflate出来的Layout只能用于查看,却不能进行点击。求解决办法。如果实现不行的话我只能回去再次采用TABHOST方法了。




我来回答

. post_newreply





...全文
200 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
onlymiaomiao 2013-07-23
  • 打赏
  • 举报
回复
帖子详情:有截图的链接。http://www.eoeandroid.com/thread-296192-1-1.html

80,351

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧