From c9d41fa18725df9b11a1f614cb6d258c8d1b9f39 Mon Sep 17 00:00:00 2001 From: sfsheng0322 Date: Sat, 8 Oct 2016 11:00:54 +0800 Subject: [PATCH] =?UTF-8?q?=E7=82=B9=E5=87=BB=E4=BA=8B=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../manager/ImageManager.java | 4 +-- .../StickyHeaderListView/util/ModelUtil.java | 7 +++-- .../StickyHeaderListView/util/ToastTip.java | 30 +++++++++++++++++++ .../view/HeaderChannelViewView.java | 4 ++- .../view/HeaderOperationViewView.java | 11 ++++++- app/src/main/res/layout/item_operation.xml | 1 - 6 files changed, 49 insertions(+), 8 deletions(-) create mode 100644 app/src/main/java/com/sunfusheng/StickyHeaderListView/util/ToastTip.java diff --git a/app/src/main/java/com/sunfusheng/StickyHeaderListView/manager/ImageManager.java b/app/src/main/java/com/sunfusheng/StickyHeaderListView/manager/ImageManager.java index 4b31e3f..abd1e93 100644 --- a/app/src/main/java/com/sunfusheng/StickyHeaderListView/manager/ImageManager.java +++ b/app/src/main/java/com/sunfusheng/StickyHeaderListView/manager/ImageManager.java @@ -15,7 +15,7 @@ public class ImageManager { private Context mContext; public static final String ANDROID_RESOURCE = "android.resource://"; - public static final String FOREWARD_SLASH = "/"; + public static final String SEPARATOR = "/"; public ImageManager(Context context) { this.mContext = context; @@ -23,7 +23,7 @@ public ImageManager(Context context) { // 将资源ID转为Uri public Uri resourceIdToUri(int resourceId) { - return Uri.parse(ANDROID_RESOURCE + mContext.getPackageName() + FOREWARD_SLASH + resourceId); + return Uri.parse(ANDROID_RESOURCE + mContext.getPackageName() + SEPARATOR + resourceId); } // 加载网络图片 diff --git a/app/src/main/java/com/sunfusheng/StickyHeaderListView/util/ModelUtil.java b/app/src/main/java/com/sunfusheng/StickyHeaderListView/util/ModelUtil.java index 01a5f6b..6bcb2a2 100644 --- a/app/src/main/java/com/sunfusheng/StickyHeaderListView/util/ModelUtil.java +++ b/app/src/main/java/com/sunfusheng/StickyHeaderListView/util/ModelUtil.java @@ -27,9 +27,10 @@ public class ModelUtil { // 广告数据 public static List getAdData() { List adList = new ArrayList<>(); - adList.add("http://img0.imgtn.bdimg.com/it/u=1270781761,1881354959&fm=21&gp=0.jpg"); - adList.add("http://img0.imgtn.bdimg.com/it/u=2138116966,3662367390&fm=21&gp=0.jpg"); - adList.add("http://img0.imgtn.bdimg.com/it/u=1296117362,655885600&fm=21&gp=0.jpg"); + adList.add("http://img2.imgtn.bdimg.com/it/u=2850936076,2080165544&fm=206&gp=0.jpg"); + adList.add("http://img3.imgtn.bdimg.com/it/u=524208507,12616758&fm=206&gp=0.jpg"); + adList.add("http://img3.imgtn.bdimg.com/it/u=698582197,4250615262&fm=206&gp=0.jpg"); + adList.add("http://img5.imgtn.bdimg.com/it/u=1467751238,3257336851&fm=11&gp=0.jpg"); return adList; } diff --git a/app/src/main/java/com/sunfusheng/StickyHeaderListView/util/ToastTip.java b/app/src/main/java/com/sunfusheng/StickyHeaderListView/util/ToastTip.java new file mode 100644 index 0000000..39dd53d --- /dev/null +++ b/app/src/main/java/com/sunfusheng/StickyHeaderListView/util/ToastTip.java @@ -0,0 +1,30 @@ +package com.sunfusheng.StickyHeaderListView.util; + +import android.content.Context; +import android.text.TextUtils; +import android.widget.Toast; + +/** + * Created by sunfusheng on 15/8/7. + */ +public class ToastTip { + + private static Toast mToast; + + public static void show(Context context, String message) { + if (TextUtils.isEmpty(message)) return; + int duration; + if (message.length() > 10) { + duration = Toast.LENGTH_LONG; //如果字符串比较长,那么显示的时间也长一些。 + } else { + duration = Toast.LENGTH_SHORT; + } + if (mToast == null) { + mToast = Toast.makeText(context, message, duration); + } else { + mToast.setText(message); + mToast.setDuration(duration); + } + mToast.show(); + } +} diff --git a/app/src/main/java/com/sunfusheng/StickyHeaderListView/view/HeaderChannelViewView.java b/app/src/main/java/com/sunfusheng/StickyHeaderListView/view/HeaderChannelViewView.java index 8d79930..3ebd0a4 100644 --- a/app/src/main/java/com/sunfusheng/StickyHeaderListView/view/HeaderChannelViewView.java +++ b/app/src/main/java/com/sunfusheng/StickyHeaderListView/view/HeaderChannelViewView.java @@ -8,6 +8,7 @@ import com.sunfusheng.StickyHeaderListView.R; import com.sunfusheng.StickyHeaderListView.adapter.HeaderChannelAdapter; import com.sunfusheng.StickyHeaderListView.model.ChannelEntity; +import com.sunfusheng.StickyHeaderListView.util.ToastTip; import java.util.List; @@ -48,12 +49,13 @@ private void dealWithTheView(final List list) { gvChannel.setNumColumns(4); } - HeaderChannelAdapter adapter = new HeaderChannelAdapter(mContext, list); + final HeaderChannelAdapter adapter = new HeaderChannelAdapter(mContext, list); gvChannel.setAdapter(adapter); gvChannel.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView parent, View view, int position, long id) { + ToastTip.show(mContext, adapter.getItem(position).getTitle()); } }); } diff --git a/app/src/main/java/com/sunfusheng/StickyHeaderListView/view/HeaderOperationViewView.java b/app/src/main/java/com/sunfusheng/StickyHeaderListView/view/HeaderOperationViewView.java index bc705e2..d8517e5 100644 --- a/app/src/main/java/com/sunfusheng/StickyHeaderListView/view/HeaderOperationViewView.java +++ b/app/src/main/java/com/sunfusheng/StickyHeaderListView/view/HeaderOperationViewView.java @@ -2,11 +2,13 @@ import android.app.Activity; import android.view.View; +import android.widget.AdapterView; import android.widget.ListView; import com.sunfusheng.StickyHeaderListView.R; import com.sunfusheng.StickyHeaderListView.adapter.HeaderOperationAdapter; import com.sunfusheng.StickyHeaderListView.model.OperationEntity; +import com.sunfusheng.StickyHeaderListView.util.ToastTip; import java.util.List; @@ -35,8 +37,15 @@ protected void getView(List list, ListView listView) { } private void dealWithTheView(List list) { - HeaderOperationAdapter adapter = new HeaderOperationAdapter(mContext, list); + final HeaderOperationAdapter adapter = new HeaderOperationAdapter(mContext, list); gvOperation.setAdapter(adapter); + + gvOperation.setOnItemClickListener(new AdapterView.OnItemClickListener() { + @Override + public void onItemClick(AdapterView parent, View view, int position, long id) { + ToastTip.show(mContext, adapter.getItem(position).getTitle()); + } + }); } } diff --git a/app/src/main/res/layout/item_operation.xml b/app/src/main/res/layout/item_operation.xml index 3967557..b53c752 100644 --- a/app/src/main/res/layout/item_operation.xml +++ b/app/src/main/res/layout/item_operation.xml @@ -4,7 +4,6 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@drawable/ripple_item_clicked_with_mask" - android:clickable="true" android:minHeight="72.5dp">