现在我正在使用 android 中的一项 Web 服务。该 Web 服务有两个输入值,分别是 01/01/2012 和 07/07/2012。
单击调用按钮并提供这些作为输入值后,我的项目将显示一些条形图。它工作正常。这里我使用两个编辑文本框来获取这些输入值。
但我想使用日期选择器小部件而不是使用编辑文本框。所以我拖动了日期选择器小部件并做了一些代码。
但现在的问题是,输入值完全是数字和反斜杠,对吧?但是在日期选择器小部件中,它以字符和数字的组合显示输入值,但我只需要使用日期选择器小部件。
日期选择器小部件采用这种格式 dd-mm-yyyy 例如:- 01-jan-1990
但我需要将上述格式转换为 01/01/1990。这个怎么做?
请找到我的参考资料来源
图表.java
public class Chart extends Activity
{
//EditText edt1, edt2;
DatePicker dp1,dp2;
TextView txtv1;
Button btn;
Bundle data;
String[] orderNo = new String[20];
int[] freightRate = new int[20];
int[] marginPercent = new int[20];
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
dp1 = (DatePicker) findViewById(R.id.datePicker_one);
dp2 = (DatePicker) findViewById(R.id.datePicker_Two);
String res_1 = dp1.getDayOfMonth()+"/"+dp1.getMonth()+"/"+dp1.getYear();
String res_2 = dp2.getDayOfMonth()+"/"+dp2.getMonth()+"/"+dp2.getYear();
btn = (Button) findViewById(R.id.button1);
btn.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
getTMSChart(dp1.getYear(), dp2.getYear());
Intent intnt = new Intent(v.getContext(), BarGraphActivity.class);
intnt.putExtras(data);
startActivity(intnt);
}
});
}
public void getTMSChart(int j, int k)
{
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", j);
request.addProperty("ToDate", k);
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();
} } }
条形图活动.java
public class BarGraphActivity extends Activity {
String[] orderNo = new String[20];
int[] freightRate = new int[20];
int[] marginPercent = new int[20];
int count;
RelativeLayout rltv;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main1);
final GraphicalView grfv = createIntent();
RelativeLayout rltv = (RelativeLayout)findViewById(R.id.rlyot);
rltv.addView(grfv);
}
public GraphicalView createIntent()
{
rltv = (RelativeLayout)findViewById(R.id.rlyot);
String[] titles = new String[] { "Order's profit of the year", " " };
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]);
Thread th = new Thread();
try
{
Thread.sleep(2000);
}
catch (InterruptedException e)
{
e.printStackTrace();
}
}
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);
mRenderer.setXLabelsColor(Color.WHITE);
mRenderer.setYLabelsColor(0,Color.WHITE);
mRenderer.setZoomButtonsVisible(true);
mRenderer.setApplyBackgroundColor(true);
mRenderer.setBackgroundColor(Color.parseColor("#000000"));
mRenderer.setBarSpacing(0.7f);
// mRenderer.setChartTitleTextSize(20);
// mRenderer.setLabelsTextSize(25);
// mRenderer.setMarginsColor(Color.WHITE);
final GraphicalView grfv = ChartFactory.getBarChartView(BarGraphActivity.this, dataset, mRenderer, Type.DEFAULT);
return grfv;
}
return null;
}
}
任何想法?
感谢您宝贵的时间!..