Right now i am creating a barchart in android using AChartEngine.After getting run of my application,at-first the emulator is showing like the first below image. But i need to show like the second below image how to do this?
And also i need to change the color for the background and also i wanna change the bar-charts colors,
How to do these things?
I have tried these codes, but not working
renderer.setApplyBackgroundColor(true);
renderer.setBackgroundColor(Color.GRAY);
Please find my sources for reference.
Chart.java
public class Chart extends Activity {
EditText edt1, edt2;
TextView txtv1;
Button btn;
Bundle data;
String[] orderNo = new String[10];
int[] freightRate = new int[10];
int[] marginPercent = new int[10];
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
edt1 = (EditText) findViewById(R.id.editText1);
edt2 = (EditText) findViewById(R.id.editText2);
btn = (Button) findViewById(R.id.button1);
btn.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
getTMSChart(edt1.getText().toString(), edt2.getText().toString());
Intent intnt = new Intent(v.getContext(), BarGraphActivity.class);
intnt.putExtras(data);
startActivity(intnt);
}
});
}
public void getTMSChart(String FromDate, String ToDate)
{
System.setProperty("http.keepAlive", "false");
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
String METHOD = "GetTMSChart";
String NAMESPACE = "http://tempuri.org/";
String SOAP_ACTION = "http://tempuri.org/GetTMSChart";
String URL = "http://54.251.60.177/TMSOrdersService/TMSDetails.asmx";
SoapObject request = new SoapObject(NAMESPACE, METHOD);
request.addProperty("FromDate", FromDate.trim());
request.addProperty("ToDate", ToDate.trim());
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
try {
androidHttpTransport.call(SOAP_ACTION, envelope);
SoapObject result = (SoapObject) envelope.bodyIn;
SoapObject root = (SoapObject) ((SoapObject) (result).getProperty(0)).getProperty("NewDataSet");
int tablesCount = root.getPropertyCount();
data = new Bundle();
for (int i = 0; i < tablesCount; i++) {
SoapObject table = (SoapObject) root.getProperty(i);
orderNo[i] = table.getPropertyAsString("Order_No");
freightRate[i] = Integer.parseInt(table.getPropertyAsString("Freight_Rate"));
marginPercent[i] = Integer.parseInt(table.getPropertyAsString("Margin_Percent"));
/*Toast.makeText(getApplicationContext(), "Order No:" + orderNo[i] + "\nFreigtRate:" + freightRate[i] + "\nMarginPc:" + marginPercent[i], Toast.LENGTH_SHORT).show();*/
}
data.putStringArray("orderno", orderNo);
data.putIntArray("freightrate", freightRate);
data.putIntArray("marginpercent", marginPercent);
data.putInt("count",tablesCount);
}
catch (Exception e)
{
Toast.makeText(getApplicationContext(), e.getMessage(), Toast.LENGTH_LONG).show();
e.printStackTrace();
} }}
BarGraphActivity.java
public class BarGraphActivity extends Activity{
String[] orderNo = new String[10];
int[] freightRate = new int[10];
int[] marginPercent = new int[10];
int count;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main1);
Bundle idata = getIntent().getExtras();
if (idata !=null)
{
orderNo = idata.getStringArray("orderno");
freightRate = idata.getIntArray("freightrate");
marginPercent = idata.getIntArray("marginpercent");
count = idata.getInt("count");
CategorySeries series = new CategorySeries("Order-FreightRate Graph");
for ( int i = 0; i < count; i++){
series.add(orderNo[i], freightRate[i]);
}
XYMultipleSeriesDataset dataset = new XYMultipleSeriesDataset();
dataset.addSeries(series.toXYSeries());
XYSeriesRenderer renderer = new XYSeriesRenderer();
renderer.setDisplayChartValues(true);
//renderer.setChartValuesSpacing(1);
XYMultipleSeriesRenderer mRenderer = new XYMultipleSeriesRenderer();
mRenderer.addSeriesRenderer(renderer);
for ( int i = 0; i < count; i++){
mRenderer.addXTextLabel(i+1, orderNo[i]);
}
mRenderer.setZoomButtonsVisible(true);
mRenderer.setBarSpacing(0.5);
Intent intent = ChartFactory.getBarChartIntent(getApplicationContext(), dataset, mRenderer, Type.DEFAULT);
startActivity(intent);
} } }
Thanks for your precious time!..
Hi if you want to change background color for your chart just use these methods
mrenderer.setApplyBackgroundColor(true);
mrenderer.setBackgroundColor(Color.parseColor("#898989")); // here you have to give hexa decimal code
mrenderer.setMarginsColor(Color.parseColor("#898989")); // here you have to give hexa decimal code
If you want to change your bar color means just do like this
int[] colors = new int[] { Color.parseColor("#DAE1EB"), Color.parseColor("#406193")};
int color_length = colors.length;
for (int i = 0; i < color_length; i++)
{
SimpleSeriesRenderer r = new SimpleSeriesRenderer();
r.setColor(colors[i]);
r.setChartValuesSpacing(5);
mrenderer.addSeriesRenderer(r);
}
If you are creating multiple renderer means use different color for the dual bar. If you are creating single bar means give only one color. It will works.
Related
I am trying to make a bar graph through web service but I m getting a problem. The bar graph page is display but no bar is there. So please any one help me.
Thanks in advance....
MY Code Is Here :
Chart Activity
public class Chart_MainActivity extends Activity
{
/// EditText edt1, edt2;
// TextView txt_1;
Button btn;
ArrayList<String> result;
//String x,y;
String x = "", y = "";
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.mainn);
// edt1 = (EditText) findViewById(R.id.edt1_date1);
// edt2 = (EditText) findViewById(R.id.edt_date2);
btn = (Button) findViewById(R.id.button_invoke);
result = new ArrayList<String>();
btn.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
// result.addAll(getTMSChart(edt1.getText().toString(), edt2.getText().toString()));
result.add(x);
result.add(y);
Intent in = new Intent(getApplicationContext(), NextActivity.class);
in.putExtra("gotonextpageX", result.get(0));
in.putExtra("gotonextpageY", result.get(1));
startActivity(in);
}
});}
private ArrayList<String> getTMSChart(String FromDate, String ToDate)
{
// txt_1 = (TextView)findViewById(R.id.textView1);
System.setProperty("http.keepAlive", "false");
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
String NAMESPACE = "http://tempuri.org/";
String URL = "http://smartData/weight.asmx";
String METHOD = "weight";
SoapObject request = new SoapObject(NAMESPACE, METHOD);
request.addProperty("FromDate", FromDate);
request.addProperty("ToDate", ToDate);
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
String x = "", y = "";
ArrayList<String> stringResult = new ArrayList<String>();
try
{
androidHttpTransport.call(NAMESPACE + METHOD, envelope);
SoapObject result = (SoapObject) envelope.bodyIn;
SoapObject root = (SoapObject) ((SoapObject) (result).getProperty(0)).getProperty("NewDataSet");
int tablesCount = root.getPropertyCount();
for (int i = 0; i < tablesCount; i++)
{
SoapObject table = (SoapObject) root.getProperty(i);
int propertyCount = table.getPropertyCount();
for (int j = 0; j < propertyCount; j++)
{
stringResult.add(table.getProperty("Name").toString());
stringResult.add(table.getProperty("Value").toString());
// stringResult.add(table.getPropertyAsString("Margin_Percent").toString());
// freightRate = Integer.parseInt(table.getPropertyAsString("Freight_Rate"));
}
}
}
catch (ArrayIndexOutOfBoundsException e)
{}
catch(Exception e)
{}
return stringResult;
} }
Next Activity :
public class NextActivity extends Activity
{
double x,y;
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.mainn1);
Bundle extras = getIntent().getExtras();
if(extras != null)
{
x = extras.getDouble("gotonextpageX");
y = extras.getDouble("gotonextpageY");
}
else
{}
final GraphicalView gv =createIntent();
RelativeLayout rl=(RelativeLayout)findViewById(R.id.rlt);
rl.addView(gv);
}
public GraphicalView createIntent()
{
String[] titles = new String[] { "Orders profit"};
List<double[]> values = new ArrayList<double[]>();
values.add(new double[] {x,x,x});
values.add(new double[] {y,y,y});
int[] colors = new int[] { Color.parseColor("#77c4d3")};
XYMultipleSeriesRenderer renderer = buildBarRenderer(colors);
renderer.setOrientation(XYMultipleSeriesRenderer.Orientation.HORIZONTAL);
setChartSettings(renderer,"","Order number","Freight Rate",0.5,12.5, 0, 1000, Color.GREEN, Color.GREEN);
renderer.setXLabels(1);
renderer.setYLabels(5);
renderer.setPanEnabled(true, false);
/*renderer.addXTextLabel(1, "Jan");
renderer.addXTextLabel(2, "Feb");
renderer.addXTextLabel(3, "Mar");
renderer.addXTextLabel(4, "Apr");
renderer.addXTextLabel(5, "May");
renderer.addXTextLabel(6, "Jun");
*/
int length = renderer.getSeriesRendererCount();
for (int i = 0; i < length; i++)
{
SimpleSeriesRenderer seriesRenderer = renderer.getSeriesRendererAt(i);
seriesRenderer.setDisplayChartValues(true);
}
final GraphicalView grfv = ChartFactory.getBarChartView(NextActivity.this, buildBarDataset(titles, values), renderer, BarChart.Type.DEFAULT);
return grfv;
}
protected XYMultipleSeriesRenderer buildBarRenderer(int[] colors)
{
XYMultipleSeriesRenderer renderer = new XYMultipleSeriesRenderer();
renderer.setAxisTitleTextSize(16);
renderer.setChartTitleTextSize(20);
renderer.setLabelsTextSize(15);
renderer.setLegendTextSize(15);
renderer.setBarSpacing(1);
renderer.setMarginsColor(Color.parseColor("#0E120E"));
renderer.setXLabelsColor(Color.WHITE);
renderer.setYLabelsColor(0,Color.WHITE);
renderer.setApplyBackgroundColor(true);
renderer.setBackgroundColor(Color.parseColor("#000000"));
int length = colors.length;
for (int i = 0; i < length; i++)
{
SimpleSeriesRenderer r = new SimpleSeriesRenderer();
r.setColor(colors[i]);
r.setChartValuesSpacing(-90);
r.setChartValuesSpacing(15);
renderer.addSeriesRenderer(r);
}
return renderer;
}
protected XYMultipleSeriesDataset buildBarDataset(String[] titles, List<double[]> values)
{
XYMultipleSeriesDataset dataset = new XYMultipleSeriesDataset();
int length = titles.length;
for (int i = 0; i < length; i++)
{
CategorySeries series = new CategorySeries(titles[i]);
double[] v = values.get(i);
int seriesLength = v.length;
for (int k = 0; k < seriesLength; k++)
{
series.add(v[k]);
}
dataset.addSeries(series.toXYSeries());
}
return dataset;
}
protected void setChartSettings(XYMultipleSeriesRenderer renderer, String title, String xTitle,
String yTitle, double xMin, double xMax, double yMin, double yMax, int axesColor,int labelsColor)
{
renderer.setChartTitle(title);
renderer.setYLabelsAlign(Paint.Align.RIGHT);
renderer.setXTitle(xTitle);
renderer.setYTitle(yTitle);
renderer.setXAxisMin(xMin);
renderer.setXAxisMax(xMax);
renderer.setYAxisMin(yMin);
renderer.setYAxisMax(yMax);
renderer.setMargins(new int[] { 10, 65, 10, 15 });
renderer.setAxesColor(axesColor);
renderer.setLabelsColor(labelsColor);
} }
I got an unknown buffer error...plzzz help me
Next Activity :
Change below lines
x = extras.getString("gotonextpageX");
y = extras.getString("gotonextpageY");
to
x = Double.valueOf(extras.getString("gotonextpageX"));
y = Double.valueOf(extras.getString("gotonextpageY"));
i want to set the calculation result in TextView named total[] from the value of EditText named point[] .but i am able to parse the value and put it in the TextView . it give me an error in logcat
06-27 02:27:01.467: E/AndroidRuntime(275): Caused by: java.lang.NumberFormatException: unable to parse '' as integer
this is an error in logcat. i want to add integer values to the textview continuously from the edittext on the same layout
public class player_name extends Activity {
LinearLayout player_name;
TableLayout ply_name;
Bundle b,b1;
List<TextView> allEds = new ArrayList<TextView>();
List<Button> allplus = new ArrayList<Button>();
List<Button> allminus = new ArrayList<Button>();
List<EditText> alledit = new ArrayList<EditText>();
List<TextView> alltotal = new ArrayList<TextView>();
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.player_name);
b1 = getIntent().getExtras();
String[] result = b1.getStringArray("playerName");
player_name = (LinearLayout) findViewById(R.id.player_name);
ply_name = new TableLayout(this);
player_name.addView(ply_name);
TableLayout.LayoutParams tableRowParams=new TableLayout.LayoutParams
(TableLayout.LayoutParams.MATCH_PARENT,TableLayout.LayoutParams.MATCH_PARENT,1.0f);
TextView[] ed1 = new TextView[result.length+1];
Button[] plus = new Button[result.length+1];
Button[] minus = new Button[result.length+1];
EditText[] point = new EditText[result.length+1];
TextView[] total = new TextView[result.length+1];
TableRow[] TR= new TableRow[result.length+1];
int[] totalscore = null;
String[] temp = null;
Button btnResult = new Button(player_name.this);
btnResult.setText(" click here to get RESULT");
for(int i=0;i<=(result.length-1);i++) {
ed1[i] = new TextView(player_name.this);
plus[i] = new Button(player_name.this);
minus[i] = new Button(player_name.this);
point[i] = new EditText(player_name.this);
total[i] = new TextView(player_name.this);
TR[i] = new TableRow(player_name.this);
allEds.add(ed1[i]);
alltotal.add(total[i]);
alledit.add(point[i]);
allplus.add(plus[i]);
allminus.add(minus[i]);
TR[i].addView(ed1[i]);
TR[i].addView(point[i]);
TR[i].addView(plus[i]);
TR[i].addView(minus[i]);
TR[i].addView(total[i]);
ply_name.addView(TR[i]);
TR[i].setLayoutParams(tableRowParams);
totalscore[i] =Integer.parseInt(point[i].getText().toString());
temp[i] = "" + totalscore[i];
ed1[i].setId(i);
ed1[i].setHeight(50);
ed1[i].setWidth(70);
ed1[i].setText(result[i]);
ed1[i].setTextColor(Color.CYAN);
total[i].setId(i);
total[i].setHeight(50);
total[i].setWidth(70);
total[i].setText(""+0);
total[i].setTextColor(Color.CYAN);
point[i].setId(i);
point[i].setHeight(50);
point[i].setWidth(120);
point[i].setHint(result[i]+"\'s");
point[i].setInputType(InputType.TYPE_CLASS_NUMBER);
point[i].setTextColor(Color.BLACK);
plus[i].setId(i);
plus[i].setHeight(50);
plus[i].setWidth(50);
plus[i].setText("+");
plus[i].setTextColor(Color.BLACK);
minus[i].setId(i);
minus[i].setHeight(50);
minus[i].setWidth(50);
minus[i].setText("-");
minus[i].setTextColor(Color.BLACK);
plus[i].setOnClickListener(new OnClickListener() {
public void onClick(View v) {
}
});
minus[i].setOnClickListener(new OnClickListener() {
public void onClick(View v) {
}
});
}
LayoutParams lp = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
player_name.addView(btnResult, lp);
btnResult.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Intent intent1 = new Intent(player_name.this,result.class);
startActivity(intent1);
}
});
}
}
You need to check whether the string you are parsing is an integer. Try this code:
if (IsInteger(point[i].getText().toString()))
totalscore[i] =Integer.parseInt(point[i].getText().toString());
and add this function:
public static boolean IsInteger(String s)
{
if (s == null || s.length() == 0) return false;
for(int i = 0; i < s.length(); i++)
{
if (Character.digit(s.charAt(i), 10) < 0)
return false;
}
return true;
}
I hope this helps
actually i am attempting to create a bar-chart.But i am getting the x and y axis values from the web service by consuming it.
There is no problem on getting the values from the web service, but i have only doubts on passing those values to the bar-chart for creating a bar graph.
Because,after getting run of my emulator,i am providing the proper inputs,if i try to invoke the "Invoke" button,its just showing only the blank screen..But i need to draw a bar-chart.How to do this?
Suggestions please.....
thanks for your precious time!..
PLEASE FIND MY SOURCES FOR REFERENCE
Chart.java
public class Chart extends Activity
{
EditText edt1, edt2;
TextView txtv1;
Button btn;
int orderNo = 0;
int freightRate = 0;
int marginPercent;
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
edt1 = (EditText) findViewById(R.id.editText1);
edt2 = (EditText) findViewById(R.id.editText2);
btn = (Button) findViewById(R.id.button1);
btn.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
getTMSChart(edt1.getText().toString(), edt2.getText().toString());
Intent intnt = new Intent(v.getContext(), BarGraphActivity.class);
intnt.putExtra("orderNo", orderNo);
intnt.putExtra("freightRate", freightRate);
//intnt.putExtra("marginPercent", marginPercent);
startActivity(intnt);
}
});
}
public void getTMSChart(String FromDate, String ToDate)
{
System.setProperty("http.keepAlive", "false");
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
String METHOD = "GetTMSChart";
String NAMESPACE = "http://tempuri.org/";
String SOAP_ACTION = "http://tempuri.org/GetTMSChart";
String URL = "http://54.251.60.177/TMSOrdersService/TMSDetails.asmx";
SoapObject request = new SoapObject(NAMESPACE, METHOD);
request.addProperty("FromDate", FromDate);
request.addProperty("ToDate", ToDate);
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
try
{
androidHttpTransport.call(SOAP_ACTION, envelope);
SoapObject result = (SoapObject) envelope.bodyIn;
SoapObject root = (SoapObject) ((SoapObject) (result).getProperty(0)).getProperty("NewDataSet");
int tablesCount = root.getPropertyCount();
for (int i = 0; i < tablesCount; i++)
{
SoapObject table = (SoapObject) root.getProperty(i);
int propertyCount = table.getPropertyCount();
for (int j = 0; j < propertyCount; j++)
{
// String ord = table.getPropertyAsString("");
orderNo = Integer.parseInt(table.getPropertyAsString("Order_No"));
freightRate = Integer.parseInt(table.getPropertyAsString("Freight_Rate"));
//marginPercent = Integer.parseInt(table.getPropertyAsString("Margin_Percent"));
Log.i("Order Number Check : ", ""+orderNo);
Log.i("Freight Rate Check : ", ""+freightRate);
}
}
} catch (Exception e)
{
}
}}
BarGraphACtivity.java
public class BarGraphActivity extends Chart
{
int[] x_axis;
int[] y_axis;
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main1);
x_axis = new int[1];
y_axis = new int[1];
x_axis[0] = getIntent().getIntExtra("orderNo", 0);
y_axis[0] = getIntent().getIntExtra("freightRate", 0);
DrawGraph();
}
public void DrawGraph()
{
String[] titles = new String[] { " Barcharts", "" };
List<int[]> values = new ArrayList<int[]>();
values.add(x_axis);
values.add(y_axis);
int[] colors = new int[] { Color.WHITE, Color.BLACK };
XYMultipleSeriesRenderer renderer = buildBarRenderer(colors);
renderer.setOrientation(Orientation.HORIZONTAL);
setChartSettings(renderer, "some texts", " ", " ", 0, x_axis, 0, y_axis, Color.GRAY, Color.LTGRAY);
renderer.setXLabels(1);
renderer.addXTextLabel(2, "orderNo");
renderer.addYTextLabel(2, "freight");
renderer.setPanEnabled(true, false);
int length = renderer.getSeriesRendererCount();
for (int i = 0; i < length; i++)
{
SimpleSeriesRenderer seriesRenderer = renderer.getSeriesRendererAt(i);
seriesRenderer.setDisplayChartValues(true);
}
ChartFactory.getBarChartIntent(this, buildBarDataset(titles, values), renderer, Type.DEFAULT);
}
public XYMultipleSeriesRenderer buildBarRenderer(int[] colors)
{
// creates a SeriesRenderer and initializes it with useful default values as well as colors
XYMultipleSeriesRenderer renderer = new XYMultipleSeriesRenderer();
renderer.setAxisTitleTextSize(15);
renderer.setChartTitleTextSize(20);
renderer.setLabelsTextSize(15);
renderer.setLegendTextSize(15);
int length = colors.length;
for (int i = 0; i < length; i++)
{
SimpleSeriesRenderer r = new SimpleSeriesRenderer();
r.setColor(colors[i]);
renderer.addSeriesRenderer(r);
}
return renderer;
}
public void setChartSettings(XYMultipleSeriesRenderer renderer, String title, String xTitle, String yTitle,
int xMin, int[] x_axis, int yMin, int[] y_axis, int axesColor, int labelsColor)
{
// sets lots of default values for this renderer
renderer.setChartTitle(title);
renderer.setXTitle(xTitle);
renderer.setYTitle(yTitle);
renderer.setXAxisMin(xMin);
renderer.setYAxisMin(yMin);
renderer.setAxesColor(axesColor);
renderer.setLabelsColor(labelsColor);
renderer.setApplyBackgroundColor(true);
renderer.setBackgroundColor(Color.GRAY);
}
public XYMultipleSeriesDataset buildBarDataset(String[] titles, List<int[]> values)
{
// adds the axis titles and values into the dataset
XYMultipleSeriesDataset dataset = new XYMultipleSeriesDataset();
int length = titles.length;
for (int i = 0; i < length; i++)
{
CategorySeries series = new CategorySeries(titles[i]);
int[] v = values.get(i);
int seriesLength = v.length;
for (int k = 0; k < seriesLength; k++)
{
series.add(v[k]);
}
dataset.addSeries(series.toXYSeries());
}
return dataset;
}
}
I am trying to consume a web service from android by the method SOAP.
Here my problem is,actually i am getting two values from that web service namely "OrderNo" and "FreightRate" and i am trying to show these values in each Text-view boxes of the next screen but i am getting nothing on the text view boxes,
How to achieve this concept?Suggestions please..
NOTE :- I can able to show only any one values in the text view box of the another screen if i consume any one values like "orderNo" or "FreightRate". But unable to show two values simultaneously in separate text-view boxes of the another screen.
Please find my sources for reference
Main_WB.java
public class Main_WB extends Activity
{
EditText edt1,edt2;
//TextView txt_1;
Button btn;
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
edt1 = (EditText)findViewById(R.id.editText1);
edt2 = (EditText)findViewById(R.id.editText2);
btn = (Button)findViewById(R.id.button1);
btn.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
getTMSChart(edt1.getText().toString(),edt2.getText().toString());
// Intent myint = new Intent(Main_WB.this,ResultActivity.class);
// startActivity(myint);
}
});
}
private void getTMSChart(String FromDate,String ToDate)
{
// txt_1 = (TextView)findViewById(R.id.textView1);
System.setProperty("http.keepAlive", "false");
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
String NAMESPACE = "http://tempuri.org/";
String URL = "http://54.251.60.177/TMSOrdersService/TMSDetails.asmx";
String METHOD = "GetTMSChart";
SoapObject request = new SoapObject(NAMESPACE, METHOD);
request.addProperty("FromDate", FromDate);
request.addProperty("ToDate", ToDate);
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
try
{
androidHttpTransport.call(NAMESPACE + METHOD, envelope);
SoapObject result = (SoapObject) envelope.bodyIn;
SoapObject root = (SoapObject) ((SoapObject)(result).getProperty(0)).getProperty("NewDataSet");
int tablesCount = root.getPropertyCount();
for (int i = 0; i < tablesCount; i++)
{
SoapObject table = (SoapObject) root.getProperty(i);
int propertyCount = table.getPropertyCount();
// String[] ord = new String[propertyCount];
// String[] fre = new String[propertyCount];
// int[] fre = new int[propertyCount];
// int[] margin = new int[propertyCount];
for (int j = 0; j < propertyCount; j++)
{
String x,y;
// int orderNo = Integer.parseInt(table.getPropertyAsString("Order_No"));
// int freightRate = Integer.parseInt(table.getPropertyAsString("Freight_Rate"));
// int marginPercent = Integer.parseInt(table.getPropertyAsString("Margin_Percent"));
String orderNo = table.getPropertyAsString("Order_No");
String freight = table.getAttributeAsString("Freight_Rate");
x = orderNo.toString();
y = freight.toString();
Intent in = new Intent(getApplicationContext(),ResultActivity.class);
in.putExtra("gotonextpage",x);
in.putExtra("gotonextpage", y);
startActivity(in);
//ord[j] = orderNo;
// fre[j] = freightRate;
// margin[j]= marginPercent;
// x = orderNo.toString();
// y = fre.toString();
// Intent myIntent = new Intent(Main_WB.this, ResultActivity.class);
// myIntent.putExtra("gotonextpage", x);
// startActivity(myIntent);
// whatever you do with these values
}
}
}
catch (Exception e)
{
}
} }
ResultActivity.java
public class ResultActivity extends Activity
{
String x,y;
TextView txt1,txt2;
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main1);
Bundle extras = getIntent().getExtras();
if(extras != null)
{
x = extras.getString("gotonextpage");
y = extras.getString("gotonextpage");
}
else
{
}
txt1 = (TextView)findViewById(R.id.txtVw);
txt2 = (TextView)findViewById(R.id.txtVw2);
txt1.setText(x);
txt2.setText(y);
}}
Thanks for your precious time!..
Maybe this is not your problem but, in your main activity you're trying to send both values with your intent but you are adding them using the same key. In your example you are always sending value y because you're overwriting the x value.
in.putExtra("gotonextpage",x);
in.putExtra("gotonextpage", y);
If I understand your problem correctly, you need to use two different keys for your values, when sending them with the intent, and extracting them.
in.putExtra("gotonextpageX",x);
in.putExtra("gotonextpageY", y);
x = extras.getString("gotonextpageX");
y = extras.getString("gotonextpageY");
Another way to do it is
x = getIntent().getStringExtra("gotonextpageX");
y = getIntent().getStringExtra("gotonextpageY");
I am consuming a web service by soap method from Android. And I am showing the values from that web service in to two separate text views on the next screen.
Here that web service is returning two values. But I'm only able to show one value from that web service in text view on the next screen.
But I need to show both values in two separate textview boxes on the next screen....
How can I do this?
Suggestions please..
NOTE :- The input value for that web service is for FromDate : 01/01/2012 and
for ToDate : 07/07/2012
Please find my sources for reference
Main_WB.java
public class Main_WB extends Activity
{
EditText edt1,edt2;
//TextView txt_1;
Button btn;
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
edt1 = (EditText)findViewById(R.id.editText1);
edt2 = (EditText)findViewById(R.id.editText2);
btn = (Button)findViewById(R.id.button1);
btn.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
getTMSChart(edt1.getText().toString(),edt2.getText().toString());
Intent myint = new Intent(Main_WB.this,ResultActivity.class);
startActivity(myint);
}
});
}
private void getTMSChart(String FromDate,String ToDate)
{
// txt_1 = (TextView)findViewById(R.id.textView1);
System.setProperty("http.keepAlive", "false");
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
String NAMESPACE = "http://tempuri.org/";
String URL = "http://54.251.60.177/TMSOrdersService/TMSDetails.asmx";
String METHOD = "GetTMSChart";
SoapObject request = new SoapObject(NAMESPACE, METHOD);
request.addProperty("FromDate", FromDate);
request.addProperty("ToDate", ToDate);
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
try
{
androidHttpTransport.call(NAMESPACE + METHOD, envelope);
SoapObject result = (SoapObject) envelope.bodyIn;
SoapObject root = (SoapObject) ((SoapObject)(result).getProperty(0)).getProperty("NewDataSet");
int tablesCount = root.getPropertyCount();
for (int i = 0; i < tablesCount; i++)
{
SoapObject table = (SoapObject) root.getProperty(i);
int propertyCount = table.getPropertyCount();
// String[] ord = new String[propertyCount];
// String[] fre = new String[propertyCount];
// int[] fre = new int[propertyCount];
// int[] margin = new int[propertyCount];
for (int j = 0; j < propertyCount; j++)
{
String x,y;
// int orderNo = Integer.parseInt(table.getPropertyAsString("Order_No"));
// int freightRate = Integer.parseInt(table.getPropertyAsString("Freight_Rate"));
// int marginPercent = Integer.parseInt(table.getPropertyAsString("Margin_Percent"));
String orderNo = table.getPropertyAsString("Order_No");
String freight = table.getAttributeAsString("Freight_Rate");
x = orderNo.toString();
y = freight.toString();
Intent in = new Intent(getApplicationContext(),ResultActivity.class);
in.putExtra("gotonextpageX",x);
in.putExtra("gotonextpageY", y);
startActivity(in);
//ord[j] = orderNo;
// fre[j] = freightRate;
// margin[j]= marginPercent;
// x = orderNo.toString();
// y = fre.toString();
// Intent myIntent = new Intent(Main_WB.this, ResultActivity.class);
// myIntent.putExtra("gotonextpage", x);
// startActivity(myIntent);
// whatever you do with these values
}
}
}
catch (Exception e)
{
}
} }
ResultActivity.java
public class ResultActivity extends Activity
{
String x,y;
TextView txt1,txt2;
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main1);
Bundle extras = getIntent().getExtras();
if(extras != null)
{
x = extras.getString("gotonextpageX");
y = extras.getString("gotonextpageY");
}
else
{
}
txt1 = (TextView)findViewById(R.id.txtVw);
txt2 = (TextView)findViewById(R.id.txtVw2);
txt1.setText(x);
txt2.setText(y);
}}
Thanks for your precious time!..
Here check it out ...
public class Main_WB extends Activity {
EditText edt1, edt2;
// TextView txt_1;
Button btn;
ArrayList<String> result;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
edt1 = (EditText) findViewById(R.id.editText1);
edt2 = (EditText) findViewById(R.id.editText2);
btn = (Button) findViewById(R.id.button1);
result = new ArrayList<String>();
btn.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
result.addAll(getTMSChart(edt1.getText().toString(), edt2.getText().toString()));
Intent in = new Intent(getApplicationContext(), ResultActivity.class);
in.putExtra("gotonextpageX", result.get(0));
in.putExtra("gotonextpageY", result.get(1));
startActivity(in);
}
});
}
private ArrayList<String> getTMSChart(String FromDate, String ToDate) {
// txt_1 = (TextView)findViewById(R.id.textView1);
System.setProperty("http.keepAlive", "false");
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
String NAMESPACE = "http://tempuri.org/";
String URL = "http://54.251.60.177/TMSOrdersService/TMSDetails.asmx";
String METHOD = "GetTMSChart";
SoapObject request = new SoapObject(NAMESPACE, METHOD);
request.addProperty("FromDate", FromDate);
request.addProperty("ToDate", ToDate);
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
String x = "", y = "";
ArrayList<String> stringResult = new ArrayList<String>();
try {
androidHttpTransport.call(NAMESPACE + METHOD, envelope);
SoapObject result = (SoapObject) envelope.bodyIn;
SoapObject root = (SoapObject) ((SoapObject) (result).getProperty(0)).getProperty("NewDataSet");
int tablesCount = root.getPropertyCount();
for (int i = 0; i < tablesCount; i++) {
SoapObject table = (SoapObject) root.getProperty(i);
int propertyCount = table.getPropertyCount();
for (int j = 0; j < propertyCount; j++) {
stringResult.add(table.getPropertyAsString("Order_No").toString());
stringResult.add(table.getPropertyAsString("Freight_Rate").toString());
}
}
} catch (Exception e) {
}
return stringResult;
}
}
And dont change your second class, this must work.