2017-11-07 7 views
-5

im for vooley-mySql을 사용하는 미니 응용 프로그램을 코딩하는 중입니다. 이제는 SQLite로 변환하지만 아무 것도 표시하지 않는 gridview는 왜 데이터가 좋지만 표시되지 않는지 잘 모릅니다. 메사추세츠가 ArrayAdapter를 사용하려고하는데 작동하지만 내 앱에 이미지가있는 customAdapter가 필요합니다. helpme PLSCustomGridView가 작동하지 않고 아무 것도 표시하지 않습니다.

CustomGridView_Home.java : http://www.paste.org/88161

Fragment_home.java : http://www.paste.org/88162

SQLheper : http://www.paste.org/88163

+0

은 당신의 코드를 추가하십시오 질문, 나는 누군가가 그것을 보게 될 것입니다!. –

답변

0

어댑터 파일 :

활동에
public class CustomProductsAdapter extends BaseAdapter { 

TextView textView; 
ImageView imageView; 
String[] title = new String[]{}; 
String[] image = new String[]{}; 
private LayoutInflater inflater = null; 

public CustomProductsAdapter(Context context, String[] title, String[] image) { 

    this.title = title; 
    this.image = image; 

    inflater = (LayoutInflater) context. 
      getSystemService(Context.LAYOUT_INFLATER_SERVICE); 

} 

@Override 
public int getCount() { 
    return productList.size(); 
} 

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

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

@Override 
public View getView(final int position, View convertView, ViewGroup parent) { 
    LayoutInflater inflater = (LayoutInflater) context.getSystemService(context.LAYOUT_INFLATER_SERVICE); 
    View view = inflater.inflate(R.layout.custom_grid, null); 
    textView = (TextView) view.findViewById(R.id.textView); 
    imageView = (ImageView) view.findViewById(R.id.imageView); 
    return view; 
}} 

이있는 gridview를 초기화하고 어댑터 설정 목록,지도, 배열로 보낼 제목과 이미지가있는 곳

GridView products= (GridView) view.findViewById(R.id.products_grid); 
        products.setAdapter(new CustomProductsAdapter(getContext(),title,image); 
        setDynamicHeight(products); 

동적 높이는 방법은 여기에 있습니다 : 활동 XML의

public void setDynamicHeight(GridView gridView) { 
    ListAdapter gridViewAdapter = gridView.getAdapter(); 
    if (gridViewAdapter == null) { 
    return; 
    } 

    int totalHeight = 0; 
    int items = gridViewAdapter.getCount(); 
    int rows = 0; 

    View listItem = gridViewAdapter.getView(0, null, gridView); 
    listItem.measure(0, 0); 
    totalHeight = listItem.getMeasuredHeight(); 

    float x = 1; 
    if(items > 4){ 
    x = items/4; 
    if (x >= 2){ 
    x = x-1; 
    } 
    rows = (int) (x + 1); 
    totalHeight *= rows; 
    } 

    ViewGroup.LayoutParams params = gridView.getLayoutParams(); 
    params.height = totalHeight; 
    gridView.setLayoutParams(params); 
    } 

GRIDVIEW :

<GridView 
      android:layout_width="match_parent" 
        android:layout_height="match_parent" 
        android:id="@+id/products_grid" 
        android:numColumns="4" 
        android:layout_marginTop="@dimen/margin_10" 
        android:layout_marginStart="@dimen/margin_8" 
        android:layout_marginEnd="@dimen/margin_14" 
        android:layout_marginBottom="@dimen/margin_24" 
        /> 

그리드 주입을위한 어댑터 파일에

<ImageView 
    android:id="@+id/imageView" 
    android:layout_width="30dp" 
    android:layout_height="30dp" 
    android:layout_marginTop="14dp" 
    android:layout_marginStart="24dp" 
    android:layout_marginBottom="5dp" 
    android:src="@mipmap/bus" /> 
<TextView 
    android:id="@+id/textView" 
    android:gravity="center" 
    android:layout_width="75dp" 
    android:layout_height="wrap_content" 
    android:layout_marginTop="5dp" 
    android:layout_marginStart="5dp" 
    android:layout_marginEnd="10dp" 
    android:layout_marginBottom="14dp" 
    android:textSize="@dimen/textsize_12" 
    android:textColor="@color/mildblack" 
    android:text="Image Name" /> 
+0

여러 편집 죄송합니다. stackoverflow 편집기 그래서 지연 지연, 희망 솔루션을 찾을 수 프롬프트 –