Skip to content

Commit

Permalink
点击事件
Browse files Browse the repository at this point in the history
  • Loading branch information
sunfusheng committed Oct 8, 2016
1 parent 43eae9c commit c9d41fa
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ 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;
}

// 将资源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);
}

// 加载网络图片
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ public class ModelUtil {
// 广告数据
public static List<String> getAdData() {
List<String> 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;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -48,12 +49,13 @@ private void dealWithTheView(final List<ChannelEntity> 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());
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -35,8 +37,15 @@ protected void getView(List<OperationEntity> list, ListView listView) {
}

private void dealWithTheView(List<OperationEntity> 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());
}
});
}

}
1 change: 0 additions & 1 deletion app/src/main/res/layout/item_operation.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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">

<ImageView
Expand Down

0 comments on commit c9d41fa

Please sign in to comment.