2011-09-09 24 views
0

我的手指在我的牙齒與Java和Android。通常我使用Python編碼,它更容易和更容易!Android noobie與形式使url

的Java從來不讓我做任何事情,或者只在一個獨特的方法,我從來不知道:( 所以,唯一的代碼工作是複製粘貼,很難定製...

所以,我一個簡單的可編輯文本和一個按鈕,當我點擊它,我去一個URL。按鈕的作品:我可以打開我的webview。 但我想使editText的url,我不能:(

看出:

public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 

// Add Click listeners for all buttons 
    final EditText Login = (EditText) findViewById(R.id.entry); 
    View firstButton = findViewById(R.id.ok); 
    firstButton.setOnClickListener(this); 
} 

public void onClick(View v) { 

    switch(v.getId()){ 
     case R.id.ok: 
      Intent j = new Intent(this, Webscreen.class); 
      j.putExtra(com.tatai.froyo.Webscreen.URL, 
       "http://192.168.1.12/index2.php"); 
      startActivity(j); 
     break; 
    } 

所以,我怎麼能有登錄編輯文本,使url像http://192.168.1.12/index2.php?log=toto ...哪裏可能是與登錄編輯文本。

不可能在onclick上讀取全局變量,我迷路了! :(

我TRID上的onclick聽者: 字符串設置logdetail = Login.getText()的toString(); 但它不能看到登錄,它指出:未申報

+0

Login.getText()的toString()將讓你開始 – Rob

+0

我認爲對象是不是我的大腦......這些都是被其他代碼隔離太多,很難與對象進行通信。我更喜歡獨特的集中和線性代碼! – Defcode

回答

0

您的代碼,!試試這個,

public void onClick(View v) 
    {  
     switch(v.getId()) 
     {   
     case R.id.ok: 

      String logDetail = Login.getText().toString(); 

      Intent j = new Intent(this, Webscreen.class); 
      j.putExtra(com.tatai.froyo.Webscreen.URL,"http://192.168.1.12/index2.php?log="+logDetail); 
      startActivity(j);  
      break;  
      } 

編輯:。

EditText Login; 

public void onCreate(Bundle savedInstanceState) 
    {  
super.onCreate(savedInstanceState);  
setContentView(R.layout.main); 
// Add Click listeners for all buttons  

    Login = (EditText) findViewById(R.id.entry);  

View firstButton = findViewById(R.id.ok);  

    firstButton.setOnClickListener(this); 
    } 

    public void onClick(View v) 
    {  
     switch(v.getId()) 
     {   
     case R.id.ok: 

      String logDetail = Login.getText().toString(); 

      Intent j = new Intent(this, Webscreen.class); 

j.putExtra(com.tatai.froyo.Webscreen.URL,"http://192.168.1.12/index2.php?log="+logDetail); 
      startActivity(j);  
      break;  
      } 
+0

感謝您的幫助。我試過,但它說:登錄未申報 – Defcode

+0

看看我編輯的答案。你應該以這種方式聲明edittext,這樣你就不會出錯。 – user370305

+0

oh,editext登錄爲全局變量?我會嘗試的! – Defcode