1
wxr
2023-04-23 2cd55265ccff3b0a267d7953b2dd9e5dca437aa6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/* 
 * @ProjectName ezviz-openapi-android-demo
 * @Copyright null
 * 
 * @FileName MenuAdapter.java
 * @Description 这里对文件进行描述
 * 
 * @author chenxingyf1
 * @data 2015-5-12
 * 
 * @note 这里写本文件的详细功能描述和注释
 * @note 历史记录
 * 
 * @warning 这里写本文件的相关警告
 */
package com.videogo.widget;
 
import android.content.Context;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.ArrayAdapter;
import android.widget.RelativeLayout.LayoutParams;
import android.widget.TextView;
 
import com.videogo.util.Utils;
 
import java.util.List;
 
import ezviz.ezopensdk.R;
 
public class MenuAdapter extends ArrayAdapter<TitleMenuItem> {
    private Context mContext = null;
    public MenuAdapter(Context context, List<TitleMenuItem> objects) {
        super(context, 0, objects);
        mContext = context;
    }
 
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        TextView textView;
        if (convertView == null) {
            textView = new TextView(getContext());
            textView.setGravity(Gravity.CENTER_VERTICAL);
            textView.setPadding(Utils.dip2px(getContext(), 10), 0, Utils.dip2px(getContext(), 10), 0);
            textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 15);
            textView.setCompoundDrawablePadding(Utils.dip2px(getContext(), 4));
            textView.setTextColor(mContext.getResources().getColorStateList(R.color.title_down_text_selector));
            AbsListView.LayoutParams layoutParams = new AbsListView.LayoutParams(LayoutParams.MATCH_PARENT,
                    Utils.dip2px(mContext, 40));
            textView.setLayoutParams(layoutParams);
            convertView = textView;
        } else {
            textView = (TextView) convertView;
        }
 
        TitleMenuItem menuItem = getItem(position);
        textView.setText(menuItem.text);
        textView.setCompoundDrawablesWithIntrinsicBounds(menuItem.iconResId, 0, 0, 0);
 
        return convertView;
    }   
}