Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>If I understood right, your problem is getting the data from the dynamically created fields. You could solve it by saving the dynamically created <code>EditText</code> in your class. </p> <p>Here's your code saving the fields (I didn't check the syntax). I've marked the changed blocks with //BUBBLE comment.</p> <pre><code>package com.isoft.uploader; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; import java.util.Hashtable; import java.util.List; import org.json.JSONArray; import org.json.JSONObject; import org.ksoap2.SoapEnvelope; import org.ksoap2.serialization.SoapObject; import org.ksoap2.serialization.SoapSerializationEnvelope; import org.ksoap2.transport.HttpTransportSE; import android.app.Activity; import android.app.AlertDialog; import android.content.Intent; import android.database.Cursor; import android.net.Uri; import android.os.Bundle; import android.provider.MediaStore; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.LinearLayout; import android.widget.LinearLayout.LayoutParams; import android.widget.ScrollView; import android.widget.TextView; public class UploaderActivity extends Activity { ArrayList &lt;Response&gt; WebData= new ArrayList&lt;Response&gt;(); public static final int SELECT_VIDEO=1; public static final String TAG="UploadActivity"; String path=""; final String NAMESPACE = "http://tempuri.org/"; final String SERVICEURL = "http://192.168.10.177/androidws/isandroidws.asmx"; final String METHOD_NAME1="OzelVeriAlanlariniGetir"; final String METHOD_NAME="KullaniciGiris"; // BUBBLE private List&lt;EditText&gt; dynaFields = null; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Button enter=(Button)findViewById(R.id.Enter); final EditText username=(EditText)findViewById(R.id.username); final EditText password=(EditText)findViewById(R.id.password); final AlertDialog ad=new AlertDialog.Builder(this).create(); enter.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View arg0) { // TODO Auto-generated method stub //request code for Webservice SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME); //sending the username to the webservice request.addProperty("kullaniciAdi",username.getText().toString()); //sending the password to the webservice request.addProperty("password",password.getText().toString()); SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); envelope.dotNet = true; //Putting the request in an envelope envelope.setOutputSoapObject(request); HttpTransportSE transport = new HttpTransportSE(SERVICEURL); Object response = null; try { transport.call("http://tempuri.org/"+METHOD_NAME, envelope); //getting the response from the webservice response= envelope.getResponse(); } catch(Exception exception) { exception.printStackTrace(); }//end of catch if(response!=null &amp;&amp; Integer.parseInt(response.toString()) != 0) { openGaleryVideo(); }//end of if else { ad.setMessage("Lütfen Kullanıcı Adınızı ve Şifrenizi Kontrol Ediniz."); ad.show(); }//end of else }//end of onClick method });//end of OnclickListener method }//end of onCreate method public void openGaleryVideo() { Intent intent=new Intent(); intent.setType("video/*"); intent.setAction(Intent.ACTION_GET_CONTENT); startActivityForResult(Intent.createChooser(intent, "Select Video"),SELECT_VIDEO); }//end of openGaleryVideo method public String getPath(Uri uri) { String[] projection = { MediaStore.Video.Media.DATA}; Cursor cursor = managedQuery(uri, projection, null, null, null); int column_index = cursor.getColumnIndexOrThrow(MediaStore.Video.Media.DATA); cursor.moveToFirst(); return cursor.getString(column_index); }//end of getPath method //Response Class public class Response { int Id; String Name; String Type; String Value; String DefaultValue; int Flag; int Index; }//end of Response class //onActivityResult @SuppressWarnings("unused") public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (resultCode == RESULT_OK) { if (requestCode == SELECT_VIDEO) { Uri videoUri = data.getData(); path=getPath(videoUri); ScrollView scroll = new ScrollView(this); LinearLayout layout=new LinearLayout(this); layout.setOrientation(LinearLayout.VERTICAL); layout.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); scroll.addView(layout,new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)); setContentView(scroll); SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME1); SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); envelope.dotNet = true; //İsteğimizi zarf'a koyuyoruz envelope.setOutputSoapObject(request); HttpTransportSE transport = new HttpTransportSE(SERVICEURL); final AlertDialog adr=new AlertDialog.Builder(this).create(); Object response1=null; try { transport.call("http://tempuri.org/"+METHOD_NAME1, envelope); //getting the response from the webservice response1 =envelope.getResponse(); JSONArray jArray= new JSONArray(response1.toString()); for(int i=0;i&lt;jArray.length();i++) { JSONObject json_data= jArray.getJSONObject(i); Response result= new Response(); result.Id= json_data.getInt("Id"); result.Name= json_data.getString("Name"); result.Type= json_data.getString("Type"); result.Value=json_data.getString("Value"); result.DefaultValue=json_data.getString("DefaultValue"); result.Flag=json_data.getInt("Flag"); result.Index=json_data.getInt("Index"); WebData.add(i,result); }//end of for loop }//end of try catch(Exception exception) { exception.printStackTrace(); }//end of catch // BUBBLE create a list with the exact size of input fields this.dynaFields = new ArrayList&lt;EditText&gt;(WebData.size()); for(int j=0;j&lt;WebData.size();j++) { //BUBBLE: instantiate and add the current field to the list and view EditText newField = new EditText(this); this.dynaFields.add (newField) layout.addView(newField); TextView t= new TextView(this); t.setText(WebData.get(j).Name); layout.addView(t); if("Type"=="datetime") { //BUBBLE newField.setId(j); SimpleDateFormat sdf = new SimpleDateFormat( "yyyy/MM/dd" ); newField.setText(sdf.format( new Date())); }//end of if }//end of for loop Button button= new Button(this); button.setClickable(true); button.setText("Yükle"); layout.addView(button); button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View arg0) { // TODO Auto-generated method stub } }); }//end of If request code }//end of If result code }//end of onActivityResult }//end of main </code></pre> <p>In a nutshell, I've created an ArrayList of <code>EditText</code></p> <pre><code>private List&lt;EditText&gt; dynaFields = null; </code></pre> <p>Then the list have been instantiated right before the fields creation:</p> <pre><code>// BUBBLE create a list with the exact size of input fields this.dynaFields = new ArrayList&lt;EditText&gt;(WebData.size()); </code></pre> <p>And finally, once the fields were created, I've added them to both the list and the view:</p> <pre><code>// instantiate and add the current field to the list and view EditText newField = new EditText(this); this.dynaFields.add (newField) layout.addView(newField); </code></pre> <p>I've made some small simplifications in your if statements, so I could use just one EditText object.</p> <p>To get the components, just iterate through the array in the onClick method:</p> <pre><code>public void onClick(View arg0) { TextField currText; for (currText : UploaderActivity.this.dynaFields) { // TODO: get the current EditText text and have fun! } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload