A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

周开伟

注册黑马

  • 黑马币:0

  • 帖子:6

  • 精华:0

© 周开伟 注册黑马   /  2012-8-23 17:24  /  1539 人查看  /  1 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

  1. <manifest xmlns:android="http://schemas.android.com/apk/res/android"
  2.     package="com.meishuihuiyin.bbs"
  3.     android:versionCode="1"
  4.     android:versionName="1.0" >

  5.     <uses-sdk
  6.         android:minSdkVersion="5"
  7.         android:targetSdkVersion="15" />

  8.     <application
  9.         android:icon="@drawable/ic_launcher"
  10.         android:label="@string/app_name"
  11.         android:theme="@style/test" >
  12.         <activity
  13.             android:name=".MainActivity"
  14.             android:label="@string/title_activity_main" >
  15.             <intent-filter>
  16.                 <action android:name="android.intent.action.MAIN" />

  17.                 <category android:name="android.intent.category.LAUNCHER" />
  18.             </intent-filter>
  19.         </activity>
  20.         <activity
  21.             android:name=".ZiXunChu">
  22.         </activity>
  23.     </application>

  24. </manifest>
复制代码
先贴代码MainActivity代码
  1. package com.meishuihuiyin.bbs;


  2. import android.os.Bundle;
  3. import android.app.ActivityGroup;
  4. import android.content.Intent;
  5. import android.view.View;
  6. import android.view.Window;
  7. import android.view.View.OnClickListener;
  8. import android.widget.Button;
  9. import android.widget.ScrollView;

  10. public class MainActivity extends ActivityGroup implements OnClickListener {

  11.         Button one = null;
  12.         Button two = null;
  13.     @Override
  14.     public void onCreate(Bundle savedInstanceState) {
  15.         super.onCreate(savedInstanceState);
  16.         setContentView(R.layout.activity_main);
  17.         one = (Button)findViewById(R.id.first);
  18.         two = (Button)findViewById(R.id.second);
  19.         
  20.         one.setOnClickListener(this);
  21.         one.setTag(1);
  22.         two.setOnClickListener(this);
  23.         two.setTag(2);
  24.     }
  25.    
  26.     public void onClick(View v){
  27.             int tag = (Integer)v.getTag();
  28.             Intent intent = null;
  29.             Window subActivity = null;
  30.             ScrollView container = null;
  31.             switch(tag){
  32.             case 1:
  33.                     //container.removeAllViews();
  34.                     intent=new Intent(MainActivity.this,ZiXunChu.class);
  35.                     intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
  36.                     ((ActivityGroup)MainActivity.this.getParent()).getLocalActivityManager().removeAllActivities();
  37.                      subActivity=((ActivityGroup)MainActivity.this.getParent()).getLocalActivityManager().startActivity("locallist",intent);
  38.                     container.addView(subActivity.getDecorView());
  39.                     break;
  40.             case 2:
  41.                     //container.removeAllViews();
  42.                     intent=new Intent(MainActivity.this,ZiXunChu.class);
  43.                     intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
  44.                     ((ActivityGroup)MainActivity.this.getParent()).getLocalActivityManager().removeAllActivities();
  45.                      subActivity=((ActivityGroup)MainActivity.this.getParent()).getLocalActivityManager().startActivity("locallist",intent);
  46.                     container.addView(subActivity.getDecorView());
  47.                     break;
  48.             }
  49.     }

  50.    
  51.    
  52. }
复制代码
ZiXunChu代码
  1. package com.meishuihuiyin.bbs;


  2. import android.app.Activity;
  3. import android.os.Bundle;
  4. import android.view.KeyEvent;
  5. import android.view.View;
  6. import android.view.View.OnClickListener;
  7. import android.view.Window;
  8. import android.webkit.WebSettings;
  9. import android.webkit.WebView;
  10. import android.webkit.WebViewClient;
  11. import android.widget.ImageButton;

  12. public class ZiXunChu extends Activity {
  13.         ImageButton back = null;
  14.         ImageButton refresh = null;
  15.         WebView show_web = null;
  16.         @Override
  17.         protected void onCreate(Bundle savedInstanceState) {
  18.                 // TODO Auto-generated method stub
  19.                 super.onCreate(savedInstanceState);
  20.                
  21.             setContentView(R.layout.show); // 注意顺序   
  22.                         
  23.             back = (ImageButton)findViewById(R.id.back);
  24.             refresh = (ImageButton)findViewById(R.id.refresh);
  25.             show_web = (WebView)findViewById(R.id.show);
  26.             
  27.             WebSettings settings = show_web.getSettings();
  28.         settings.setSupportZoom(false);   //支持缩放
  29.         //settings.setBuiltInZoomControls(true); //启用内置缩放装置
  30.         //settings.setJavaScriptEnabled(true); //启用JS脚本
  31.         
  32.         show_web.loadUrl("http://www.jyubbs.com/bbs/forum-43-1.html");
  33.         
  34.         show_web.setWebViewClient(new WebViewClient() {
  35.                    //当点击链接时,希望覆盖而不是打开新窗口
  36.                    @Override
  37.                    public boolean shouldOverrideUrlLoading(WebView view, String url) {
  38.                     view.loadUrl(url); //加载新的url
  39.                     return true; //返回true,代表事件已处理,事件流到此终止
  40.                    }
  41.         });
  42.         
  43.         back.setOnClickListener(new OnClickListener() {
  44.                        
  45.                         @Override
  46.                         public void onClick(View v) {
  47.                                 // TODO Auto-generated method stub
  48.                                 show_web.goBack();
  49.                         }
  50.                 });
  51.         
  52.                 refresh.setOnClickListener(new OnClickListener() {
  53.                                        
  54.                                         @Override
  55.                                         public void onClick(View v) {
  56.                                                 // TODO Auto-generated method stub
  57.                                                 show_web.reload();
  58.                                         }
  59.                                 });
  60.         show_web.setOnKeyListener(new View.OnKeyListener() {
  61.                         @Override
  62.                         public boolean onKey(View v, int keyCode, KeyEvent event) {
  63.                                 // TODO Auto-generated method stub
  64.                                  if (event.getAction() == KeyEvent.ACTION_DOWN) {
  65.                              if (keyCode == KeyEvent.KEYCODE_BACK && show_web.canGoBack()) {
  66.                               show_web.goBack(); //后退
  67.                               return true; //已处理
  68.                              }
  69.                             }             
  70.                                 return false;
  71.                         }
  72.         });

  73.         }
  74.        
  75. }
