如何在android中的textviews中放置soap url值,我想以特定的顺序显示数据,我将数据逐个拆分但现在我想将数据放在特定的textview,Edittext中,我该怎么办?请你帮忙...提前致谢
public class MainActivity extends Activity {
private static final String SOAP_ACTION = "http://tempuri.org/Sessionamount";
private static final String OPERATION_NAME = "Sessionamount";
private static final String WSDL_TARGET_NAMESPACE = "http://tempuri.org/";
private static final String SOAP_ADDRESS = "220.226.170.5/service.asmx?WSDL";
TextView tvData1,ts;
EditText edata;
ImageView button;
String Date;
HttpTransportSE httpTransport;
SoapSerializationEnvelope envelope;
Object response;
//SoapPrimitive s;
ProgressDialog progress;
//
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
progress = new ProgressDialog(MainActivity.this);
button = (ImageView) findViewById(R.id.imageView1);
tvData1 = (TextView) findViewById(R.id.textView3);
ts = (TextView) findViewById(R.id.textView1);
edata = (EditText) findViewById(R.id.editText1);
// calendar function
final Calendar myCalendar = Calendar.getInstance();
final DatePickerDialog.OnDateSetListener date = new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year, int monthOfYear,
int dayOfMonth) {
// TODO Auto-generated method stub
myCalendar.set(Calendar.YEAR, year);
myCalendar.set(Calendar.MONTH, monthOfYear);
myCalendar.set(Calendar.DAY_OF_MONTH, dayOfMonth);
updateLabel();
}
private void updateLabel() {
// TODO Auto-generated method stub
String myFormat = "dd/MM/yyyy";
SimpleDateFormat sdf = new SimpleDateFormat(myFormat, Locale.US);
edata.setText(sdf.format(myCalendar.getTime()));
}
};
// listener for button
edata.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);*/
envelope=new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet=true;
envelope.setOutputSoapObject(request);
httpTransport = new HttpTransportSE(SOAP_ADDRESS);
try {
serviceCall();
} catch (Exception exception) {
tvData1.setText(exception.toString()
+ " Or No Records Found!");
}
}
});
}
void serviceCall() {
progress.setMessage("Loading Contents");
progress.show();
progress.setMessage("Redirecting credientials");
progress.show();
new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... params) {
try {
httpTransport.call(SOAP_ACTION, envelope);
response = envelope.getResponse();
} catch (IOException e) {
// TODO Auto-generated catch block
Toast.makeText(getApplicationContext(), e.getMessage(), 1)
.show();
e.printStackTrace();
} catch (XmlPullParserException e) {
// TODO Auto-generated catch block
Toast.makeText(getApplicationContext(), e.getMessage(), 1)
.show();
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(Void result) {
String str = "";
if (progress != null)
progress.dismiss();
if (response !=null)
{
/* private static List <String> parse (String str)
{
String temp;
List <String> list = new ArrayList <String> ();
if (str!= null && Str.length ()> 0)
{
int start = str.indexOf ("string");
int end = str.lastIndexOf (";");
temp = str.substring (start, end - 3);
String [] test = temp.split (";");
for (int i = 0; i <test.length; i++)
{
if (i == 0) {temp = test [i]. substring (7);
}
else
{
temp = test [i]. substring (8);
}
int index = temp.indexOf (",");
list.add (temp.substring (0, index));
}}
return list;
} */
String resultArr[] = response.toString().split(";");
/*for(int i=0;i<resultArr.length;i++)
{
str=str+resultArr[i]+"\n\n";
tvData1.setText(str);
}*/
for(int i=0;i<resultArr.length;i++)
{
str=str+resultArr[i]+"\n\n";
//tvData1.setText(str);
edata.setText(str);
tvData1.setText(str);
}
} else
//tvData1.setText("");
Toast.makeText(getApplicationContext(), "No Records Found", 1)
.show();
}
}.execute();
}
}
//this is my xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/splash"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<EditText
android:id="@+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="DD/MM/YY"
android:textColor="#FFFFFF"
android:layout_weight="1"
android:ems="10" >
<requestFocus />
</EditText>
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_weight="1"
android:src="@drawable/search" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:orientation="horizontal" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/roundborder"
android:text="Session Amount"
android:textColor="#FFFFFF"
android:textSize="20sp"
android:textStyle="bold"
android:visibility="invisible" />
<!-- <TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Amount"
android:background="@drawable/roundborder"
android:textColor="#FFFFFF"
android:visibility="invisible"
android:textSize="20sp"
android:textStyle="bold" /> -->
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_marginTop="30dp"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:textColor="#FFFFFF"
android:background="@drawable/roundborder"
android:visibility="invisible"
android:layout_weight="2"
android:layout_height="match_parent"
android:text="" />
</LinearLayout>
</LinearLayout>
//this is the format i need
session Amount
Afternoon 68788798
Morning 87686978
Evening 24232
I want to get the total amount of those amounts,I just add(+) amount alone
How can i add
Is there any concept
//The URL look like this,
Afternoon-99127.79;Night-67236.27;Morning-61876.65;Evening-20271.42;Housekeeping-5444.05;
答案 0 :(得分:0)
如果您喜欢以下
for(int i=0;i<resultArr.length;i++)
{
str=str+resultArr[i]+"\n\n";
//tvData1.setText(str);
edata.setText(str);
tvData1.setText(str);
}
然后edittext和textview具有相同的值。
所以你应该做的是,
tvData1.setText(resultArr[0]);
edata.setText(resultArr[1]); // this is the general idea. You can do this only if you know the exact position of the value and length of the array.
tvData1.setText(resultArr[2]);