2017-03-19 10 views
0

私はこのようになりますGridViewコントロールアダプタでレイアウトを作成しました:https://gyazo.com/20990f2640d115e8751c386f51913142 は、どのように私はそれがあまりにもスクロール可能であることを、このようにボタンを追加することができます?: https://gyazo.com/46806b05c52e963f146cc7f87f2017b1生成されたGridViewに別のボタンを追加するにはどうすればよいですか?

断片でマイアダプタ:

package com.aaron.waller.tanzverbotsoundboard.mFragments; 

import android.content.Context; 
import android.os.Bundle; 
import android.support.annotation.Nullable; 
import android.support.v4.app.Fragment; 
import android.view.LayoutInflater; 
import android.view.View; 
import android.view.ViewGroup; 
import android.widget.BaseAdapter; 
import android.widget.Button; 
import android.widget.GridView; 

import com.aaron.waller.tanzverbotsoundboard.MainActivity; 
import com.aaron.waller.tanzverbotsoundboard.R; 

/** 
* Created by Oclemmy on 5/10/2016 for ProgrammingWizards Channel and http://www.Camposha.com. 
*/ 
public class erstesFragment extends Fragment{ 


    GridView myGridView; 
    public String[] items1 ={"alter schwede","Alter finne","was was was","ach schön","Du alte kacksau","Beatbox","Achjaa 1","Achjaa 2","Warum hast du eine Maske auf?" 
      ,"boah 1","boah 2","Das Kackhuhn","Das ist doch wohl..." 
      ,"Das ist ja unverschämt","das ist nicht wahr 1","das ist nicht wahr 2" 
      ,"Das klappt ja super","eh","eh was","wie gemein","Engels-\nstimme","Englisch skills over 9000" 
      ,"Freunde suche","Evil chicken","Pfui 1","Pfui 2","Gehirn-\naussetzer","Feierlaune","Gesangs-\neinlage 1" 
      ,"Gesangs-\neinlage 2","Gesangs-\neinlage 3","was?","Miau","Halt die Fresse","hör auf","huaa","huch 1","huch 2","huiii","Ich bin noch ganz klein","ja geile scheiße","jaa" 
      ,"Jo","kann man machen","Ihre Frau hat krebs","Komisches Geräusch 1","Komisches Geräusch 2","Komisches Geräusch 3","Komisches Geräusch 4","Komisches Geräusch 5","Komisches Geräusch 6","Komisches Geräusch 7" 
      ,"Kuh 1","Kuh 2","Kuh 3","Definition von Kunstraum","Ladescreen 1","Ladescreen 2","Ladescreen 3","Ladescreen 4","Ladescreen 5","Ladescreen 6","Ladescreen 7","Ladescreen 8","Ladescreen 9" 
      ,"Ledersofa aus Plastik","Mobbing spiel","Nachbar 1","Nachbar 2","Nachbar 3","Neiin 1","Neiin 2","Neiin 3","Neiin 4","Nein Nein Nein nein","niemals","ok","oke","oh man","Omi?","Omi bist dus?","Geschäfts-\nidee" 
      ,"Der Pissnapf","Plastik-\nfliesen","Qualität","Dunkel wie im Rattenarsch","Räusperer","Rindenmulch","Die Scheere","wueah","schlipper","Schnauze!","Der Schwimmer","Soo 1" 
      ,"soo 2","Spieglein Spieglein...","Sprachlos 1","Sprachlos 2","Stöhnen 1","Stöhnen 2","Stöhnen + Neiin","Das Treppenhaus","Tupperparty","und ähm 1","und ähm 2","Nur ein husten" 
      ,"Wie geil ist das denn 1","Wie geil ist das denn 2"}; 

    @Nullable 
    @Override 
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 
     View rootView=inflater.inflate(R.layout.erstes_fragment,container,false); 




     myGridView = (GridView)rootView.findViewById(R.id.gridView1); 
     myGridView.setAdapter(new CustomGridAdapter(getActivity(), items1)); 

     return rootView; 
    } 




    public class CustomGridAdapter extends BaseAdapter { 

     private Context context; 
     private String[] items; 
     LayoutInflater inflater; 

     public CustomGridAdapter(Context c, String[] items) { 
      this.context = c; 
      this.items = items; 
      inflater = (LayoutInflater) this.context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
     } 




     @Override 
     public int getCount() { 
      return items.length; 
     } 

     @Override 
     public Object getItem(int position) { 
      return items[position]; 
     } 

     @Override 
     public long getItemId(int position) { 
      return position; 
     } 

     @Override 
     public View getView(final int position, View convertView, ViewGroup parent) { 

      if (convertView == null) { 
       convertView = inflater.inflate(R.layout.single_item, null); 
      } 
      Button button = (Button) convertView.findViewById(R.id.button); 
      button.setText(items[position]); 
      button.setOnClickListener(new View.OnClickListener() { 

       @Override 
       public void onClick(View v) { 
        if (context instanceof MainActivity) { 
         ((MainActivity) context).itemClicked1(position); 
        } 
       } 
      }); 

      return convertView; 
     } 


    } 
} 

そして、私のフラグメントのXML:

<?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" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context="com.aaron.waller.tanzverbotsoundboard.MainActivity"> 


    <GridView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:id="@+id/gridView1" 
     android:layout_marginTop="50dp" 
     android:layout_alignParentTop="true" 
     android:layout_alignParentLeft="true" 
     android:numColumns="auto_fit" 
     android:horizontalSpacing="0dp" 
     android:verticalSpacing="0dp" 
     android:columnWidth="155dp" 
     android:layout_marginBottom="55dp" 
     android:stretchMode="spacingWidthUniform"/> 

</RelativeLayout> 

答えて

0

GridViewは列スパニングをサポートしていません。代わりにTableLayoutGridLayoutを使用する必要があります。

+0

@TheUseraccawd便利ですか? – LaurentY

関連する問題