复制代码
layout_main.xml
  1. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  2.     xmlns:tools="http://schemas.android.com/tools"
  3.     android:layout_width="match_parent"
  4.     android:layout_height="match_parent" >
  5.    
  6.     <LinearLayout
  7.         android:layout_height="wrap_content"
  8.         android:layout_width="fill_parent"
  9.         android:gravity="center_horizontal">
  10.         <Button android:id="@+id/first"
  11.             android:layout_height="wrap_content"
  12.             android:layout_width="wrap_content"
  13.             android:layout_weight="0.5"
  14.             android:text="学生咨询"/>
  15.         <Button android:id="@+id/second"
  16.             android:layout_height="wrap_content"
  17.             android:layout_width="wrap_content"
  18.             android:layout_weight="0.5"
  19.             android:text="水客茶园"/>
  20.     </LinearLayout>
  21.    
  22.     <ScrollView android:measureAllChildren="true" android:id="@+id/body"
  23.         android:layout_height="fill_parent"
  24.         android:layout_width="wrap_content">
  25.     </ScrollView>


  26.    

  27. </RelativeLayout>
复制代码
show.xml
  1. <p><?xml version="1.0" encoding="UTF-8"?>
  2. <LinearLayout xmlns:android="<a >http://schemas.android.com/apk/res/android</a>"
  3.     xmlns:tools="<a >http://schemas.android.com/tools</a>"
  4.     android:layout_width="fill_parent"
  5.     android:layout_height="fill_parent"
  6.     android:gravity="fill_vertical">
  7.     <WebView
  8.         android:id="@+id/show"
  9.         android:layout_width="fill_parent"
  10.         android:layout_height="wrap_content"
  11.         android:layout_weight="1"
  12.         />
  13.     <RelativeLayout
  14.         android:layout_width="fill_parent"
  15.         android:layout_height="wrap_content"
  16.         android:layout_gravity="bottom"
  17.         ></p><p>        <ImageButton
  18.             android:id="@+id/refresh"
  19.             android:layout_width="wrap_content"
  20.             android:layout_height="30dip"
  21.             android:layout_alignParentRight="true"
  22.             android:layout_alignParentTop="true"
  23.             android:background="@drawable/ic_refresh" /></p><p>        <ImageButton
  24.             android:id="@+id/back"
  25.             android:layout_width="wrap_content"
  26.             android:layout_height="30dip"
  27.             android:layout_alignParentLeft="true"
  28.             android:layout_alignParentTop="true"
  29.             android:background="@drawable/ic_back" /></p><p>    </RelativeLayout>
  30. </LinearLayout>
  31. </p><p> </p>
复制代码
AndroidManifest.xml
  1. <manifest xmlns:android="http://schemas.android.com/apk/res/android"
  2.     package="com.meishuihuiyin.bbs"
  3.     android:versionCode="1"
  4.     android:versionName="1.0" >

  5.     <uses-sdk
  6.         android:minSdkVersion="5"
  7.         android:targetSdkVersion="15" />

  8.     <application
  9.         android:icon="@drawable/ic_launcher"
  10.         android:label="@string/app_name"
  11.         android:theme="@style/test" >
  12.         <activity
  13.             android:name=".MainActivity"
  14.             android:label="@string/title_activity_main" >
  15.             <intent-filter>
  16.                 <action android:name="android.intent.action.MAIN" />

  17.                 <category android:name="android.intent.category.LAUNCHER" />
  18.             </intent-filter>
  19.         </activity>
  20.         <activity
  21.             android:name=".ZiXunChu">
  22.         </activity>
  23.     </application>

  24. </manifest>
复制代码
哥们纠结,报了N多错误。。。
求解

1 个回复

正序浏览
空指针错误
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马