按钮旁边和preV不工作 [英] Button next and prev not working

查看:139
本文介绍了按钮旁边和preV不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的线性布局

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/white"
android:gravity="center_horizontal"
android:orientation="vertical" >

<AutoCompleteTextView
    android:id="@+id/autoCompleteTextView1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_weight=".16"
    android:ems="10"
    android:text="Rule" >

    <requestFocus />
</AutoCompleteTextView>

<LinearLayout style="@style/verticallayout" >

    <LinearLayout style="@style/verticallayout" >

        <Button
            android:id="@+id/b1"
            style="@style/buttons"
            android:layout_weight=".16"
            android:text="Button 1" />
    </LinearLayout>

    <LinearLayout
        android:id="@+id/ll41"
        style="@style/horizontallayouthidden" >

        <TextView
            android:id="@+id/t1"
            style="@style/textview"
            android:layout_weight="0.5" />

        <TextView
            android:id="@+id/tt1"
            style="@style/textview"
            android:layout_weight="0.5" />
    </LinearLayout>
</LinearLayout>

<LinearLayout style="@style/verticallayout" >

    <LinearLayout style="@style/verticallayout" >

        <Button
            android:id="@+id/b2"
            style="@style/buttons"
            android:layout_weight=".16"
            android:text="Button 2" />
    </LinearLayout>

    <LinearLayout
        android:id="@+id/ll42"
        style="@style/horizontallayouthidden" >

        <TextView
            android:id="@+id/t2"
            style="@style/textview"
            android:layout_weight="0.5" />

        <TextView
            android:id="@+id/tt2"
            style="@style/textview"
            android:layout_weight="0.5" />
    </LinearLayout>
</LinearLayout>

<LinearLayout style="@style/verticallayout" >

    <LinearLayout style="@style/verticallayout" >

        <Button
            android:id="@+id/b3"
            style="@style/buttons"
            android:layout_weight=".16"
            android:text="Button 3" />
    </LinearLayout>

    <LinearLayout
        android:id="@+id/ll43"
        style="@style/horizontallayouthidden" >

        <TextView
            android:id="@+id/t3"
            style="@style/textview"
            android:layout_weight="0.5" />

        <TextView
            android:id="@+id/tt3"
            style="@style/textview"
            android:layout_weight="0.5" />
    </LinearLayout>
</LinearLayout>

<LinearLayout style="@style/verticallayout" >

    <LinearLayout style="@style/verticallayout" >

        <Button
            android:id="@+id/b4"
            style="@style/buttons"
            android:layout_weight=".16"
            android:text="Button 4" />
    </LinearLayout>

    <LinearLayout
        android:id="@+id/ll44"
        style="@style/horizontallayouthidden" >

        <TextView
            android:id="@+id/t4"
            style="@style/textview"
            android:layout_weight="0.5" />

        <TextView
            android:id="@+id/tt4"
            style="@style/textview"
            android:layout_weight="0.5" />
    </LinearLayout>
</LinearLayout>

<LinearLayout style="@style/verticallayout" >

    <LinearLayout style="@style/verticallayout" >

        <Button
            android:id="@+id/b5"
            style="@style/buttons"
            android:layout_weight=".16"
            android:text="Button 5" />
    </LinearLayout>

    <LinearLayout
        android:id="@+id/ll45"
        style="@style/horizontallayouthidden" >

        <TextView
            android:id="@+id/t5"
            style="@style/textview"
            android:layout_weight="0.5" />

        <TextView
            android:id="@+id/tt5"
            style="@style/textview"
            android:layout_weight="0.5" />
    </LinearLayout>
</LinearLayout>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >

    <Button
        android:id="@+id/left"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:layout_weight="0.5"
        android:enabled="false"
        android:text="Prev" />

    <Button
        android:id="@+id/right"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:layout_weight="0.5"
        android:text="Next" />
</LinearLayout>

这是我的Java类

public void onClick(View arg0) {
    String a=null;
    switch(arg0.getId()){
    case R.id.left:
        Toast.makeText(getApplicationContext(), "Prev"+ count, Toast.LENGTH_LONG).show();
                    if( count==0)
        prev.setEnabled(false);
        else{
             count--;
            Toast.makeText(getApplicationContext(), "Prev", Toast.LENGTH_LONG).show();
        }
        break;
    case R.id.right:
        Toast.makeText(getApplicationContext(), "Prev"+ count, Toast.LENGTH_LONG).show();
        if( count>((abc.size()/5)))
            next.setEnabled(false);
        else{
             count++;
            onClick(arg0);
        }
        break;
    case R.id.b1:
        t41.setText("t1");
            tt41.setText("tt1");
            a=abc.get(( count*0)+0)+"";
            bb1.setText(a);
        }
        break;
    case R.id.b2:
        t42.setText("t1");
            tt42.setText("tt1");
            a=abc.get(( count*0)+1)+"";
            bb2.setText(a);
        }
        break;
    case R.id.b3:
        t43.setText("t1");
            tt43.setText("tt1");
            a=abc.get(( count*0)+2)+"";
            bb3.setText(a);
        }
        break;
    case R.id.b4:
        t44.setText("t1");
            tt44.setText("tt1");
            a=abc.get((count*0)+3)+"";
            bb4.setText(a);
        }
        break;
    case R.id.b5:
            t45.setText("t1");
            tt45.setText("tt1");
            a=abc.get((count*0)+4)+"";
            bb5.setText(a);
        }
        break;

    }
}

现在我想改变按钮上的文字,当我点击下一个和$ P $光伏按钮dynamicaaly从一个列表,在列表中的ABC可用。伯爵是在其他类的静态变量。当我点击的价值并没有改变的按钮。任何人都可以请帮我出这个问题。

Now i want to change the text of button when i click the next and prev button dynamicaaly from a list that is available in list "abc". The count is STATIC variable in an other class. When i click the values are not changing in the button. Could anyone please help me out with this issue..

推荐答案

在你的XML使用code()方法

in your xml use this code wherever you want to call onClick() method

android:onClick="onClick"

为前:

<Button
    android:id="@+id/left"
    android:layout_width="wrap_content"
    android:layout_height="fill_parent"
    android:layout_weight="0.5"
    android:enabled="false"
    android:text="Prev"
    android:onClick="onClick" />

<Button
    android:id="@+id/right"
    android:layout_width="wrap_content"
    android:layout_height="fill_parent"
    android:layout_weight="0.5"
    android:text="Next"
    android:onClick="onClick" />`

这篇关于按钮旁边和preV不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