2013-02-12 110 views
1

我有一个正在实施onClickListener接口递增/递减button.onclicklistener

的活动课,我无法找出下一步该怎么做。 我的目标是具有压倒一切的视图方法onClick(View v)将递增为1的标志上的UP按钮和减量棘爪5点不同的URI(比方说5个网址)从URI-5到URI-1上的点击DOWN按钮。它在任何情况下都取决于每个按钮的位置。 请帮助我一条线索。

我曾试图为如下: -

Button up = (Button) findViewById(R.id.button1); 
Button down = (Button) findViewById(R.id.button2); 

up.setOnClickListener(this); 
down.setOnClickListener(this); 

public void onClick(View v) { 
} 

回答

1

试试这个 使静态变量

static int count=0; 

高达

if(count=<5) 
    Log.e("Output" ,"uri-"+count++); 

在下降

if(count>0) 
Log.e("Output" ,"uri-"+count--); 
+0

如果你正面临的问题比发表您的完整代码 – 2013-02-12 05:08:48

+0

你解决你的问题 – 2013-02-12 05:11:05

0

你可以试试这个: -

static int flag = 0; // Global variable in class 

/** Code to use in onCreate() **/ 
Button up = (Button) findViewById(R.id.button1); 
Button down = (Button) findViewById(R.id.button2);  
up.setOnClickListener(this); 
down.setOnClickListener(this); 

/** Override method in class **/ 
public void onClick(View v) 
{ 
    if (v == up) 
    { 
    if (flag < 5) 
     flag++; 
    } 
    else if (v == down) 
    { 
    if (flag > 0) 
     flag--; 
    } 
} 
0

你可以做这样的事情:

int currentURLIndex = 0; 
int urlCount = 5; 

public void onClick(View v) { 
    if(v == up){ 
    currentURLIndex = Math.min(++currentURLIndex, urlCount); 
    } else if if(v == down){ 
    currentURLIndex = Math.max(--currentURLIndex, 0); 
    } 
} 
+0

我正在观察@ iTech我今天非常活跃回答每个问题在stackoverflow良好的工作保持它 – 2013-02-12 05:17:10

+0

:)这是我的黄金时间SO – iTech 2013-02-12 05:23:34