【Android】实现新闻分类(二级下拉菜单)效果
功能分类:特效 | 支持平台:Android | 运行环境:Eclipse |
开发语言:Java | 开发工具:Eclipse | 源码大小:1011.04KB |
下载源码
1076 人下载
源码简介
利用ExpandableListView和GridView,实现类似新闻客户端二级下拉菜单效果。
源码截图
DevStore所有源码来自用户上传分享,版权问题及牵扯到商业纠纷均与DevStore无关。
源码片段
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
|
public
class
ExpandableListViewAdapter
extends
BaseExpandableListAdapter {
public
String[] group = {
"常用"
,
"搞笑"
,
"原创"
,
"资讯"
,
"体育"
,
"游戏"
,
"汽车"
,
"娱乐"
};
public
String[][] gridViewChild = {
{
"明星八卦"
,
"雷人囧事"
,
"网络红人"
,
"科技资讯"
,
"美女花边"
,
"游戏达人"
,
"美女车模"
,
"疯狂恶搞"
},
{
"疯狂恶搞"
,
"搞笑综艺"
,
"原创搞笑"
,
"爆笑宠物"
,
"雷人囧事"
},
{
"原创热点"
,
"原创影视"
,
"音乐动画"
,
"火星搞笑"
,
"校园作品"
,
"网络红人"
,
"拍客"
},
{
"社会资讯"
,
"国内资讯"
,
"国际资讯"
,
"财富资讯"
,
"科技资讯"
},
{
"篮球天地"
,
"足球世界"
,
"综合体育"
,
"极限运动"
,
"武术摔角"
,
"美女花边"
},
{
"网络游戏"
,
"电子竞技"
,
"单机电玩"
,
"游戏达人"
,
"工会战队"
},
{
"新车速递"
,
"车型推荐"
,
"改装酷玩"
,
"汽车广告"
,
"评测报告"
,
"美女车模"
},
{
"明星八卦"
,
"影视资讯"
} };
String[][] child = { {
""
}, {
""
}, {
""
}, {
""
}, {
""
}, {
""
},
{
""
}, {
""
} };
LayoutInflater mInflater;
Context context;
public
ExpandableListViewAdapter(Context context) {
// TODO Auto-generated constructor stub
mInflater = LayoutInflater.from(context);
this
.context = context;
}
@Override
public
Object getChild(
int
groupPosition,
int
childPosition) {
// TODO Auto-generated method stub
return
child[groupPosition][childPosition];
}
@Override
public
long
getChildId(
int
groupPosition,
int
childPosition) {
// TODO Auto-generated method stub
return
childPosition;
}
@Override
public
View getChildView(
int
groupPosition,
int
childPosition,
boolean
isLastChild, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
if
(convertView ==
null
) {
mViewChild =
new
ViewChild();
convertView = mInflater.inflate(
R.layout.channel_expandablelistview_item,
null
);
mViewChild.gridView = (GridView) convertView
.findViewById(R.id.channel_item_child_gridView);
convertView.setTag(mViewChild);
}
else
{
mViewChild = (ViewChild) convertView.getTag();
}
SimpleAdapter mSimpleAdapter =
new
SimpleAdapter(context,
setGridViewData(gridViewChild[groupPosition]),
R.layout.channel_gridview_item,
new
String[] {
"channel_gridview_item"
},
new
int
[] { R.id.channel_gridview_item });
mViewChild.gridView.setAdapter(mSimpleAdapter);
setGridViewListener(mViewChild.gridView);
mViewChild.gridView.setSelector(
new
ColorDrawable(Color.TRANSPARENT));
return
convertView;
}
/**
* 设置gridview点击事件监听
*
* @param gridView
*/
private
void
setGridViewListener(
final
GridView gridView) {
gridView.setOnItemClickListener(
new
GridView.OnItemClickListener() {
@Override
public
void
onItemClick(AdapterView<!--?--> parent, View view,
int
position,
long
id) {
// TODO Auto-generated method stub
if
(view
instanceof
TextView) {
// 如果想要获取到哪一行,则自定义gridview的adapter,item设置2个textview一个隐藏设置id,显示哪一行
TextView tv = (TextView) view;
Toast.makeText(context,
"position="
+ position +
"||"
+ tv.getText(),
Toast.LENGTH_SHORT).show();
Log.e(
"hefeng"
,
"gridView listaner position="
+ position
+
"||text="
+ tv.getText());
}
}
});
}
/**
* 设置gridview数据
*
* @param data
* @return
*/
private
ArrayList<hashmap<string, object=
""
>> setGridViewData(String[] data) {
ArrayList<hashmap<string, object=
""
>> gridItem =
new
ArrayList<hashmap<string, object=
""
>>();
for
(
int
i =
0
; i < data.length; i++) {
HashMap<string, object=
""
> hashMap =
new
HashMap<string, object=
""
>();
hashMap.put(
"channel_gridview_item"
, data[i]);
gridItem.add(hashMap);
}
return
gridItem;
}
@Override
public
int
getChildrenCount(
int
groupPosition) {
// TODO Auto-generated method stub
return
child[groupPosition].length;
}
@Override
public
Object getGroup(
int
groupPosition) {
// TODO Auto-generated method stub
return
group[groupPosition];
}
@Override
public
int
getGroupCount() {
// TODO Auto-generated method stub
return
group.length;
}
@Override
public
long
getGroupId(
int
groupPosition) {
// TODO Auto-generated method stub
return
groupPosition;
}
@Override
public
View getGroupView(
int
groupPosition,
boolean
isExpanded,
View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
if
(convertView ==
null
) {
mViewChild =
new
ViewChild();
convertView = mInflater.inflate(
R.layout.channel_expandablelistview,
null
);
mViewChild.textView = (TextView) convertView
.findViewById(R.id.channel_group_name);
mViewChild.imageView = (ImageView) convertView
.findViewById(R.id.channel_imageview_orientation);
convertView.setTag(mViewChild);
}
else
{
mViewChild = (ViewChild) convertView.getTag();
}
if
(isExpanded) {
mViewChild.imageView
.setImageResource(R.drawable.channel_expandablelistview_top_icon);
}
else
{
mViewChild.imageView
.setImageResource(R.drawable.channel_expandablelistview_bottom_icon);
}
mViewChild.textView.setText(getGroup(groupPosition).toString());
return
convertView;
}
@Override
public
boolean
hasStableIds() {
// TODO Auto-generated method stub
return
true
;
}
@Override
public
boolean
isChildSelectable(
int
groupPosition,
int
childPosition) {
// TODO Auto-generated method stub
return
true
;
}
ViewChild mViewChild;
static
class
ViewChild {
ImageView imageView;
TextView textView;
GridView gridView;
}
}</string,></string,></hashmap<string,></hashmap<string,></hashmap<string,>
|
- 赞(2)
- 收藏(19)
- 下载(1076)