2011-08-16 11 views

答えて

0

の1- ListViewクラスを拡張

public class CustomListView extends ListView { 

    public CustomListView(Context context, AttributeSet attrs, int defStyle) { 
     super(context, attrs, defStyle); 
    } 

    public CustomListView(Context context, AttributeSet attrs) { 
     super(context, attrs); 
    } 

    public CustomListView(Context context) { 
     super(context); 
    } 

    private Runnable afterLayoutRunnable; 

    public void setAfterLayoutRunnable(Runnable afterLayoutRunnable) { 
     this.afterLayoutRunnable = afterLayoutRunnable; 
    } 

    @Override 
    protected void onLayout(boolean changed, int left, int top, int right, int bottom) { 
     super.onLayout(changed, left, top, right, bottom); 
     if (afterLayoutRunnable != null) { 
      afterLayoutRunnable.run(); 
     } 
    } 

} 

2 - 私は、これは、幸運を動作するはずだと思うあなたのActivity

public class TestActivity extends Activity { 
    public static int listItemsMinimumHieght = 0; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 

     final CustomListView customListView = (CustomListView) findViewById(R.id.conversation_activity_button_send); 
     customListView.setAfterLayoutRunnable(new Runnable() { 

      @Override 
      public void run() { 
       listItemsMinimumHieght = customListView.getHeight()/4; 
       ArrayList<MyObject> objects=getListContent(); 
       customListView.setAdapter(new ListViewConversationAdapter(TestActivity.this, R.id.sample, objects)); 

      } 
     }); 

    } 

} 

で独自ArrayAdapter

public class CustomListAdapter extends ArrayAdapter<MyObject> { 
    public CustomListAdapter(Context context, int textViewResourceId, List<MyObject> objects) { 
     super(context, textViewResourceId, objects); 
    } 

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

     if (convertView == null) { 
      LayoutInflater layoutInflater = (LayoutInflater) getContext().getSystemService(
        Context.LAYOUT_INFLATER_SERVICE); 
      convertView = layoutInflater.inflate(R.layout.my_item_layout, null); 
      int height = TestActivity.listItemsMinimumHieght; 
      if (height > 0) { 
       convertView.setMinimumHeight(height); 
      } 
     } 

    } 

} 

3-作成

+0

'listItemsMinimumHieght = customListView.getHeight()/ 4;'正確な高さが返されなかった場合、 'listItemsMinimumHieght = customListView.getMeasuredHeight()/ 4;' –

+0

ありがとう!私はこれを試してみよう! – Filipe

+0

それはうまくいったのですか? –

関連する問題