0

嗨,我完全不熟悉android編程,並通過平板電腦使用AIDE。Android的基本微調問題AIDE

我想創建一個非常基本的程序與一個微調框給出的選擇Ive通過TextView或System.Out.printIn進行輸出。 (也許下一步從Hello世界 - 如果你願意)

由於某些原因,我無法理解,編譯器拒絕識別OnClickListener,並給出錯誤消息'Android.Widget.Spinner中的未知方法OnClickListener' 當我已經在進口檢查了這個。

As a matter of interest I have changed the name of the Spinner and the error seems to dissapear, the problem then is the Spinner name. I have tried several variations on this, and have came to the conclusion that the best option for me is to create a variable just after Main Acivity, and before the layout is declared. 

我還禁用了覆蓋之一,爲了解決我的問題

有沒有人有一個想法的問題可能是什麼?

package com.BGilbert.AUC; 

import android.app.*; 
import android.os.*; 
import android.widget.*; 
import android.view.View.OnClickListener; 
import android.widget.Spinner.*; 
import android.view.*; 


public class MainActivity extends Activity {; 

    String Fbstring; 
    OnClickListener Myonclick; 

    public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    this.setContentView(R.layout.main); 
    final Spinner Fbspinner=(Spinner)findViewById(R.id.Spinner); 

    // The problem is with this line. OnClickListener just wont be   
    // recognised 
    Fbspinner.OnClickListener(Myonclick); 
    } 

    // Override previously disabled 
    @Override 
    public void Onselect(AdapterView<?> parent,View V, int pos, long id) { 
    Fbstring = parent.getItemAtPosition(pos).toString(); 
    System.out.println(Fbstring); 
    } 

    @Override 
    public void onNothingSelected(AdapterView<?> arg0) { 
    } 
} 

回答

0

您無法在微調器上設置onClickListener,只能在其目前對您而言過於先進的視圖中進行設置。相反,使用onItemSelectedListener。

public class MainActivity extends Activity extends Activity implements OnItemSelectedListener { 

public void onItemSelected(AdapterView<?> parent, View view, 
     int pos, long id) { 
    ... 
    ... 
} 

你應該閱讀文檔第一http://developer.android.com/guide/topics/ui/controls/spinner.html

也可以嘗試使用標準的命名約定:

http://www.oracle.com/technetwork/java/codeconv-138413.html http://www.oracle.com/technetwork/java/javase/documentation/codeconventions-135099.html#367

最後,你有這個代碼,例如很多問題

public class MainActivity extends Activity {; 

注意末尾的分號。

首先獲得您的代碼編譯,然後回到您的下一個問題。

祝你好運

+0

嗨西蒙,非常感謝您的幫助,工作的一種享受,我沒有收到編譯器的投訴。我有3本關於這個主題的書籍,我對這個主題有濃厚的興趣,但是我沒有時間閱讀這些書籍,並且喜歡挑選我想實現的內容,出於某種原因,我在創建應用程序時有一種緊迫感。我可能在我走路之前試着跑步。我認爲前進的方向是閱讀我的材料並在我有足夠的知識時完成申請。我會檢查你提供的主題。再次感謝。 –

+0

不客氣。請接受答案。 – Simon