English 中文(简体)
以纽特人所为
原标题:Load bundle based on what button pressed
  • 时间:2011-11-22 21:08:47
  •  标签:
  • java
  • android

我有一个班子有两个县,这些县将你送至同一个班级,但取决于所敦促的纽顿会显示不同的文字/影印/布顿。

So right now when a button is pressed it send you to the next class and adds some intets, like this:

button1.setOnClickListener(new View.OnClickListener() {  
            @Override  
              public void onClick(View view) {  
                Bundle bundle1 = new Bundle();  
                bundle1.putInt("top", R.drawable.1);  
                bundle1.putInt("mid", R.drawable.2);  
                bundle1.putInt("bot", R.drawable.3);  
                Intent intet1 = new Intent(curclass.this, nextclass.class);  
                intent1.putExtras(bundle1);  
                startActivity(intent1);

在接下来的班级,我每个县都有一个dle子,但我是活着的。

So how do I make the "if" thing? I have tried but I don t know what to put after "if". Something like

"if (button1 = pressed)  
(do this)  
else if (button2 = pressed)  
(do this)"

提前感谢!

如果我像一个多面解释,或许是因为我是一派,我刚刚开始方案。

EDIT:问题在于,我在第二次活动中有两个 b子:

Bundle asd = getIntent().getExtras();
    int asdasd = asd.getInt("top");
    im1 = (ImageView) findViewById(R.id.imagetop);
    im1.setImageResource(newimage);
    bu1 = (Button) findViewById(R.id.buttontop);
    bu1.setText("blahblah");

而我有中间和下层,然后是第二大dle,从纽顿向内人讲述什么图像/文字,问题在于,即使我新闻纽特,第二大 b子仍然uff着。 我怀疑,这是由 b子与告诉他们要做的事情相伴造成的。

I hope that clears it up :)

最佳回答

得到......方法的好东西使你可以确定违约。

Put this wherever you want, maybe you have a class for constants, or where you better fill it to stay. Since it is static, you can access it wherever you want. Create "global variables" the uniquely identify your buttons.

public static final int no_button = -1;
public static final int button_1 = 1;
public static final int button_2 = 2; //you are not forced to use -1, 1, 2, just use different numbers

在塔顿受到压力之后,你第一次开展活动。

button1.setOnClickListener(new View.OnClickListener() {  
            @Override  
              public void onClick(View view) {  
                Bundle bundle1 = new Bundle(); 
                bundle1.putInt("button id", button_1); 
                bundle1.putInt("top", R.drawable.1);  
                bundle1.putInt("mid", R.drawable.2);  
                bundle1.putInt("bot", R.drawable.3);  
                Intent intet1 = new Intent(curclass.this, nextclass.class);  
                intent1.putExtras(bundle1);  
                startActivity(intent1);

or

button2.setOnClickListener(new View.OnClickListener() {  
            @Override  
              public void onClick(View view) {  
                Bundle bundle2 = new Bundle();  
                bundle2.putInt("button id", button_2);
                bundle2.putInt("top", R.drawable.1);  
                bundle2.putInt("mid", R.drawable.2);  
                bundle2.putInt("bot", R.drawable.3);  
                Intent intet2 = new Intent(curclass.this, nextclass.class);  
                intent2.putExtras(bundle1);  
                startActivity(intent1);

然后是第二次活动。

Bundle asd = getIntent().getExtras();
switch(asd.getInt("button id", -1)){
case button_1:
    [put here the code you want to execute if button1 was pressed]
case button_2:
     [put here the code you want to execute if button2 was pressed]
case no_button:
     [put here the code you want to execute if something else happened]
}
问题回答

暂无回答




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签