This works and displays the string in an EditText but doesn't work with a TextView

  • Replies:1
Stephen Wilkinson
  • Forum posts: 2

Oct 2, 2012, 3:35:17 PM via Website

am having real problems trying to display a string of text using setText on a textview. All my calls to the webservice work, my functions to get the data work and if I use an EditText to display the string, everything is shown correctly but I'd rather the text just appeared on the screen rather than in an EditText as the text is information rather than something to be edited by the user.

This code works for EditText -

1package xxx.refusecollectionday;
2
3import org.ksoap2.SoapEnvelope;
4import org.ksoap2.serialization.SoapObject;
5import org.ksoap2.serialization.SoapSerializationEnvelope;
6import org.ksoap2.transport.HttpTransportSE;
7
8import android.app.Activity;
9import android.app.AlertDialog;
10import android.content.DialogInterface;
11import android.content.Intent;
12import android.os.Bundle;
13import android.widget.EditText;
14import android.widget.TextView;
15import android.widget.Toast;
16
17public class SingleListItem extends Activity{
18 /** Called when the activity is first created. */
19 private static String NAMESPACE = "http://xxx";
20 private static String URL = "http://xxx/Service.asmx";
21 private static String SOAP_ACTION = "http://xxxx";
22 private static String METHOD_NAME1 = "xxx";
23
24 @Override
25 public void onCreate(Bundle savedInstanceState) {
26 super.onCreate(savedInstanceState);
27 this.setContentView(R.layout.single_list_item_view);
28
29 Intent intent = getIntent();
30 String uprn = intent.getStringExtra(AndroidListViewActivity.UPRN).trim();
31 String displayText = "";
32
33 //Initialize soap request + add parameters
34 SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME1);
35
36 //Use this to add parameters
37 request.addProperty("UPRN",uprn);
38
39 //Declare the version of the SOAP request
40 SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
41
42 envelope.setOutputSoapObject(request);
43 envelope.dotNet = true;
44
45 try {
46 HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
47
48 //this is the actual part that will call the webservice
49 androidHttpTransport.call(SOAP_ACTION, envelope);
50
51 // Get the SoapResult from the envelope body.
52 SoapObject result = (SoapObject)envelope.bodyIn;
53
54 if(result != null) {
55 String strXML = result.getProperty(0).toString();
56 strXML = sortXMLString(strXML);
57 }
58 }else{
59 showBalloonPopUp("No Response");
60 }
61 }catch(Exception e) {
62 e.printStackTrace();
63 }
64
65 displayText = displayText + "\nTo contact the Customer Service Centre:\n";
66
67 EditText txtCollectionResults = (EditText) findViewById(R.id.collectionresults);
68
69 // displaying selected product name
70 txtCollectionResults.setText(displayText);
71
72 //showAlertDialog(displayText);
73 }
74
75 public void showBalloonPopUp(String popUpMessage){
76 Toast.makeText(this, popUpMessage, Toast.LENGTH_SHORT).show();
77 }
78
79 public void showAlertDialog(String alertMessage){
80 AlertDialog ad = new AlertDialog.Builder(this).create();
81 ad.setCancelable(false); // This blocks the 'BACK' button
82 ad.setMessage(alertMessage);
83 ad.setButton(-1, "OK", new DialogInterface.OnClickListener() {
84 @Override
85 public void onClick(DialogInterface dialog, int which) {
86 dialog.dismiss();
87 }
88 });
89 ad.show();
90 }
91
92 public String sortXMLString(String stringToCorrect){
93 // do stuff
94
95 return stringToCorrect;
96 }
97}
98
99<?xml version="1.0" encoding="utf-8"?>
100<LinearLayout
101 xmlns:android="http://schemas.android.com/apk/res/android"
102 android:orientation="vertical"
103 android:layout_width="match_parent"
104 android:layout_height="match_parent">
105 <EditText android:id="@+id/collectionresults"
106 android:layout_width="fill_parent"
107 android:layout_height="wrap_content"
108 android:textSize="15dip"
109 android:padding="10dip"
110 android:textColor="#000000"
111 android:maxLines="50"
112 android:editable="false" />
113</LinearLayout>

but if I change the EditText to a TextView in the xml, the following

1TextView txtCollectionResults = (TextView) findViewById(R.id.collectionresults);
2
3 // displaying
4 txtCollectionResults.setText(displayText);

doesnt display any text.

Any help would be really appreciated.

Reply
Stephen Wilkinson
  • Forum posts: 2

Oct 3, 2012, 12:50:36 PM via Website

Total schoolboy error - White text on a white background ended up being the problem!

Reply