public abstract void onItemClick (AdapterView<?> parent, View view, int position, long id)
Since: API Level 1
Callback method to be invoked when an item in this AdapterView has been clicked.
Implementers can call getItemAtPosition(position) if they need to access the data associated with the selected item.
Parameters :
parent The AdapterView where the click happened.
view The view within the AdapterView that was clicked (this
will be a view provided by the adapter)
position The position of the view in the adapter.
id The row id of the item that was clicked.
public TabMenu(Context context,OnItemClickListener titleClick,OnItemClickListener bodyClick,
MenuTitleAdapter titleAdapter,int colorBgTabMenu,int aniTabMenu){
super(context);
mLayout = new LinearLayout(context);
mLayout.setOrientation(LinearLayout.VERTICAL);
//标题选项栏
gvTitle = new GridView(context);
gvTitle.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
gvTitle.setNumColumns(titleAdapter.getCount());
gvTitle.setStretchMode(GridView.STRETCH_COLUMN_WIDTH);
gvTitle.setVerticalSpacing(1); //纵向间距
gvTitle.setHorizontalSpacing(1); //横向间距
gvTitle.setGravity(Gravity.CENTER);
gvTitle.setOnItemClickListener(titleClick);
gvTitle.setAdapter(titleAdapter);
gvTitle.setSelector(new ColorDrawable(Color.TRANSPARENT));//选中的时候为透明色
this.titleAdapter=titleAdapter;
//子选项栏
gvBody = new GridView(context);
gvBody.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));
gvBody.setSelector(new ColorDrawable(Color.TRANSPARENT));//选中的时候为透明色
gvBody.setNumColumns(4);
gvBody.setStretchMode(GridView.STRETCH_COLUMN_WIDTH);
gvBody.setVerticalSpacing(10);
gvBody.setHorizontalSpacing(10);
gvBody.setPadding(10, 10, 10, 10);
gvBody.setGravity(Gravity.CENTER);
gvBody.setOnItemClickListener(bodyClick);
mLayout.addView(gvTitle);
mLayout.addView(gvBody);
//设置默认项
this.setContentView(mLayout);
this.setWidth(LayoutParams.FILL_PARENT);
this.setHeight(LayoutParams.WRAP_CONTENT);
this.setBackgroundDrawable(new ColorDrawable(colorBgTabMenu));// 设置TabMenu菜单背景
this.setAnimationStyle(aniTabMenu);
this.setFocusable(true);// menu菜单获得焦点 如果没有获得焦点menu菜单中的控件事件无法响应
}
private LinearLayout makeMenyBody(int position)
{
LinearLayout result=new LinearLayout(this.mContext);
result.setOrientation(LinearLayout.VERTICAL);
result.setGravity(Gravity.CENTER_HORIZONTAL|Gravity.CENTER_VERTICAL);
result.setPadding(10, 10, 10, 10);
TextView text = new TextView(this.mContext);
text.setText(texts[position]);
text.setTextSize(fontSize);
text.setTextColor(fontColor);
text.setGravity(Gravity.CENTER);
text.setPadding(5, 5, 5, 5);
ImageView img=new ImageView(this.mContext);
img.setBackgroundResource(resID[position]);
result.addView(img,new LinearLayout.LayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT)));
result.addView(text);
return result;
}
//再熟悉不过了,这可以作为一个Gallery的Adapter
public class ImageAdapter extends BaseAdapter {
private Context mContext;
public ImageAdapter(Context c) {
mContext = c;
}
public int getCount() {
return mThumbIds.length;
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
ImageView i = new ImageView(mContext);
i.setImageResource(mThumbIds[position]);
i.setAdjustViewBounds(true);
i.setLayoutParams(new Gallery.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
i.setBackgroundResource(R.drawable.picture_frame);
return i;
}
}
private Integer[] mThumbIds = {
R.drawable.sample_thumb_0, R.drawable.sample_thumb_1,
R.drawable.sample_thumb_2, R.drawable.sample_thumb_3,
R.drawable.sample_thumb_4, R.drawable.sample_thumb_5,
R.drawable.sample_thumb_6, R.drawable.sample_thumb_7};
//makeView是ImageSwitcher回调的一个方法,当你设置了//mSwitcher.setFactory(this)之后,将掉用两次makeView
public View makeView() {
ImageView i = new ImageView(this);
i.setBackgroundColor(0xFF000000);
i.setScaleType(ImageView.ScaleType.FIT_CENTER);
i.setLayoutParams(new ImageSwitcher.LayoutParams(LayoutParams.MATCH_PARENT,
LayoutParams.MATCH_PARENT));
return i;
}
<TextView android:id="@+id/label" style="?android:attr/textAppearanceMediumInverse" //什么意思?
android:layout_width="match_parent" android:layout_height="wrap_content"
android:layout_weight="0"
android:padding="4dip"
android:singleLine="true"
android:color="?android:attr/textColorPrimaryInverse" //还有这个
android:background="#888" />
// Tell the media scanner about the new file so that it is
// immediately available to the user.手动扫描特定文件
MediaScannerConnection.scanFile(this,
new String[] { file.toString() }, null,
new MediaScannerConnection.OnScanCompletedListener() {
public void onScanCompleted(String path, Uri uri) {
Log.i("ExternalStorage", "Scanned " + path + ":");
Log.i("ExternalStorage", "-> uri=" + uri);
}
});
分享到:
相关推荐
ensp错误代码2 内容概要:本文详细介绍了在使用华为企业网络仿真平台(eNSP)时遇到错误代码 2 的多种原因及其解决方法。首先探讨了设备启动失败的原因,包括系统资源不足、软件冲突和设备配置错误,并提供了具体的...
eNSP模拟器中错误代码2与系统资源限制的关系及解决方案
国嵌必修实验代码2-2-3国嵌必修实验代码2-2-3国嵌必修实验代码2-2-3国嵌必修实验代码2-2-3国嵌必修实验代码2-2-3国嵌必修实验代码2-2-3国嵌必修实验代码2-2-3国嵌必修实验代码2-2-3国嵌必修实验代码2-2-3国嵌必修...
全屏轮番代码 2.第二款(宽1920高500)代码全屏轮番代码 2.第二款(宽1920高500)代码全屏轮番代码 2.第二款(宽1920高500)代码全屏轮番代码 2.第二款(宽1920高500)代码全屏轮番代码 2.第二款(宽1920高500)代码全屏轮番...
国嵌必修实验代码2-3-4国嵌必修实验代码2-3-4国嵌必修实验代码2-3-4国嵌必修实验代码2-3-4国嵌必修实验代码2-3-4国嵌必修实验代码2-3-4国嵌必修实验代码2-3-4国嵌必修实验代码2-3-4国嵌必修实验代码2-3-4国嵌必修...
国嵌必修实验代码2-3-1国嵌必修实验代码2-3-1国嵌必修实验代码2-3-1国嵌必修实验代码2-3-1国嵌必修实验代码2-3-1国嵌必修实验代码2-3-1国嵌必修实验代码2-3-1国嵌必修实验代码2-3-1国嵌必修实验代码2-3-1国嵌必修...
国嵌必修实验代码2-3-3国嵌必修实验代码2-3-3国嵌必修实验代码2-3-3国嵌必修实验代码2-3-3国嵌必修实验代码2-3-3国嵌必修实验代码2-3-3国嵌必修实验代码2-3-3国嵌必修实验代码2-3-3国嵌必修实验代码2-3-3国嵌必修...
国嵌必修实验代码2-6-1国嵌必修实验代码2-6-1国嵌必修实验代码2-6-1国嵌必修实验代码2-6-1国嵌必修实验代码2-6-1国嵌必修实验代码2-6-1国嵌必修实验代码2-6-1国嵌必修实验代码2-6-1国嵌必修实验代码2-6-1国嵌必修...
国嵌必修实验代码2-6-3国嵌必修实验代码2-6-3国嵌必修实验代码2-6-3国嵌必修实验代码2-6-3国嵌必修实验代码2-6-3国嵌必修实验代码2-6-3国嵌必修实验代码2-6-3国嵌必修实验代码2-6-3国嵌必修实验代码2-6-3国嵌必修...
python爬虫源代码2
数字图像处理代码2-2
cocos2dx游戏开发之旅源代码2 方便大家学习
代码2.cpp
ajax on java 源代码2
vuejs资料和代码2.zip
ensp错误代码2
南邮智能控制作业代码2
VC++深入详解源代码2
VC++深入详解源代码2