我有一个活动类,它正在实现onClickListener Interface
我无法找出下一步该做什么。我的目标是有一个覆盖的视图方法onClick(View v),它将在单击UP按钮时将标志从1增加到5不同的uri(比如5个uri),并在单击DOWN按钮时将从uri-5减少到uri-1。它将取决于在任何情况下每个按钮的位置。请帮我找个线索。
我试过如下:-
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) {
}发布于 2013-02-12 05:06:30
试试这个,使之成为一个静态变量
static int count=0;向上
if(count=<5)
Log.e("Output" ,"uri-"+count++);倒下去
if(count>0)
Log.e("Output" ,"uri-"+count--);发布于 2013-02-12 05:14:09
你可以试试这个:-
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--;
}
}发布于 2013-02-12 05:15:06
你可以这样做:
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);
}
}https://stackoverflow.com/questions/14825650
复制相似问题