I am trying to get the data from the webservice and create dynamic custom fields according to the response from the webservice. Then the user will fill the fields and then after clicking the upload button it will send the data from the dynamic custom fields to the webservice and then start to upload. I wonder that how can I get the data from the custom fields because they are created dynamically I can not reach them. Here is my code. Here is my picture that I created the fields after getting the response from the webservice I need your help.

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 <Response> WebData= new ArrayList<Response>();
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";
/** 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 && 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<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
for(int j=0;j<WebData.size();j++)
{
TextView t= new TextView(this);
t.setText(WebData.get(j).Name);
layout.addView(t);
if("Type"=="datetime")
{
EditText datetime= new EditText(this);
datetime.setId(j);
SimpleDateFormat sdf = new SimpleDateFormat( "yyyy/MM/dd" );
datetime.setText(sdf.format( new Date()));
layout.addView(datetime);
}//end of if
else if("Type"=="int")
{
EditText integer= new EditText(this);
layout.addView(integer);
}//end of else if
else
{
EditText nvarchar= new EditText(this);
layout.addView(nvarchar);
}//end of else
}//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
If I understood right, your problem is getting the data from the dynamically created fields. You could solve it by saving the dynamically created
EditTextin your class.Here’s your code saving the fields (I didn’t check the syntax). I’ve marked the changed blocks with //BUBBLE comment.
In a nutshell, I’ve created an ArrayList of
EditTextThen the list have been instantiated right before the fields creation:
And finally, once the fields were created, I’ve added them to both the list and the view:
I’ve made some small simplifications in your if statements, so I could use just one EditText object.
To get the components, just iterate through the array in the onClick method: