2014-09-04 29 views
0

我使用下面的代碼。每次在logcat上我都看不到對話廣告。不爽快。而且廣告沒有顯示,但同樣的事情正在使用罰款時,沒有一個片段的幫助。廣告不可見。沒有令人耳目一新的問題與Android片段admob

有人請告訴我什麼是我的代碼。

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/ll1" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="#ffffff" 
    > 
    <ScrollView 
     android:id="@+id/scrollView1" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentTop="true" 
     > 
    <LinearLayout 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:orientation="vertical" 
        > 
     <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" 
     android:weightSum="4" 
     android:gravity="center" 
     > 

       <TextView 
       android:id="@+id/textView1" 
       android:layout_marginLeft="5dp" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_weight="1" 
       /> 

       <Button 
      android:id="@+id/Button1" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_weight="3" 
      android:paddingRight="5dp" 
      android:layout_marginRight="15dp" 
      android:layout_marginTop="5dp" 
      android:layout_marginBottom="5dp" 
      android:background="@android:color/transparent" 
      /> 
    </LinearLayout> 
    <ListView 
     android:id="@+id/list" 
     android:layout_width="match_parent" 
     android:layout_height="250dp" 
     /> 

       <TextView 
       android:id="@+id/textView4" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:paddingLeft="5dp" 
       android:paddingRight="5dp" 
       /> 
       <TextView 
       android:id="@+id/textView2" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:paddingLeft="15dp" 
       android:paddingRight="10dp" 
       android:text="" 
       /> 
       <TextView 
       android:id="@+id/textView5" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:paddingLeft="5dp" 
       android:paddingRight="5dp" 
       /> 
       <TextView 
       android:id="@+id/textView3" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:paddingLeft="15dp" 
       android:paddingRight="10dp" 
       /> 
       <com.google.android.gms.ads.AdView 
     xmlns:ads="http://schemas.android.com/apk/res-auto" 
     android:id="@+id/adView" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     ads:adSize="BANNER" 
     ads:adUnitId="xxxxxxxxxxxxxxxxxxxxxxx" /> 
    </LinearLayout> 
    </ScrollView> 



</RelativeLayout> 

Java代碼

package com.xx.xx; 

import java.io.BufferedReader; 
import java.io.IOException; 
import java.io.InputStream; 
import java.io.InputStreamReader; 
import java.net.URI; 
import java.net.URISyntaxException; 

import org.apache.http.HttpResponse; 
import org.apache.http.client.ClientProtocolException; 
import org.apache.http.client.HttpClient; 
import org.apache.http.client.methods.HttpGet; 
import org.apache.http.impl.client.DefaultHttpClient; 
import org.json.JSONArray; 
import org.json.JSONObject; 

import android.app.AlertDialog; 
import android.app.Fragment; 
import android.app.ProgressDialog; 
import android.content.Context; 
import android.content.DialogInterface; 
import android.graphics.Color; 
import android.graphics.Typeface; 
import android.os.AsyncTask; 
import android.os.Bundle; 
import android.telephony.TelephonyManager; 
import android.util.Log; 
import android.view.LayoutInflater; 
import android.view.View; 
import android.view.ViewGroup; 
import android.widget.Button; 
import android.widget.ListView; 
import android.widget.TextView; 

import com.google.android.gms.ads.AdRequest; 
import com.google.android.gms.ads.AdView; 


public class DetailsFragment extends Fragment { 

    public DetailsFragment(){} 

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

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

