2016-05-24 4 views
0

私はforループに従ってeditboxの番号を生成したいと思っています。ボタンを使って、ユーザ入力データをeditboxに処理するメソッドを呼び出さなければなりません。androidのforループに相当するテキストボックスの数

私が知っている限り、私は警告ダイアログボックスを非同期で使用することはできず、ユーザーの応答を待たずに、私は上記の方法を使用して動作を見るかもしれません。 と提案とアドバイスが必要です。以下のコードはいくつかのアイデアを与えるかもしれません。

for(int x=0;x<vars.size();x++) 
    { 
     String get_var=vars.get(x).toString();//get the first item from array 
     replace(get_var,temp_t);//send the get_var to replace method 
    } 

置き換える方法のアイデアは

replace(String get_var,String temp_t) 
{ 
String y=(user input from the textbox, which has to be created dynamically) 
if(button pressed) //created dynamically 
process(y,temp_t) 
} 

である私は、ボタンを排除し、直接 を処理するように動作するはずだと思うものを、その後の周りに、より良い他の作業がある場合に提案してください[更新]

for(int x=0;x<vars.size();x++) 
    { 
     String get_var=vars.get(x).toString(); 
     get_vals_for_xy(get_var, temp_t); 
    } 

    getSupportActionBar().setDisplayHomeAsUpEnabled(true); 
}//end of oncreate method 

public void get_vals_for_xy(String get_var,String[][] temp_t) { 
    System.out.println("value of get_var is " + get_var); 
    AlertDialog.Builder alert = new AlertDialog.Builder(this); 
    final EditText edittext = new EditText(this); 
    alert.setMessage("value is"+get_var); 
    alert.setTitle("Title"); 

    alert.setView(edittext); 

    alert.setPositiveButton("Yes", new DialogInterface.OnClickListener() { 
     public void onClick(DialogInterface dialog, int whichButton) { 

      String to_replace = edittext.getText().toString(); 
      show(to_replace); 
      Toast.makeText(AssignValandFacts.this, to_replace, Toast.LENGTH_SHORT).show(); 
     } 
    }); 

    alert.setNegativeButton("No", new DialogInterface.OnClickListener() { 
     public void onClick(DialogInterface dialog, int whichButton) { 

     } 
    }); 

    alert.show(); 


} 

答えて

0

forループの各項目に対してダイアログを表示し、ユーザー入力を取得することができます

boolean userResponseReceived=false; 
//create a dialog 
Dialog dialog=new Dialog(context); 
//set dialog content view 
//I just assume you have a button in dialog that says OK 
Button okButton=(Button)dialog.findViewById(R.id.btnId); 
okButton.setOnClickListener(new View.OnclickListener{ 
    @Override 
    public void onClick(View v){ 
     //userResponseRecieved is a instance variable 
     userResponseReceived=true; 
    } 
}); 
for(int x=0;x<vars.size();x++){ 
    //make a while loop to hold the for loop while user inserts data 
    //make a dialog box and handle user input 
    dialog.show(); 
    while(!userResponseReceived){} 
    //continue with the for loop 
    dialog.dismiss(); 
    userResponseReceived=false; 
} 
+0

これも私が知っていることですが、どのように行うのですか?上記のプロンプトとロジックを使用しましたが、動作していません。 –

+0

アップデートを確認してください。 –

+0

コードを更新しました。ブール値。私はここでnを試していますが、同じ結果です。それはループ内で停止していません –

関連する問題