2013-10-24 30 views
-1

我想開發一個能力應用程序.. 在我的文本視圖中,我必須顯示第一個問題..在點擊下一個按鈕時,我必須顯示第二個問題..再次點擊下一個按鈕第三個問題必須顯示..喜歡我想顯示一些30個問題..所有問題都應該顯示在單個java文件中。我試圖顯示兩個問題。但對於多的問題,我找不到代碼..Android Apptitude練習應用程序

package com.example.asl; 
    import java.util.Arrays; 
    import java.util.Random; 

import android.app.Activity; 
import android.os.Bundle; 
import android.view.View; 
import android.view.View.OnClickListener; 
import android.widget.Button; 
import android.widget.TextView; 

    public class Aptitude extends Activity { 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.aptitude); 
    Button b=(Button) findViewById(R.id.button1); 
    final TextView tv=(TextView) findViewById(R.id.textView1); 
    final String Question[]={"what is UR Name","What is ur Age","Whats ur Qualification"}; 
    Button btnNext = (Button) findViewById(R.id.button1); 
    final TextView cumulos = (TextView) findViewById(R.id.textView1); 
     //TextView respostas = (TextView)findViewById(R.id.respostas); 

     Random randPhrase = new Random(); 
     final String[] cum = {"what is UR Name","What is ur Age","Whats ur Qualification"}; 
     //String[] resp = getResources().getStringArray(R.array.resp_cumulos); 

     String textout = ""; 
     String textresp = ""; 

    //Button btnPrevious = (Button) findViewById(R.id.yourPreviousbutton); 

    btnNext.setOnClickListener(new OnClickListener(){ 

     public void onClick(View arg0) { 
      int i = 0; 
       if(i<cum.length-1){ 
        i+=1; 
        cumulos.setText(cum[i]); 
        // respostas.setText(resp[i]); 
       } 

     } 


    }); 
    //btnPrevious.setOnClickListener(new OnClickListener(){ 

     //public void onClick(View arg0) { 
       //if(i>0){ 
        // i-=1; 
       // cumulos.setText(cum[i]); 
        // respostas.setText(resp[i]); 
      // } 

     // } 


    //}); 

} 

    } 

enter code here 
+1

你在這段代碼中遇到了一些錯誤,或者你不知道如何製作應用程序?我完全無法理解這個問題。 – azmuhak

+0

我不能改變問題...在文本視圖中,我得到第一個問題..後點擊按鈕下一個應該來..在第三點擊第三個問題應該來 –

回答

2

初始化你的櫃檯在onClick()總是要重置

初始化它的onClick()之外,並增加其在onClick()的你。

public class Aptitude extends Activity { 

    int i = 0; 

    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.aptitude); 
     Button b=(Button) findViewById(R.id.button1); 
     ... 
    } 

    public void onClick(View arg0) { // rename arg0 to something meaningful 
             // like v or view for readibility 
    // int i = 0; remove this guy 
      if(i<cum.length-1){ 
       i+=1; 
       cumulos.setText(cum[i]); 

如果這沒有解決您的問題,那麼請解釋的問題是什麼,但我敢肯定,這部分是給你造成麻煩。

+0

我需要顯示一個問題,當我第一次進入該頁面時設置在數組中..點擊該數組後的下一個問題後應顯示替換現有的第一個問題。在第二次點擊第三陣列應該顯示替換第二個問題... –

+0

這就是我以爲你想要做的。那麼這個解決方案應該可以幫助你。 – codeMagic

+0

非常感謝... 這種編碼適用於我...但我想通過從服務器數據庫檢索,而不是陣列... \t public int count = 0; \t \t \t \t \t \t 最終\t字符串問題[] = { 「whatsURName」, 「WhatsurAge」, 「WhatsurQualition」}; \t \t tv.setText(「hello」); \t \t \t \t b.setOnClickListener(新OnClickListener(){ \t \t \t \t \t \t @覆蓋 \t \t \t公共無效的onClick(查看爲arg0){ \t \t \t \t \t \t \t \t \t \t \t \t count ++; \t \t \t \t開關(計數){ \t \t \t \t情況下0:電視。的setText(問題[0]); \t \t \t \t \t \t \t \t \t \t休息; \t \t \t \t案例1:tv.setText(Question [1])\t; break; \t \t \t \t案例2:tv.setText(Question [2]); break; \t \t \t \t \t \t \t \t} \t \t \t \t \t \t \t \t \t \t \t} \t \t}); \t \t \t \t \t \t} } –