     return rootView; 
    } 

    ListView list; 
    Lazyimg adapter; 
    String name,imageurl,description,ingradiants,tduration; 
    String[] mname,mimageurl; 
    private ProgressDialog dialog; 
    String ids,b1status; 
    Button b1; 
    private static Typeface typeFace = null; 
    private static Typeface itypeFace = null; 


    public void onActivityCreated(Bundle savedInstanceState) { 
     super.onActivityCreated(savedInstanceState); 

     AdView adView = (AdView) getActivity().findViewById(R.id.adView); 
     AdRequest adRequest = new AdRequest.Builder().build(); 
     adView.loadAd(adRequest); 

     b1=(Button)getActivity().findViewById(R.id.Button1); 

     ids= getArguments().getString("ids"); 
     ids=ids.replace(" ", "%20"); 
     ids=ids.replace("-", "%27"); 

     initTypeFace(getActivity()); 
     iinitTypeFace(getActivity()); 
     b1.setOnClickListener(new View.OnClickListener() { 
      public void onClick(View v) { 
       // Perform action on click 
       GetData obj = new GetData(); 
       dialog = ProgressDialog.show(getActivity(), "", 
         "Please wait...", true); 
       TelephonyManager tManager = (TelephonyManager) getActivity().getBaseContext() 
         .getSystemService(Context.TELEPHONY_SERVICE); 
         String deviceIMEI = tManager.getDeviceId(); 
       String urls="cczczccxx/xxy.php?id="+ids+"&imei="+deviceIMEI+"&fav=jomin"; 
       obj.execute(urls); 
      } 
     }); 
     loadingPopup(); 

    } 



    private void loadingPopup() { 
     GetData obj = new GetData(); 
     dialog = ProgressDialog.show(getActivity(), "", 
       "Loading recipe details...", true); 
     TelephonyManager tManager = (TelephonyManager) getActivity().getBaseContext() 
       .getSystemService(Context.TELEPHONY_SERVICE); 
       String deviceIMEI = tManager.getDeviceId(); 
     String urls="xxx/xxy.php?id="+ids+"&imei="+deviceIMEI; 
     obj.execute(urls); 

    } 
    public class GetData extends AsyncTask<String, Void, String>{ 

      @Override 
      protected String doInBackground(String... params) { 
       // TODO Auto-generated method stub 

       BufferedReader reader =null; 
       String data =null; 

       try{ 

        HttpClient client = new DefaultHttpClient(); 
        URI uri=new URI(params[0]); 

        HttpGet get =new HttpGet(uri); 

        HttpResponse response= client.execute(get); 

        InputStream stream=response.getEntity().getContent(); 

        reader = new BufferedReader(new InputStreamReader(stream)); 

        StringBuffer buffer =new StringBuffer(""); 
        String line=""; 

        while((line=reader.readLine())!=null){ 
         buffer.append(line); 
        } 
        reader.close(); 
        data = buffer.toString(); 

        JSONObject fulldata = new JSONObject(data); 
        JSONArray albumdata = (JSONArray) fulldata.get("data"); 
        JSONObject sobj = null; 

        name=""; imageurl=""; description=""; ingradiants=""; tduration=""; b1status=""; 

        for(int j=0;j<albumdata.length();++j) 
        { 
        sobj= (JSONObject) albumdata.get(j); 
        b1status += (String)sobj.get("fav"); 
        name += (String) sobj.get("name"); 
        imageurl += (String) sobj.get("imageurl"); 
        description += (String) sobj.get("description"); 
        ingradiants += (String) sobj.get("ingradiants"); 
        tduration += (String) sobj.get("tduration"); 
        } 

        return ""; 

       } 
       catch(URISyntaxException e){ 
        e.printStackTrace(); 
       } 
       catch(ClientProtocolException f){ 
        f.printStackTrace(); 
       } 
       catch(IOException g){ 
        g.printStackTrace(); 
       } 
       catch(Exception e) 
       { 
       // 
       } 
       finally{ 
        if(reader!=null){ 
         try{ 
          reader.close(); 
         } 
         catch(Exception e){ 

         } 
        } 
       } 

       return null; 
      } 
      @Override 
      protected void onPostExecute(String result) { 
       // TODO Auto-generated method stub 
       super.onPostExecute(result); 

       try { 
        dialog.dismiss(); 
       } catch (Exception e) { 
       Log.e(e.getClass().getName(), e.getMessage(), e); 
       } 

       if(result==null) 
       { 
        new AlertDialog.Builder(getActivity()) 
        .setIcon(android.R.drawable.ic_dialog_alert) 
        .setMessage("\n Connection Error..!\n") 
        .setPositiveButton("Exit", new DialogInterface.OnClickListener() 
       { 
        @Override 
        public void onClick(DialogInterface dialog, int which) { 
         getActivity().finish();  
        } 

       }) 
       .setNegativeButton("Retry", new DialogInterface.OnClickListener() 
       { 
        @Override 
        public void onClick(DialogInterface dialoga, int which) { 
         try { 
          dialog.dismiss(); 
         } catch (Exception e) { 
         Log.e(e.getClass().getName(), e.getMessage(), e); 
         } 
         GetData obj = new GetData(); 
         dialog = ProgressDialog.show(getActivity(), "", 
           "Loading recipe details...", true); 
         TelephonyManager tManager = (TelephonyManager) getActivity().getBaseContext() 
           .getSystemService(Context.TELEPHONY_SERVICE); 
           String deviceIMEI = tManager.getDeviceId(); 
         String urls="xxxxy.php?id="+ids+"&imei="+deviceIMEI; 
         obj.execute(urls); 
        } 

       }) 
       .show(); 
       } 
       else 
       { 

       mname = name.split("xstream"); 
       mimageurl = imageurl.split("xstream"); 

       if(b1status.equals("")) 
       { 
        b1.setBackgroundResource(R.drawable.favr); 
       } 
       else if(b1status.equals("f")) 
       { 
        b1.setBackgroundResource(R.drawable.favrg); 
       } 
       TextView ting=(TextView)getView().findViewById(R.id.textView4); 
       ting.setText("Ingredients"); 
       ting.setTypeface(typeFace); 
       ting.setTextColor(Color.parseColor("#210B61")); 
       ting.setTextSize(25); 

       TextView tpre=(TextView)getView().findViewById(R.id.textView5); 
       tpre.setText("\n\nDirections for Preparation"); 
       tpre.setTypeface(typeFace); 
       tpre.setTextColor(Color.parseColor("#210B61")); 
       tpre.setTextSize(25); 

       if(tduration.equals("")) 
       { 
        TextView ttduration=(TextView)getView().findViewById(R.id.textView1); 
        ttduration.setText("READY IN : Depends"); 
        ttduration.setTypeface(itypeFace); 
        ttduration.setTextColor(Color.parseColor("#FF8000")); 
        ttduration.setTextSize(20); 
       } 
       else 
       { 
       TextView ttduration=(TextView)getView().findViewById(R.id.textView1); 
       ttduration.setText("READY IN : "+tduration); 
       ttduration.setTypeface(itypeFace); 
       ttduration.setTextColor(Color.parseColor("#FF8000")); 
       ttduration.setTextSize(20); 
       } 

       TextView tingradiants=(TextView)getView().findViewById(R.id.textView2); 
       ingradiants=ingradiants.replaceAll("<br>", "\n\n"); 
       ingradiants=ingradiants.replaceAll("&#34;", "\""); 
       ingradiants=ingradiants.replaceAll("&#39;", "'"); 
       ingradiants=ingradiants.replaceAll("&#174;", " "); 
       tingradiants.setText(ingradiants); 
       tingradiants.setTypeface(typeFace); 
       tingradiants.setTextColor(Color.parseColor("#000000")); 
       tingradiants.setTextSize(20); 


       TextView tdescription=(TextView)getView().findViewById(R.id.textView3); 
       description=description.replaceAll("<br>", "\n\n"); 
       description=description.replaceAll("&#34;", "\""); 
       description=description.replaceAll("&#39;", "'"); 
       description=description.replaceAll("&#174;", " "); 

       tdescription.setText(description); 
       tdescription.setTypeface(itypeFace); 
       tdescription.setTextSize(20); 

       list=(ListView)getView().findViewById(R.id.list); 
       // Create custom adapter for listview 
       adapter=new Lazyimg(getActivity(), mimageurl,mname); 

       //Set adapter to listview 
       list.setAdapter(adapter); 
       } 
           //Button b=(Button)findViewById(R.id.button1); 
       //b.setOnClickListener(listener); 
      } 
     } 
    public static void initTypeFace(Context context) { 

       try { 
        typeFace = Typeface.createFromAsset(context.getAssets(), "Nexa_Light.otf"); 
       } catch (Exception e) { 
        e.printStackTrace(); 
       } 

     } 
    public static void iinitTypeFace(Context context) { 

     try { 
      itypeFace = Typeface.createFromAsset(context.getAssets(), "iowan.ttf"); 
     } catch (Exception e) { 
      e.printStackTrace(); 
     } 

} 
} 
+0

任何錯誤我會來 – 2014-09-04 04:49:47

+0

@NaveenTamrakar對不起,我沒有得到你。 – 2014-09-04 04:51:20

+0

有你在設備上檢查它或emulater – 2014-09-04 04:59:53

回答

0

爲您的AdView沒有實際是在屏幕上它可能是那樣簡單。 AdView包含在ScrollView中,因此不能保證它實際上在屏幕上。

您有一個複雜的視圖層次結構。建議您簡化它並在您的ScrollView之外移動AdView。