Android TV 节目列表 选择 (3级) 第3级是动态的加载。
效果图如下:
附件:(第一次发不知道怎么附件加上)
先把代码贴上:
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
package com.smartTv.directTv;
import java.util.ArrayList;
import java.util.List;
import com.smartTv.MediaPlayer.TVMediaPlayer;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnFocusChangeListener;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
public class DirectTVActivity extends Activity {
/** Called when the activity is first created. */
private String TAG="DirectTVActivity";
private TVMediaPlayer TvMediaPlayer=null;
/**
* Listview
*/
private ListView TvTypeList;
private ListView TvNameList;
private ListView TvNameMessList;
/**
* 适配器
*/
private ArrayAdapter<String> TvTypeListAdapter;
private ArrayAdapter<String> TvNameListAdapter;
/**
* 列表上要显示的数据
*/
private List<String> data;
private List<String> data2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.dircettv_main);
TvMediaPlayer=(TVMediaPlayer)findViewById(R.id.mediaPlayer);
/**==========TvTypeList=============================**/
TvTypeList = (ListView) findViewById(R.id.TvChanelList);
data = getData(10);
TvTypeListAdapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, data);
TvTypeList.setAdapter(TvTypeListAdapter);
TextView tv = (TextView) findViewById(R.id.empty_view);
TvTypeList.requestFocus();
TvTypeList.setItemsCanFocus(true);
/**==========TvNameList=============================**/
TvNameList = (ListView) findViewById(R.id.TvNameList);
data2 = getData2(21);
TvNameListAdapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1, data2);
TvNameList.setAdapter(TvNameListAdapter);
TvNameList.setItemsCanFocus(true);
/**==========TvNameMessList=============================**/
TvNameMessList = (ListView) findViewById(R.id.TvNameMessList);
TvNameMessList.setAdapter(TvNameListAdapter);
TvNameMessList.setFocusable(false);
TvNameMessList.setItemsCanFocus(false);
/*+++++++++++++++++++++++当类型被浏览监听处理+++++++++++++++++++++++*/
TvTypeList.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
// TODO Auto-generated method stub
Toast.makeText(DirectTVActivity.this, "++TvTypeList Selected is:"+arg2,Toast.LENGTH_SHORT).show();
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
Toast.makeText(DirectTVActivity.this, "++TvTypeList Selected is:"+arg0,Toast.LENGTH_SHORT).show();
}
});
/*+++++++++++++++++++++++当名字被浏览监听处理+++++++++++++++++++++++*/
TvNameList.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
// TODO Auto-generated method stub
Toast.makeText(DirectTVActivity.this, "++TvNameList Selected is:"+arg2,Toast.LENGTH_SHORT).show();
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
Toast.makeText(DirectTVActivity.this, "++TvNameList Selected is:"+arg0,Toast.LENGTH_SHORT).show();
}
});
/**====================用户浏览电视类型=========================*/
TvTypeList.setOnFocusChangeListener(new OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
// TODO Auto-generated method stub
if(hasFocus){
TvNameMessList.setVisibility(View.INVISIBLE);
Log.e(TAG,"has focus================");
Toast.makeText(DirectTVActivity.this, "++TvTypeList++====has focus",Toast.LENGTH_SHORT).show();
findViewById(R.id.TVname_mess_layout).setAlpha(0);
}else{
TvNameMessList.setVisibility(View.VISIBLE);
Toast.makeText(DirectTVActivity.this, "++TvNameList++====No focus",Toast.LENGTH_SHORT).show();
findViewById(R.id.TVname`代码块`_mess_layout).setAlpha(200);
}
}
});
/**====================用户确认选择选台=========================*/
TvNameList.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
// TODO Auto-generated method stub
Log.d(TAG,arg0+"======"+arg1+""+arg2+ ""+arg3);
TvNameMessList.setVisibility(View.VISIBLE);
Toast.makeText(DirectTVActivity.this, "++TvNameList Selected is: ++"+arg2,Toast.LENGTH_SHORT).show();
}
});
//TvTypeList.setOnItemClickListener(new OnItemClickListener() {
//@Override
//public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
//long arg3) {
//// TODO Auto-generated method stub
//Log.d(TAG,arg0+"======"+arg1+""+arg2+ ""+arg3);
//TvNameMessList.setVisibility(View.INVISIBLE);
//Toast.makeText(DirectTVActivity.this, "++TvTypeList++===="+arg2,Toast.LENGTH_SHORT).show();
//
//}
//});
}
/**
*
*
*/
public List<String> getData(int i) {
List<String> data = new ArrayList<String>();
for (int j = 0; j < i; j++) {
data.add("This is CNTV:" + (j + 1));
}
return data;
}
/**
*
*
*/
public List<String> getData2(int i) {
List<String> data = new ArrayList<String>();
for (int j = 0; j < i; j++) {
data.add("This is test data:" + (j + 1));
}
return data;
}
}// DirectTVActivity is over here!
布局文件:
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
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:start="http://schemas.android.com/apk/res/com.smartTv.directTv"
android:id="@+id/rl"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<com.smartTv.MediaPlayer.TVMediaPlayer
android:id="@+id/mediaPlayer"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:focusable="false"
android:gravity="bottom"/>
<!-- SelectLayout 包含了LeftLayout和RightLayout-->
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="50dp"
android:id="@+id/SelectLayout"
android:orientation="horizontal"
android:gravity="center"
>
<!-- LeftLayout 包含可以选择的2级列表结构TVchanel & TVname-->
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="3"
android:paddingLeft="10dp"
android:id="@+id/LeftLayout"
android:focusable="false"
>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/TVchanel"
android:background="@drawable/white_border"
android:layout_weight="3">
<TextView
android:id="@+id/hello_tv"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="27sp"
android:gravity="center"
android:background="#aa003300"
android:text="MuMu_Player" />
<ListView
android:id="@+id/TvChanelList"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#aa336699"
android:focusable="true"
android:divider=""
android:layout_below="@id/hello_tv" >
</ListView>
<TextView
android:id="@+id/empty_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/TvChanelList"
android:gravity="center_vertical|center_horizontal"
android:text="没有更多的选择" />
</RelativeLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="2"
android:paddingLeft="15dp"
android:id="@+id/TVname"
android:background="#aa336699"
>
<ListView
android:id="@+id/TvNameList"
android:background="@drawable/white_border"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
</ListView>
</RelativeLayout>
</LinearLayout>
<!-- RightLayout 包含可以选择的2级列表结构TVchanel & TVname-->
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="2"
android:id="@+id/RightLayout"
>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="2"
android:paddingLeft="15dp"
android:id="@+id/TVname_mess_layout"
android:background="#AA66CC66"
>
<ListView
android:id="@+id/TvNameMessList"
android:background="@drawable/white_border"
android:focusable="false"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
</ListView>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="20dp"
android:id="@+id/TVAdd"
android:layout_weight="2"
>
<TextView
android:id="@+id/h_6"
android:textColor="#FFaa0033"
android:textSize="25sp"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="带你走入随心所欲的影音世界">
</TextView>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</FrameLayout>