2011-01-10 221 views
3

我有Android的一个问题,一个按钮。我编写了 按钮,就像它在开发者页面中,当单击时在文本视图中显示 文本,但是当我运行我的应用程序时,我必须按两次 我的按钮才能使它发生。我认为它可能有一些 与焦点做,但我不知道。按钮点击两次

而且,当我申请一个主题(见的风格和主题),我甚至有 按任意键两次,不仅上述的按钮,但 例子也是“是”或“否”的按钮问题退出 应用程序(通过对话)

我搜索了这个论坛,但没有找到 我一直在寻找的答案。希望有人可以给我提供一个想法 。

public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 
    root = (LinearLayout) findViewById(R.id.root);  

((Button) findViewById(R.id.btnZoeken)).setOnClickListener(
      new Button.OnClickListener(){ 
       @Override 
       public void onClick(View arg0) { 
        zoekOpPostcodes(txtZoeken.getText().toString()); 
       } 

       private void zoekOpPostcodes(String zoekterm){ 

               //more irrelevant code 
             txtResultaat.setText(txtRes); 
          } 

//more irrelevant code 
private void quit() { 
    // prepare the alert box 
    AlertDialog.Builder abQuit = new AlertDialog.Builder(this); 

    // set the message to display 
    abQuit.setMessage("Weet je zeker dat je wil afsluiten?"); 

    // set a positive/yes button and create a listener 
    abQuit.setPositiveButton("Ja", new DialogInterface.OnClickListener() { 

     // do something when the button is clicked 
     public void onClick(DialogInterface arg0, int arg1) { 
      Toast.makeText(getApplicationContext(), "Tot ziens!", Toast.LENGTH_LONG).show(); 
      iRegionForAndroid.this.finish(); 
     } 
    }); 

    // set a negative/no button and create a listener 
    abQuit.setNegativeButton("Nee", new DialogInterface.OnClickListener() { 

     // do something when the button is clicked 
     public void onClick(DialogInterface arg0, int arg1) { 
      Toast.makeText(getApplicationContext(), "Afsluiten geannuleerd!", Toast.LENGTH_SHORT).show(); 
     } 
    }); 

    // display box 
    abQuit.show(); 

}

如果你需要的任何更多的我的代码,“问你应接受” :) 似乎是用“代码”部分不对劲,它doensn't包含所有的代码,但它的部分“代码”部分

+2

我们需要的代码。我认为你应该假设我们需要并给予我们最初而不是等待。 – 2011-01-10 18:01:15

+0

这是发生在模拟器还是实际的机器上?是的,代码会很好! – 2011-01-10 18:38:47

回答

17

下它专注正在与您可能是正确的。

您可能有android:focusableInTouchMode =“true”,它需要为false。第一次点击关注该项目,第二次点击调用该侦听器。