2012-02-20 26 views
0

フォームをレンダリングしていますが、[送信]ボタンをクリックすると、結果を取得する方法が正確にわかりません。ここでAndroidのフォームからユーザー入力を取得できません

は私のActivityクラスです:

package com.problemio; 

import android.app.Activity; 
import android.content.Intent; 
import android.os.Bundle; 
import android.view.View; 
import android.widget.Button; 
import android.widget.EditText; 
import android.widget.TextView; 

public class AddProblemActivity extends Activity 
{ 
    /** Called when the activity is first created. */ 
    @Override 
    public void onCreate(Bundle savedInstanceState) 
    { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.add_problem); 


     final EditText problemName = (EditText) findViewById(R.id.problem_name); 
     String name = problemName.getText().toString(); 

     final EditText problemText = (EditText) findViewById(R.id.problem_text); 
     String text = problemText.getText().toString();   

    System.out.println(name);  
    System.out.println(text);   




//  Button browseProblemsButton = (Button)findViewById(R.id.browseProblemsButton); 
//  Button searchProblemsButton = (Button)findViewById(R.id.searchProblemsButton); 
//  Button myProblemsButton = (Button)findViewById(R.id.myProblemsButton);   


    } 

    public void sendFeedback(View button) 
    { 


     System.out.println("3"); 
     Button addProblemButton = (Button)findViewById(R.id.button_send_feedback); 

     addProblemButton.setOnClickListener(new Button.OnClickListener() 
     { 
      public void onClick(View v) 
      { 
       System.out.println("4"); 

       //Intent myIntent = new Intent(ProblemioActivity.this, AddProblem.class); 
       //ProblemioActivity.this.startActivity(myIntent); 
      } 
     });   
     System.out.println("end"); 

     // Do click handling here 
    }  
} 

私は何が私のログ出力に書き込まれますかどうかを確認するためにそこにいくつかのSystem.out文を置くが、それは動作しませんでした。私はAndroidデベロッパーが初めてです - コンソールに物事を出力するためによく使われる方法がありますか?

また、フォーム要素からの入力をどこでどのように取得するかわかりません。感謝

ヘルプ、 アレックス

答えて

3

ユーザーが入力した内容を取得する方法は次のとおりです。実際には、最初に必要なすべてのコードがあり、正しく配置されていません。あなたのリスナーが(私が正しくあなたの意図を理解していた場合)、次のようになりますとonCreate()方法に置かれる:@onitが述べたように

private void sendFeedback(String name, String text){ 
    //Do what ever you need to here for sending feed back. 
} 

Button addProblemButton = (Button)findViewById(R.id.button_send_feedback); 
addProblemButton.setOnClickListener(new Button.OnClickListener() 
{ 
    public void onClick(View v) 
    { 
     String name = problemName.getText().toString(); 
     String text = problemText.getText().toString(); 
     sendFeedback(name, text); 
    } 
}); 

を次に、あなたのsendFeedback機能は次のようになります。デバッグ情報を出力するには、Logクラスを使用する必要があります。具体的にはLog.d()

+0

このリスナーはsendFeedback()メソッドまたはonCreate()メソッド内にある必要がありますか?ありがとう! – Genadinik

+0

申し訳ありませんが、私の答えを少しクリアしました –

+0

ありがとう、それは素晴らしいです!私はちょうど答えを受け入れた。私が尋ねることができる場合は、もう1つ質問Q:画面にエラーメッセージを表示したり、そのデータをリモートデータベースに挿入する必要がある場合は、そのための良い手順は何ですか? – Genadinik

1

はあなたの問題は、あなたがのSystem.outを使用していることです。デフォルトでは、System.outは/ dev/nullに出力しますので、出力はありません。 Android Debug Bridgeを使用してSystem.outをリダイレクトして、データをログに出力することができます。 Logクラスを使用してログに情報を投稿することもできます。

関連する問題