2017-06-07 2 views
0

Ich versuche eine Android-Anwendung zu erstellen, ich habe eine 3 Spalten Gridview, die eine Liste von Punkten anzeigen, ich möchte in einer Bedingung zur nächsten Zeile springen, auch wenn einige der Spalten sind leerArtikel überspringen Android Grid View in Zustand

Beispiel möchte ich so etwas wie dies zu tun:

ARX ARH 
BRH BRX BRY 
CRH 
DRH DRY 
+0

Ist es Gridpflicht zu verwenden, oder wir können mit Listview verwalten? –

+0

Ja, wir können mit Listview jede Lösung verwalten? –

+0

Ja ich habe eine Lösung .... siehe meinen Beitrag als Antwort. –

Antwort

0

Versuchen Sie dieses
Ihre Liste item Row XML wie folgt abc.xml

wäre
<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="vertical" 
    android:background="@android:color/darker_gray"> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" 
     android:layout_margin="5dp"> 

     <TextView 
      android:id="@+id/textView1" 
      android:layout_width="match_parent" 
      android:layout_height="80dp" 
      android:layout_weight="1" 
      android:gravity="center" 
      android:text="Name1" 
      android:textSize="18sp" 
      android:background="@android:color/white" 
      android:layout_margin="5dp"/> 

     <TextView 
      android:id="@+id/textView2" 
      android:layout_width="match_parent" 
      android:layout_height="80dp" 
      android:layout_weight="1" 
      android:gravity="center" 
      android:text="Name2" 
      android:textSize="18sp" 
      android:layout_margin="5dp" 
      android:background="@android:color/white"/> 

     <TextView 
      android:id="@+id/textView3" 
      android:layout_width="match_parent" 
      android:layout_height="80dp" 
      android:layout_weight="1" 
      android:gravity="center" 
      android:text="Name3" 
      android:textSize="18sp" 
      android:layout_margin="5dp" 
      android:background="@android:color/white"/> 


    </LinearLayout> 


</LinearLayout> 

Und CustomAdapter für List möchten uns an dieser

public class Custom_Adapter_Products extends BaseAdapter { 
    Context context; 
    String[] list = {"AAA","AAA","AAA","AAA","AAA","","AAA", "AAA","AAA"}; 

    public Custom_Adapter_Products(Context context){ 
     this.context = context; 
    } 

    @Override 
    public int getCount() { 
     return (list.length/3); 
    } 

    @Override 
    public Object getItem(int position) { 

     return null; 
    } 

    @Override 
    public long getItemId(int position) { 

     return position; 
    } 

    @Override 
    public View getView(int pos, View convertView, ViewGroup parent) { 
     try{ 
      int position = (pos*3); 
      ViewHolder holder; 
      LayoutInflater vi = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
      if (convertView == null) 
      { 
       convertView = vi.inflate(R.layout.abc, null); 
       holder = createViewHolder(convertView); 
       convertView.setTag(holder); 
      } 
      else 
      { 
       holder = (ViewHolder) convertView.getTag(); 
      } 


      if(!list[position].equals("")){ 
       holder.textView1.setText(list[position]); 
       holder.textView1.setVisibility(View.VISIBLE); 
      } 
      else{ 
       holder.textView1.setVisibility(View.GONE); 
      } 

      if(!list[position+1].equals("")){ 
       holder.textView2.setText(list[position]); 
       holder.textView2.setVisibility(View.VISIBLE); 
      } 
      else{ 
       holder.textView2.setVisibility(View.GONE); 
      } 

      if(!list[position+2].equals("")){ 
       holder.textView3.setText(list[position]); 
       holder.textView3.setVisibility(View.VISIBLE); 
      } 
      else{ 
       holder.textView3.setVisibility(View.GONE); 
      } 

     }catch (Exception e){ 
      e.printStackTrace(); 
     } 
     return convertView; 
    } 


    private static class ViewHolder 
    { 
     public TextView textView1; 
     public TextView textView2; 
     public TextView textView3; 
    } 

    private ViewHolder createViewHolder(View v) { 
     ViewHolder holder = new ViewHolder(); 
     try{ 
      holder.textView1 = (TextView) v.findViewById(R.id.textView1); 
      holder.textView2 = (TextView) v.findViewById(R.id.textView2); 
      holder.textView3 = (TextView) v.findViewById(R.id.textView3); 
     }catch (Exception e) { 
      // TODO: handle exception 
      e.printStackTrace(); 
     } 
     return holder; 
    } 
} 
sein