Get it on google play

Admob banner problem



  • بعد انهائى للتطبيق تدريبي يعتمد على
    listview
    والadapter
    ونفس ال
    Listview
    مربوط بيها اكتر من
    Activity

    وهنا كانت المشكلة انى مش عارف اضيفله
    banner ad من admob
    ولكن الشاشة الرئيسية تمت الاضافة بنجاح للاعلان
    رابط النهائى للمشروع على
    Github
    عشان مش عارف اساسا هحط الكود فين
    المطلوب:
    معرفة كيف اضيف اعلان البانر على الشاشات الفرعية
    وليست الرئيسية لانه تم اضافة الاعلان على الشاشة الرئيسية
    https://github.com/udacity/ud839_Miwok/tree/3d055a71fd487403f0d0d513b224b6f23f88d482


  • administrators

    ارجو دعم الموضوع بالصور


  • administrators

    وكمان اللنك ده بتاع يوداستى على جت هب
    فين المشروع بتاعك؟


  • administrators

    وارجو شرح تسلسل الشاشات او الموضوع



  • هوا بالضبط
    لانى شلت المعروض للمستخدم مع بقاء الاكواد بالضبط
    بس مش عارف ارفع انهوا
    Activity or class or layout or adapter
    هوالموضوع كلو مركز على
    Listview
    بيتعرض فيها محتويات أربعة
    activity
    وبيتفتحوا عن طريق ال
    Adapters
    وال
    Listener


  • administrators

    عذرا اخى مش فاهم حاجة ارجو دعم الموضوع بالصور



  • صور للاكواد؟



  • وهل وضح انى عايز اضيف اعلان بانر؟


  • administrators

    مش عندك مشروع زى
    miwok
    وعدلت عليه
    وبيشتغل على الموبايل
    ارفع المشروع بعد التعديلات على جت هب
    ولا انت تقصد ايه؟



  • أول حاجة دة اكتيفيتى من ال
    Activites
    @Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.word_list);

        // Create and setup the {@link AudioManager} to request audio focus
        mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
    
        // Create a list of words
        final ArrayList<Word> words = new ArrayList<Word>();
        words.add(new Word("Where are you going?", "minto wuksus",
                R.raw.phrase_where_are_you_going));
        words.add(new Word("What is your name?", "tinnә oyaase'nә",
                R.raw.phrase_what_is_your_name));
        words.add(new Word("My name is...", "oyaaset...", R.raw.phrase_my_name_is));
        words.add(new Word("How are you feeling?", "michәksәs?", R.raw.phrase_how_are_you_feeling));
        words.add(new Word("I’m feeling good.", "kuchi achit", R.raw.phrase_im_feeling_good));
        words.add(new Word("Are you coming?", "әәnәs'aa?", R.raw.phrase_are_you_coming));
        words.add(new Word("Yes, I’m coming.", "hәә’ әәnәm", R.raw.phrase_yes_im_coming));
        words.add(new Word("I’m coming.", "әәnәm", R.raw.phrase_im_coming));
        words.add(new Word("Let’s go.", "yoowutis", R.raw.phrase_lets_go));
        words.add(new Word("Come here.", "әnni'nem", R.raw.phrase_come_here));
    
        // Create an {@link WordAdapter}, whose data source is a list of {@link Word}s. The
        // adapter knows how to create list items for each item in the list.
        WordAdapter adapter = new WordAdapter(this, words, R.color.category_phrases);
    
        // Find the {@link ListView} object in the view hierarchy of the {@link Activity}.
        // There should be a {@link ListView} with the view ID called list, which is declared in the
        // word_list.xml layout file.
        ListView listView = (ListView) findViewById(R.id.list);
    
        // Make the {@link ListView} use the {@link WordAdapter} we created above, so that the
        // {@link ListView} will display list items for each {@link Word} in the list.
        listView.setAdapter(adapter);
    
        // Set a click listener to play the audio when the list item is clicked on
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {
                // Release the media player if it currently exists because we are about to
                // play a different sound file
                releaseMediaPlayer();
    
                // Get the {@link Word} object at the given position the user clicked on
                Word word = words.get(position);
    
                // Request audio focus so in order to play the audio file. The app needs to play a
                // short audio file, so we will request audio focus with a short amount of time
                // with AUDIOFOCUS_GAIN_TRANSIENT.
                int result = mAudioManager.requestAudioFocus(mOnAudioFocusChangeListener,
                        AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN_TRANSIENT);
    
                if (result == AudioManager.AUDIOFOCUS_REQUEST_GRANTED) {
                    // We have audio focus now.
    
                    // Create and setup the {@link MediaPlayer} for the audio resource associated
                    // with the current word
                    mMediaPlayer = MediaPlayer.create(PhrasesActivity.this, word.getAudioResourceId());
    
                    // Start the audio file
                    mMediaPlayer.start();
    
                    // Setup a listener on the media player, so that we can stop and release the
                    // media player once the sound has finished playing.
                    mMediaPlayer.setOnCompletionListener(mCompletionListener);
                }
            }
        });
    }


  • ودة الكلاس الوسيط
    package com.example.android.miwok;

    /**

    • {@link Word} represents a vocabulary word that the user wants to learn.

    • It contains a default translation, a Miwok translation, and an image for that word.
      */
      public class Word {

      /** Default translation for the word */
      private String mDefaultTranslation;

      /** Miwok translation for the word */
      private String mMiwokTranslation;

      /** Audio resource ID for the word */
      private int mAudioResourceId;

      /** Image resource ID for the word */
      private int mImageResourceId = NO_IMAGE_PROVIDED;

      /** Constant value that represents no image was provided for this word */
      private static final int NO_IMAGE_PROVIDED = -1;

      /**

      • Create a new Word object.
      • @param defaultTranslation is the word in a language that the user is already familiar with
      •                       (such as English)
        
      • @param miwokTranslation is the word in the Miwok language
      • @param audioResourceId is the resource ID for the audio file associated with this word
        */
        public Word(String defaultTranslation, String miwokTranslation, int audioResourceId) {
        mDefaultTranslation = defaultTranslation;
        mMiwokTranslation = miwokTranslation;
        mAudioResourceId = audioResourceId;
        }

      /**

      • Create a new Word object.
      • @param defaultTranslation is the word in a language that the user is already familiar with
      •                       (such as English)
        
      • @param miwokTranslation is the word in the Miwok language
      • @param imageResourceId is the drawable resource ID for the image associated with the word
      • @param audioResourceId is the resource ID for the audio file associated with this word
        */
        public Word(String defaultTranslation, String miwokTranslation, int imageResourceId,
        int audioResourceId) {
        mDefaultTranslation = defaultTranslation;
        mMiwokTranslation = miwokTranslation;
        mImageResourceId = imageResourceId;
        mAudioResourceId = audioResourceId;
        }

      /**

      • Get the default translation of the word.
        */
        public String getDefaultTranslation() {
        return mDefaultTranslation;
        }

      /**

      • Get the Miwok translation of the word.
        */
        public String getMiwokTranslation() {
        return mMiwokTranslation;
        }

      /**

      • Return the image resource ID of the word.
        */
        public int getImageResourceId() {
        return mImageResourceId;
        }

      /**

      • Returns whether or not there is an image for this word.
        */
        public boolean hasImage() {
        return mImageResourceId != NO_IMAGE_PROVIDED;
        }

      /**

      • Return the audio resource ID of the word.
        */
        public int getAudioResourceId() {
        return mAudioResourceId;
        }
        }


  • ودة ال
    Adapter
    public class WordAdapter extends ArrayAdapter<Word> {

    /** Resource ID for the background color for this list of words */
    private int mColorResourceId;
    
    /**
     * Create a new {@link WordAdapter} object.
     *
     * @param context is the current context (i.e. Activity) that the adapter is being created in.
     * @param words is the list of {@link Word}s to be displayed.
     * @param colorResourceId is the resource ID for the background color for this list of words
     */
    public WordAdapter(Context context, ArrayList<Word> words, int colorResourceId) {
        super(context, 0, words);
        mColorResourceId = colorResourceId;
    }
    
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        // Check if an existing view is being reused, otherwise inflate the view
        View listItemView = convertView;
        if (listItemView == null) {
            listItemView = LayoutInflater.from(getContext()).inflate(
                    R.layout.list_item, parent, false);
        }
    
        // Get the {@link Word} object located at this position in the list
        Word currentWord = getItem(position);
    
        // Find the TextView in the list_item.xml layout with the ID miwok_text_view.
        TextView miwokTextView = (TextView) listItemView.findViewById(R.id.miwok_text_view);
        // Get the Miwok translation from the currentWord object and set this text on
        // the Miwok TextView.
        miwokTextView.setText(currentWord.getMiwokTranslation());
    
        // Find the TextView in the list_item.xml layout with the ID default_text_view.
        TextView defaultTextView = (TextView) listItemView.findViewById(R.id.default_text_view);
        // Get the default translation from the currentWord object and set this text on
        // the default TextView.
        defaultTextView.setText(currentWord.getDefaultTranslation());
    
        // Find the ImageView in the list_item.xml layout with the ID image.
        ImageView imageView = (ImageView) listItemView.findViewById(R.id.image);
        // Check if an image is provided for this word or not
        if (currentWord.hasImage()) {
            // If an image is available, display the provided image based on the resource ID
            imageView.setImageResource(currentWord.getImageResourceId());
            // Make sure the view is visible
            imageView.setVisibility(View.VISIBLE);
        } else {
            // Otherwise hide the ImageView (set visibility to GONE)
            imageView.setVisibility(View.GONE);
        }
    
        // Set the theme color for the list item
        View textContainer = listItemView.findViewById(R.id.text_container);
        // Find the color that the resource ID maps to
        int color = ContextCompat.getColor(getContext(), mColorResourceId);
        // Set the background color of the text container View
        textContainer.setBackgroundColor(color);
    
        // Return the whole list item layout (containing 2 TextViews) so that it can be shown in
        // the ListView.
        return listItemView;
    }
    

    }



  • ودة ال
    Xml listview
    <?xml version="1.0" encoding="utf-8"?>

    <ListView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/list"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:drawSelectorOnTop="true"/>



  • وخيرا ال
    Xml
    اللى فيه
    التصميم
    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="@dimen/list_item_height"
    android:background="@color/tan_background"
    android:minHeight="@dimen/list_item_height">

    <ImageView
        android:id="@+id/image"
        android:layout_width="@dimen/list_item_height"
        android:layout_height="@dimen/list_item_height" />
    
    <RelativeLayout
        android:id="@+id/text_container"
        android:layout_width="match_parent"
        android:layout_height="@dimen/list_item_height"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:layout_toRightOf="@id/image"
        android:orientation="vertical"
        android:paddingLeft="16dp">
    
        <TextView
            android:id="@+id/miwok_text_view"
            android:layout_width="match_parent"
            android:layout_height="44dp"
            android:layout_weight="1"
            android:gravity="bottom"
            android:textAppearance="?android:textAppearanceMedium"
            android:textColor="@android:color/white"
            android:textStyle="bold"
            tools:text="lutti" />
    
        <TextView
            android:id="@+id/default_text_view"
            android:layout_width="match_parent"
            android:layout_height="44dp"
            android:layout_below="@id/miwok_text_view"
            android:layout_weight="1"
            android:gravity="top"
            android:textAppearance="?android:textAppearanceMedium"
            android:textColor="@android:color/white"
            tools:text="one" />
    
        <ImageView
            android:layout_width="24dp"
            android:layout_height="24dp"
            android:layout_alignParentRight="true"
            android:layout_centerVertical="true"
            android:layout_marginRight="16dp"
            android:src="@drawable/ic_play_arrow" />
    </RelativeLayout>
    

    </RelativeLayout>



  • السؤال اين أضع الاعلان فال
    xml
    واين وكيف اربطة بالجافا



  • تم الحل بحمد الله
    💟💟💟💟💟💟
    شكرا جدا على محاوله المساعدة



  • ممكن وضع الحل ليستفيد منه الاخرون لو سمحت ؟



  • الحل بسيط الاعلان بتحطوا فال
    xml
    في
    ال
    listview
    <?xml version="1.0" encoding="utf-8"?>

    <ListView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/list"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:drawSelectorOnTop="true"/>



  • هنخليه بالشكل دة



  • <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    >
    <ListView
    android:id="@+id/list"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:drawSelectorOnTop="true"
    android:orientation="vertical"
    android:layout_above="@id/adView"
    android:layoutDirection="ltr">
    </ListView>
    android:paddingLeft="@dimen/activity_horizontal_margin"--><!--android:paddingRight="@dimen/activity_horizontal_margin"--><!--android:paddingTop="@dimen/activity_vertical_margin"-->

    <com.google.android.gms.ads.AdView
        android:id="@+id/adView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        app:adSize="BANNER"
        app:adUnitId="@string/adPanner"
        android:layoutDirection="ltr">
    
    
    </com.google.android.gms.ads.AdView>
    

    </RelativeLayout>


 

Suggested Topics