我有这个items.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal" android:layout_width="match_parent"
android:focusable="true"
android:clickable="true"
android:background="?android:attr/selectableItemBackground"
android:layout_height="wrap_content">
<ImageView
android:layout_width="match_parent"
android:layout_height="60dp"
android:id="@+id/colorPreview" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:textAppearance="@android:style/TextAppearance.Large"
android:textColor="@android:color/white"
android:id="@+id/colorName" />
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
当我单独使用它时,selectableItemBackground在我单击视图时动画.但是当我将它用于RecyclerView中的项目时,对点击的影响不再发生.我怎样才能解决这个问题?
PS:这是RecyclerView上的监听器,如果它是相关的:
public ColorListOnItemTouchListener(Context context, OnItemClickListener clickListener) {
mClickListener = clickListener;
mGestureDetector = new GestureDetector(context, new GestureDetector.SimpleOnGestureListener() {
@Override
public boolean onDown(MotionEvent e) {
return true;
}
@Override
public void onLongPress(MotionEvent e) {
if(childView != null && mClickListener != null) {
mClickListener.onItemLongPress(childView, index);
}
}
@Override
public boolean onSingleTapUp(MotionEvent e) {
if(childView != null …Run Code Online (Sandbox Code Playgroud) 我需要将一个变量从AppDelegate传递给另一个我创建的类来保存项目的全局变量,我无法找到使其工作的方法.
这是AppDelegate中的代码:
func application(application: UIApplication!, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData!) {
println("Device's token is: \(deviceToken)")
//Global Variables Class Instance
let globals:Globals = Globals()
globals.setDeviceToken("test1") //method1 not working
globals.deviceToken = "test2" //method2 not working
}
Run Code Online (Sandbox Code Playgroud)
这是我的Globals类:
public class Globals {
var deviceToken = String()
init() {
//nothing
}
func setDeviceToken(s:String){
deviceToken = s
}
func getDeviceToken() -> String {
return deviceToken
}
}
Run Code Online (Sandbox Code Playgroud)
如果我尝试从项目的其他文件打印值,我将无法获得任何内容,只是一个空字符串.
class ViewController: UIViewController {
//Global Variables Class Instance
let globals:Globals = Globals()
override func viewDidLoad() {
println(globals.getDeviceToken()) //return empty …Run Code Online (Sandbox Code Playgroud)