2016-05-25 13 views
1

私はthisの仕切りをmy gridviewに設定していますが、問題はサーバーから5つのアイテムを取得していて、gridviewに設定していますが、最後のgriditemでは灰色のボックスが表示されます。 row番号に挿入されるもうrowsがないのでdefault行動だこの出力https://imageshack.com/i/poKIvv1Upgridviewで仕切りを設定する方法

+0

そして、それは何をする必要がありますしてください? – xAqweRx

答えて

4

public class Best_Product extends BaseAdapter { 
 
    View gridView; 
 
    private Context context; 
 
    
 
    private ArrayList<HashMap<String, String>> MyArr = new ArrayList<HashMap<String, String>>(); 
 
    Function_List fun_lib = new Function_List(); 
 
    public Best_Product(Context c,ArrayList<HashMap<String, String>> json_value) { 
 
     // TODO Auto-generated method stub 
 
     context = c; 
 
     MyArr = json_value; 
 
    } 
 

 
    public int getCount() { 
 
     // TODO Auto-generated method stub 
 
     int total_size = MyArr.size(); 
 
\t \t Log.d("size of item", "" + MyArr.size()); 
 
\t \t \t if((MyArr.size()%2)==0) 
 
\t \t \t { 
 
\t \t \t \t // do nothing 
 
\t \t \t } 
 
\t \t \t else 
 
\t \t \t { 
 
\t \t \t \t total_size = MyArr.size()+1; 
 
\t \t \t } 
 
\t \t \t 
 
     return total_size; 
 
    } 
 

 
    public Object getItem(int position) { 
 
     // TODO Auto-generated method stub 
 
     return position; 
 
    } 
 

 
    public long getItemId(int position) { 
 
     // TODO Auto-generated method stub 
 
     HashMap<String, String> mapAtPostion = MyArr.get(position); 
 
     return Long.valueOf(MyArr.get(position).get("product_id")); 
 

 
    } 
 

 
    public View getView(int position, View convertView, ViewGroup parent) { 
 
     
 
     View view = convertView; 
 
     RelativeLayout background_color; // this will be the Relativelayout of the content of GridView. you will be set backgroud color of last item 
 
     LayoutInflater inflater = (LayoutInflater) context 
 
       .getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
 
\t \t \t if (view == null) { 
 
\t \t \t \t view = new View(context); 
 
\t \t \t \t view = inflater.inflate(R.layout.home_best_collection_content, parent, false); 
 
\t \t \t \t background_color = (RelativeLayout)view.findViewById(R.id.bckground); 
 
\t \t \t \t \t //checking last item of the array 
 
\t \t \t \t if(position ==MyArr.size()-1) 
 
\t \t \t \t { 
 
\t \t \t \t \t //change the last item background color 
 
\t \t \t \t \t background_color.setBackgroundColor(); 
 
\t \t \t \t } 
 
\t \t \t \t else 
 
\t \t \t \t { 
 
\t \t \t \t \t \t // do the work here 
 
\t \t \t \t } 
 
\t \t \t } 
 
\t \t \t else 
 
\t \t \t { 
 
\t \t 
 
\t \t \t } 
 
     return view; 
 
    } 
 
}

このコードを試してみて、私はすべての問題を教えて、 おかげ

+0

を上書きするだけでは不可能です。これはうまくいきました。ありがとうございました。 –

+0

素晴らしい、問題ありません、ありがとう –

0

を参照してください、それがbackground「空きスペース」を示す必要があります6.もし私があなただったら、私はGridViewを取り除くた
RecyclerViewを使用し、StaggeredLayoutManagerまたはGridLayoutManagerを使用して、スパン数に対するより多くの制御を行い、それに応じて修正することができます。

+0

はい私はそれがリサイクラーで簡単になることに同意しますが、グリッドビューではなぜですか? –

+0

@AdityaVyasこれは一般的なGridViewの動作であり、GridViewのelemen – xAqweRx

関連する問題