开发者

Android,CustomListView

How could i decide size of each line in a ListView?

My problem is that i have a list of text and now each text (each line) is different in length but the size of the text is the same, so the problem is if the text is big my ListView will not be adjust for the text and will cut part of it.

I use this class to build the ListView:

    private class ListAdapter extends ArrayAdapter<Medicaments> {  // --CloneChangeRequired
    private ArrayList<Med> mList;  // --CloneChangeRequired
    private Context mContext;

    public ListAdapter(Context context, int textViewResourceId,ArrayList<Med> list) { // --CloneChangeRequired
        super(context, textViewResourceId, list);
        this.mList = list;
        this.mContext = context;
    }

    public View getView(int position, View convertView, ViewGroup parent)
    {
        View view = convertView;
        try{
        if (view == null) {
            LayoutInflater vi = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            view = vi.inflate(R.layout.singleresult, null);     // --CloneChangeRequired(list_item)
        }

        final Med listItem = mList.get(position);   // --开发者_JS百科CloneChangeRequired

        String Res=listItem.getMed().substring(0, 1).toUpperCase()+listItem.getMed().substring(1).toLowerCase();
         Res=WordUtils.capitalize(Res);
        if (listItem != null) {


            ( (TextView) view.findViewById(R.id.resultTextView) ).setText( Res+"\n");

        }}catch(Exception e){
            Log.i(ResultView.ListAdapter.class.toString(), e.getMessage());             
        }
        return view;
    }




}

Thanks for helping!!


Use android:layout_height="wrap_content" for the text view and also for the parent layout of the each item of the list.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