我正在制作一个游戏应用程序,我需要使用ondraglistener进行拖放,这是我在实现onDraglistener的类上所做的.
@Override
public boolean onDrag(View v, DragEvent event) {
switch (event.getAction()) {
case DragEvent.ACTION_DRAG_STARTED:
Log.v("here","drag started");
//no action necessary
break;
case DragEvent.ACTION_DRAG_ENTERED:
//no action necessary
Log.v("here","drag enteres");
break;
case DragEvent.ACTION_DRAG_LOCATION:
int mCurX = (int) event.getX();
int mCurY = (int) event.getY();
Log.v("Cur(X, Y) : " ,"here ::" + mCurX + ", " + mCurY );
break;
case DragEvent.ACTION_DRAG_EXITED:
//no action necessary
Log.v("here","drag exits");
break;
case DragEvent.ACTION_DROP:
.................do what ever when dropped...
}
Run Code Online (Sandbox Code Playgroud)
这里我正在做一个关于拖放视图的touchlistener:
public boolean onTouch(View view, MotionEvent motionEvent) {
if …
Run Code Online (Sandbox Code Playgroud) 我是一个学习如何为USB设备编写Linux设备驱动程序的新手.我在编译代码时遇到错误.注释行中存在问题.我正在为USB驱动器制作模块,如下所示:
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/usb.h>
static int pen_probe(struct usb_interface *intf,const struct usb_device_id *id)
{
printk(KERN_ALERT"\nthe probe is successful");
return 0;
}
static void pen_disconnect(struct usb_interface *intf)
{
printk(KERN_ALERT"pen drive removed");
}
const struct usb_device_id pen_table = {
USB_DEVICE(0x058f,0x6387),
};
MODULE_DEVICE_TABLE(usb,pen_table);
static struct usb_driver pen_driver = {
.name = "pen_driver",
.id_table = pen_table, // error coming at this line
.probe = pen_probe,
.disconnect = pen_disconnect,
};
static int __init pen_init(void)
{
int ret;
ret = usb_register(&pen_driver);
printk(KERN_ALERT"THE RET::%d\n",ret);
return …
Run Code Online (Sandbox Code Playgroud) 我正在制作一个模块,其中每当我触摸一个图像时我有两个图像它应该在拖动时跟随手指或鼠标(在模拟器中)并且如果它越过另一个图像然后它们改变它们在第一次触摸时第一个图像的位置(ACTION_DOWN).我写了下面的代码,其中视图正在移动,但当我拖动第一个图像时,第二个图像也被拖动.进一步想知道如何改变立场.
.XML
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/vg"
>
<ImageView
android:id="@+id/img"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<ImageView
android:id="@+id/img1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
活动文件
public class MainActivity extends Activity {
private View selected_item = null;
private int offset_x = 0;
private int offset_y = 0;
Canvas can;
Paint paint;
ImageView img;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ViewGroup vg = (ViewGroup)findViewById(R.id.vg);
vg.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
switch(event.getActionMasked())
{
case MotionEvent.ACTION_MOVE:
if(selected_item == img) {
int …
Run Code Online (Sandbox Code Playgroud) 我已经创建了一个模块,我想在其中运行无限循环,直到我不卸载模块.现在,如果我做rmmod,它会让我注意到模块仍然很忙并且经过一段时间内核崩溃.
while(1)
{
.......
}
Run Code Online (Sandbox Code Playgroud)
在我卸载模块之前,有什么技巧可以运行无限循环.
我是java和android的新手.我正在关注并从这里制作应用程序以进行拖放.
以下文件给出的错误无法解决.
import android.view.View.DragShadowBuilder;
import android.view.View.OnDragListener;
import android.view.DragEvent;
import android.content.ClipData;
Run Code Online (Sandbox Code Playgroud)
我知道这意味着主库中没有上面提到的类.我应该如何添加它们或者是否存在拖放的替代方式(请举例说明).
我编写了一个读取和写入/proc
文件的内核模块,它工作正常.现在我想使用它的权限,但是当我为下面显示的权限编写函数时,它给了我一个错误.目标是让每个人都能够读取文件,但只有root才能写入文件.
int my_permission(struct inode *inode, int op)
{
if(op == 4||(op == 2 && current->euid = 0)) //euid is not a member of task_struct
return 0;
return -EACCES;
}
const struct inode_operations my_iops = {
.permission = my_permission,
};
Run Code Online (Sandbox Code Playgroud)
我得到的错误是:
/home/karan/practice/procf/testproc1.c: In function ‘my_permission’:
/home/karan/practice/procf/testproc1.c:50:32: error: ‘struct task_struct’ has no member named ‘euid'
Run Code Online (Sandbox Code Playgroud)
我知道current
#defined是get_current()
.为什么会这样?是否有从中返回的结构的成员列表get_current()
?
我写了以下C程序.输出是32.这是为什么?
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#define max 10+2
int main(){
int i;
i = max * max;
printf("\n%d\n",i);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
(我正在学习C并且相对较新.)
我多次尝试过以下代码.
#include<linux/module.h>
#include<linux/kernel.h>
#include<linux/fs.h>
#include<linux/cdev.h>
#include<asm/uaccess.h>
#include<linux/semaphore.h>
MODULE_LICENSE("DUAL BSD/GPL");
static int dev_open(struct inode *,struct file *);
static int dev_release(struct inode *,struct file *);
ssize_t dev_read(struct file *,char *, size_t ,loff_t *);
ssize_t dev_write(struct file *,const char *,size_t ,loff_t *);
static int major;
int dev_major = 0;
int dev_minor = 0;
struct cdev *cdev;
struct device {
char array[100];
struct semaphore sem;
}chr_arr;
struct file_operations dev_ops = {
.owner = THIS_MODULE,
.read = dev_read,
.write = dev_write,
.open = dev_open,
.release …
Run Code Online (Sandbox Code Playgroud) 我正在编写以下c代码并收到错误:
#include<stdio.h>
#include<stdlib.h>
int main()
{
char *prot;
char addr[20];
FILE *fp;
int i = 0;
int tos,pld;
prot = (char *)malloc(sizeof(char *));
//addr = (char *)malloc(sizeof(char *));
printf("\n enter the protocol for test::");
scanf(" %s",prot);
printf("\n enter the addr::");
scanf(" %s",addr);
printf("\n enter the length of the payload::");
scanf(" %d",pld);
printf("\n enter the tos :: ");
scanf(" %d",tos);
Run Code Online (Sandbox Code Playgroud)
输入值时出现以下错误.有一个分段错误,任何人都可以告诉我为什么会出现这个段错误:
enter the protocol for test::we
enter the addr::qw
enter the length of the payload::12
Segmentation fault
Run Code Online (Sandbox Code Playgroud) 我想了解以下代码:
#include<stdio.h>
#include<stdlib.h>
#include<sys/io.h>
#define baseport 0x378
int main()
{
int b;
if(ioperm(baseport,3,1))
{
perror("ioperm");
exit(1);
}
outb(0,baseport);
usleep(1000000);
printf("\n the status: %x,\n",inb(baseport));
if (ioperm(baseport,3,0)) {perror("ioperm"); exit(1);}
exit(0);
}
Run Code Online (Sandbox Code Playgroud)
输出为0xff,十进制为255,无论是写入端口1还是端口0(使用outb()
).当我写0时,我无法理解为什么它是255.
我正在通过C来到以下示例,我从"C指针"这本书中无法理解.这是代码.
以下声明存在于一个源文件中:
int a[10];
int *b = a;
Run Code Online (Sandbox Code Playgroud)
但是在不同的源文件中,这段代码是:
extern int *a;
extern int b[];
int x, y;
...
x = a[3];
y = b[3];
Run Code Online (Sandbox Code Playgroud)
有人可以解释执行两个赋值语句时会发生什么吗?(假设整数和指针都占用四个字节.)
当我尝试运行代码时,它给了我分段错误x
,当我将它注释掉并打印y的值时,它给了我0.概念是指针和数组之间的一些区别.