3

当我单击按钮时,我没有激活转到另一个 android 页面的意图。

我的java代码

public class CharSheets extends Activity implements OnClickListener{

    Button Descrip, Atributes, Weapons, Skills, ACItems, Gear,
        Feats, SpecialAbilities, Spells;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.charsheets);
        setids();
    }

    private void setids() {
        // TODO Auto-generated method stub
        Descrip = (Button)findViewById(R.id.bCharDescrip);
    }

    @Override
    public void onClick(View arg0) {
        // TODO Auto-generated method stub
        switch(arg0.getId()) {
        case R.id.bCharDescrip:
            Intent i = new Intent(CharSheets.this, CharDescrip.class);
            startActivity(i);
            break;
        case R.id.bCharAtributes:
            Intent i1 = new Intent(CharSheets.this, CharAtributes.class);
            startActivity(i1);
            break;
        }
    }
}

XML 盛会

<activity
    android:name=".CharAtributes"
    android:label="@string/app_name" >
    <intent-filter>
        <action android:name="android.intent.action.CHARSATRIBUTES" />

        <category android:name="android.intent.category.DEFAULT" />
    </intent-filter>
</activity>
<activity
    android:name=".CharDescrip"
    android:label="@string/app_name" >
    <intent-filter>
        <action android:name="android.intent.action.CHARDESCRIP" />

        <category android:name="android.intent.category.DEFAULT" />
    </intent-filter>
</activity>

我不确定是什么导致了这个问题,但我尝试了其他解决方案,但都没有奏效。我现在这样做的方式我以前用过,而且效果很好。

4

3 回答 3

3

您尚未将 应用于OnClickListener您的按钮。

private void setids() {
    // TODO Auto-generated method stub
    Descrip = (Button)findViewById(R.id.bCharDescrip);
    Descrip.setOnClickListener(this); // <--- This line is required.
}

作为旁注,通常的做法是命名以小写字母开头的变量,例如描述

于 2013-04-12T14:28:20.070 回答
3

你还没有onClickListener()为你设置Button

private void setids() {
    // TODO Auto-generated method stub
    Descrip = (Button)findViewById(R.id.bCharDescrip);
    Descrip.setOnClickListener(this);   // add this line
}

现在在Buttons此处添加您的另一个并以相同的方式使用setOnClickListener()for each。

于 2013-04-12T14:28:30.387 回答
2

您应该在 Button 上设置 OnClickListener 。. .

private void setids() {
        // TODO Auto-generated method stub
        Descrip = (Button)findViewById(R.id.bCharDescrip);
        Descrip.setOnClickListener(this);
    }
于 2013-04-12T14:31:01.820 回答