0

我只想顯示列表視圖的Web視圖,但不能。我的虛假在哪裏?如果我運行,並點擊菜單在列表視圖到webview,不幸已停止。請幫幫我。android:幫助webview無法打開從列表視圖片段

FindPeopleFragment.java

package info.androidhive.slidingmenu; 



import android.os.Bundle; 
import android.app.Fragment; 
import android.content.Context; 
import android.content.Intent; 

import java.util.ArrayList; 
import java.util.HashMap; 

import android.view.LayoutInflater; 
import android.view.View; 
import android.widget.AdapterView.OnItemClickListener; 
import android.view.ViewGroup; 
import android.widget.AdapterView; 
import android.widget.ListView; 
import android.widget.ListAdapter; 
import android.widget.SimpleAdapter; 
import android.widget.Toast; 


public class FindPeopleFragment extends Fragment { 

    public FindPeopleFragment(){} 
     protected ListView lv; 
     protected ListAdapter adapter; 
     public static final String MOVIE_DETAIL_KEY = "movie"; 
     SimpleAdapter Adapter; 
     HashMap<String, String> map; 
     ArrayList<HashMap<String, String>> mylist; 
     String[] Pil; 
     String[] Ltn; 
     String[] Gbr; 


     public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 

      View rootView = inflater.inflate(R.layout.activity_pulau, container,false); 

      final ListView lv = (ListView) rootView.findViewById(R.id.lv); 

      Pil = new String[] {"Pulau Gusung", "Binatang Laut Khas"}; 
      Ltn = new String[] {"Baca Selengkapnya...", "Baca Selengkapnya..."}; 
      Gbr = new String[] {Integer.toString(R.drawable.ic_photos), 
           Integer.toString(R.drawable.ic_photos), 

             }; 

      mylist = new ArrayList<HashMap<String,String>>(); 

      for (int i = 0; i < Pil.length; i++){ 
       map = new HashMap<String, String>(); 
       map.put("list", Pil[i]); 
       map.put("latin", Ltn[i]); 
       map.put("gbr", Gbr[i]); 
       mylist.add(map);    
      } 

      Adapter = new SimpleAdapter(getActivity(), mylist, R.layout.item_kepulauan, 
         new String[] {"list", "latin", "gbr"}, new int[] {R.id.tv_nama, R.id.tv_des, R.id.imV}); 
      lv.setAdapter(Adapter); 
      lv.setOnItemClickListener(new OnItemClickListener() { 




       @Override 
       public void onItemClick(AdapterView<?> parent, View view, 
         int position, long id) { 
        // TODO Auto-generated method stub 
        // ListView Clicked item index 
        int itemPosition = position; 

        // ListView Clicked item value 
        String itemValue = (String) lv 
          .getItemAtPosition(position); 
        if (position == 0) { 
         Intent myIntent = new Intent(getApplicationContext(), 
           Story.class); 
         myIntent.putExtra("key", 0); 
         startActivity(myIntent); 
        }else if (position == 1) { 
         Intent myIntent = new Intent(getApplicationContext(), 
           Story.class); 
         myIntent.putExtra("key", 1); 
         startActivity(myIntent); 
        } 



       } 

       private Context getApplicationContext() { 
        // TODO Auto-generated method stub 
        return null; 
       } 
       }); 



      return rootView; 


      } 






} 

Story.java

package info.androidhive.slidingmenu; 

import android.app.Fragment; 
import android.os.Bundle; 
import android.view.LayoutInflater; 
import android.view.View; 
import android.view.ViewGroup; 
import android.webkit.WebChromeClient; 
import android.webkit.WebView; 
import android.webkit.WebViewClient; 

public class Story extends Fragment { 
    @Override 
    public View onCreateView(LayoutInflater inflater, ViewGroup container, 
       Bundle savedInstanceState) { 

      View v = inflater.inflate(R.layout.fragment_home, container, false);  
      WebView webView = (WebView) v.findViewById (R.id.webView1); 
      webView.getSettings().setJavaScriptEnabled(true); 
      webView.setWebChromeClient(new WebChromeClient()); 
      int pos = getActivity().getIntent().getIntExtra("key", 0); 
      if (pos == 0) { 
       webView.loadUrl("file:///android_asset/tampilhome.html"); 
      } else if (pos == 1) { 
       webView.loadUrl("file:///android_asset/tampilhome.html"); 
      } 


      webView.setWebViewClient(new WebViewClient() { 

      @Override 
      public void onReceivedError(WebView view, int errorCode, 
        String description, String failingUrl) { 
        super.onReceivedError(view, errorCode, description, failingUrl); 
        } 
      @Override 
      public boolean shouldOverrideUrlLoading(WebView view, String url) { 
       view.loadUrl(url); 
       return true; 
      } 
     }); return v; 

     } 


} 

回答

1

你無法使用意圖打開一個片段。

你需要創建找人片段,並使用該再打活動,以取代找到故事片段

更多信息ü去通過這個頁面的人片段的接口,它會解釋ü更好

http://developer.android.com/training/basics/fragments/communicating.html