- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我正在将三个(客户名称、开始日期和结束日期)值传递给 PHP 文件,但背后的问题是,我当时没有传递三个值,只有一个值(客户名称)移动到 PHP 文件。并且如何在多列列表中显示日期
java文件:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.customer_repo);
// Permission StrictMode
if (android.os.Build.VERSION.SDK_INT > 9) {
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
}
setCurrentDateOnView();
addListenerOnButton();
cus_name = (Spinner) findViewById(R.id.spinner1);//customer spinner
created_date1 = (TextView) findViewById(R.id.tvDate);
created_date2 = (TextView) findViewById(R.id.tvDate2);
//spinner for customer name
cus_name = (Spinner) findViewById(R.id.spinner1);
adapter = new ArrayAdapter<String>(this, R.layout.spinner_custo_report, R.id.txt, listItems);
cus_name.setAdapter(adapter);
cus_name.setAdapter(new NothingSelectedSpinnerAdapter(adapter, R.layout.custo_rep_nothingselect, this));
Button submit = (Button) findViewById(R.id.loadbtn);
assert submit != null;
submit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
cus_names = cus_name.getSelectedItem().toString();
createddate = created_date1.getText().toString();
created_date = created_date2.getText().toString();
String url_server = "http://192.168.1.13:8090/Vaari_services/getCustomerReportData.php";
new BackgroundTask_Asycn().execute(url_server);
}
});
}
// Class with extends AsyncTask class
//product stock one
private class BackgroundTask_Asycn extends AsyncTask<String, Void, Void> {
// Required initialization
private final HttpClient Client = new DefaultHttpClient();
private String Content;
private String Error = null;
private ProgressDialog Dialog = new ProgressDialog(Customer_Repo.this);
String cus_name ="";
String created_date1 ="";
String created_date2 ="";
int sizeData = 0;
TextView pro_stock1 = (TextView)findViewById(R.id.tvDate);
Spinner customerName = (Spinner)findViewById(R.id.spinner1);
TextView createddate1 = (TextView) findViewById(R.id.tvDate);
TextView createddate2 = (TextView) findViewById(R.id.tvDate2);
protected void onPreExecute() {
// NOTE: You can call UI Element here.
//Start Progress Dialog (Message)
Dialog.setMessage("Please wait..");
Dialog.show();
try{
// Set Request parameter product one
cus_name +="&" + URLEncoder.encode("cus_name", "UTF-8") + "="+customerName.getSelectedItem();
//created_date1 +="&" + URLEncoder.encode("created_date1", "UTF-8") + "="+createddate1.getText();
//created_date2 +="&" + URLEncoder.encode("created_date2", "UTF-8") + "="+createddate2.getText();
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
// Call after onPreExecute method
protected Void doInBackground(String... urls) {
/************ Make Post Call To Web Server ***********/
BufferedReader reader=null;
// Send data
try
{
// Defined URL where to send data
URL url = new URL(urls[0]);
// Send POST data request
URLConnection conn = url.openConnection();
conn.setDoOutput(true);
OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
wr.write(cus_name);
//wr.write(created_date1);
//wr.write(created_date2);
wr.flush();
// Get the server response
reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
StringBuilder sb = new StringBuilder();
String line = null;
// Read Server Response
while((line = reader.readLine()) != null)
{
// Append server response in string
sb.append(line + "");
}
// Append Server Response To Content String
Content = sb.toString();
}
catch(Exception ex)
{
Error = ex.getMessage();
}
finally
{
try
{
reader.close();
}
catch(Exception ex) {}
}
return null;
}
protected void onPostExecute(Void unused) {
// NOTE: You can call UI Element here.
// Close progress dialog
Dialog.dismiss();
if (Error != null) {
pro_stock1.setText("Output : "+Error);
} else {
// Show Response Json On Screen (activity)
pro_stock1.setText( Content );
/****************** Start Parse Response JSON Data *************/
String OutputData = "";
JSONObject jsonResponse;
try {
/****** Creates a new JSONObject with name/value mappings from the JSON string. ********/
jsonResponse = new JSONObject(Content);
/***** Returns the value mapped by name if it exists and is a JSONArray. ***/
/******* Returns null otherwise. *******/
JSONArray jsonMainNode = jsonResponse.optJSONArray("customer_repo");
/*********** Process each JSON Node ************/
int lengthJsonArr = jsonMainNode.length();
for(int i=0; i < lengthJsonArr; i++)
{
/****** Get Object for each JSON node.***********/
JSONObject jsonChildNode = jsonMainNode.getJSONObject(i);
/******* Fetch node values **********/
String Stock1 = jsonChildNode.optString("created_date").toString();
String Stock2 = jsonChildNode.optString("order_no").toString();
String Stock3 = jsonChildNode.optString("product").toString();
OutputData += Stock1 + Stock2 + Stock3;
}
/****************** End Parse Response JSON Data *************/
//Show Parsed Output on screen (activity)
pro_stock1.setText( OutputData );
} catch (JSONException e) {
e.printStackTrace();
}
}
}
}
这是问题的开始,如何传递我必须做的事情。如果有任何选择
cus_name +="&" + URLEncoder.encode("cus_name", "UTF-8") + "="+customerName.getSelectedItem();
//created_date1 +="&" + URLEncoder.encode("created_date1", "UTF-8") + "="+createddate1.getText();
//created_date2 +="&" + URLEncoder.encode("created_date2", "UTF-8") + "="+createddate2.getText();
这是正确的方法
wr.write(cus_name);
//wr.write(created_date1);
//wr.write(created_date2);
XML 文件:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#282828"
android:orientation="vertical"
android:padding="10dp">
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tableLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#282828"
android:padding="10dp"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:orientation="vertical"
android:padding="2dp">
<TableRow
android:id="@+id/tableRow2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="5dp">
<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:gravity="center_horizontal"
android:text="CUSTOMER ORDER REPORT"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#00aa55"
android:textSize="30dp"
android:textStyle="bold" />
</TableRow>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:orientation="vertical"
android:padding="5dp">
<TableRow
android:id="@+id/tableRow3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="2dp">
<Spinner
android:id="@+id/spinner1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="1dp"
android:textSize="20sp" />
</TableRow>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:orientation="vertical"
android:padding="2dp">
<TableRow
android:id="@+id/tableRow1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="2dp">
<Button
android:id="@+id/btnChangeDate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/datepicker_btn"
android:padding="5dp"
android:text="FROM DATE"
android:textColor="#ffffff"
android:textSize="20sp"
android:textStyle="bold" />
<Button
android:id="@+id/btnChangeDate2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:background="@drawable/datepicker_btn"
android:padding="10dp"
android:text="TO DATE"
android:textColor="#ffffff"
android:textSize="20sp"
android:textStyle="bold" />
<TextView
android:id="@+id/tvDate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text=""
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#FFFFFF"
android:textStyle="bold" />
<TextView
android:id="@+id/tvDate2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#FFFFFF"
android:textStyle="bold" />
</TableRow>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:orientation="vertical"
android:padding="2dp">
<TableRow
android:id="@+id/tableRow4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="2dp">
<Button
android:id="@+id/loadbtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/btnbg"
android:padding="10dp"
android:text="LOAD"
android:textColor="#ffffff"
android:textSize="20sp"
android:textStyle="bold" />
</TableRow>
</LinearLayout>
<HorizontalScrollView
android:id="@+id/horizontalScrollView1"
android:layout_width="fill_parent"
android:layout_height="match_parent">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<!-- table format-->
<LinearLayout
android:id="@+id/relativeLayout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@color/colorCell">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:padding="5dp"
android:text="ORDER DATE"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#FFFFFF"
android:textStyle="bold" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
android:gravity="center"
android:padding="5dp"
android:text="ORDER NO"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#FFFFFF"
android:textStyle="bold" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1.5"
android:gravity="center"
android:padding="5dp"
android:text="PRODUCT NAME"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#FFFFFF"
android:textStyle="bold" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:padding="5dp"
android:text="ORDER QTY"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#FFFFFF"
android:textStyle="bold" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:padding="5dp"
android:text="SUPPLIED QTY"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#FFFFFF"
android:textStyle="bold" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:padding="5dp"
android:text="SUPPLIED DATE"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#FFFFFF"
android:textStyle="bold" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:padding="5dp"
android:text="BALANCE QTY"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#FFFFFF"
android:textStyle="bold" />
</LinearLayout>
</ScrollView>
</HorizontalScrollView>
<ListView
android:id="@+id/listview_customername"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:divider="@null" />
</TableLayout>
</RelativeLayout>
PHP 文件:
<?php
require "db_config.php";
$cus_name= $_POST["cus_name"];
$created_date1= $_POST['created_date1'];
$created_date2= $_POST['created_date2'];
$sql="select oc.created_date,oc.order_no,ot.product,ot.order_qty,ot.qty_supply as Supplied_qty,ot.sup_date as issue_date,ot.bal_qty from order_creation oc inner join order_tran ot on oc.order_no=ot.orderno where oc.cus_name='".$cus_name."' and convert(datetime,ot.sup_date,104) between convert(datetime,'".$created_date1."') and convert(datetime, '".$created_date2."') and ot.product is not null order by ot.product,oc.order_no,ot.bal_qty desc";
$stmt=sqlsrv_query($conn,$sql );
if($stmt===false)
{
die(print_r(sqlsrv_errors(),true));
}
while($row=sqlsrv_fetch_array($stmt,SQLSRV_FETCH_ASSOC))
{
$json['customer_repo'][]=$row;
}
sqlsrv_free_stmt($stmt);
echo json_encode($json);
?>
最佳答案
对数据集使用数据模型类而不是 HashMap 。
public class CustomerData {
String createdAt;
String orderNo;
public CustomerData(String createdAt, String orderNo) {
this.createdAt = createdAt;
this.orderNo = orderNo;
}
public String getCreatedAt() {
return createdAt;
}
public String getOrderNo() {
return orderNo;
}
}
然后像这样修改你的代码
public void ShowData() {
// listView1
final ListView lisView1 = (ListView) findViewById(R.id.listview_customername);
Spinner cus_name = (Spinner) findViewById(R.id.spinner1);
TextView created_date1 = (TextView) findViewById(R.id.tvDate);
TextView created_date2 = (TextView) findViewById(R.id.tvDate2);
String url = "http://192.168.1.13:8090/Vaari_services/getCustomerReportData.php";
// Paste Parameters
//List<NameValuePair> params = new ArrayList<NameValuePair>();
new GetCustomerDataTask().execute(url);
}
private class GetCustomerDataTask extends AsyncTask<String, Void, String> {
@Override
protected String doInBackground(String... urls) {
// params comes from the execute() call: params[0] is the url.
try {
return downloadUrl(urls[0]);
} catch (IOException e) {
return "Unable to retrieve web page. URL may be invalid.";
}
}
// onPostExecute displays the results of the AsyncTask.
@Override
protected void onPostExecute(String result) {
parseData(result);
}
}
// Given a URL, establishes an HttpUrlConnection and retrieves
// the web page content as a InputStream, which it returns as
// a string.
private String downloadUrl(String myurl) throws IOException {
InputStream is = null;
// Only display the first 500 characters of the retrieved
// web page content.
int len = 500;
List<NameValuePair> params = new ArrayList<>();
params.add(new BasicNameValuePair("cus_name", cus_names);
params.add(new BasicNameValuePair("created_date1", createddate);
params.add(new BasicNameValuePair("created_date2", created_date);
try {
URL url = new URL(myurl);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setReadTimeout(10000 /* milliseconds */);
conn.setConnectTimeout(15000 /* milliseconds */);
conn.setRequestMethod("POST");
conn.setDoInput(true);
// Starts the query
conn.connect();
int response = conn.getResponseCode();
Log.d(DEBUG_TAG, "The response is: " + response);
is = conn.getInputStream();
// Convert the InputStream into a string
String contentAsString = readIt(is, len);
return contentAsString;
// Makes sure that the InputStream is closed after the app is
// finished using it.
} finally {
if (is != null) {
is.close();
}
}
}
public void parseData(String response){
try {
JSONObject parentObject = new JSONObject(response);
JSONArray data = parentObject.getJSONArray("customer_repo");
//JSONArray data = new JSONArray(getJSONUrl(url,params));
ArrayList<CustomerData> customerArrayList = new ArrayList<CustomerData>();
for (int i = 0; i < data.length(); i++) {
JSONObject c = data.getJSONObject(i);
String createdDate = c.getString("created_date");
String orderNo = c.getString("created_date");
customerArrayList.add(new CustomerData(createdDate, orderNo));
}
imageAdapter = new ImageAdapter(this, customerArrayList);
lisView1.setAdapter(imageAdapter);
imageAdapter.notifyDataSetChanged();
registerForContextMenu(lisView1);
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public class ImageAdapter extends BaseAdapter {
private Context context;
ArrayList<CustomerData> customerDataArrayList;
public ImageAdapter(Context c,ArrayList<CustomerData> customerDataArrayList) {
// TODO Auto-generated method stub
context = c;
this.customerDataArrayList= customerDataArrayList;
}
public int getCount() {
// TODO Auto-generated method stub
return customerDataArrayList.size();
}
public Object getItem(int position) {
// TODO Auto-generated method stub
return customerDataArrayList.get(position);
}
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
public View getView(final int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if (convertView == null) {
convertView = inflater.inflate(R.layout.activity_cus_report, null);
}
// created date
TextView txtOrdDate = (TextView) convertView.findViewById(R.id.ColOrDate);
txtOrdDate.setPadding(10, 0, 0, 0);
txtOrdDate.setText(customerDataArrayList.get(position).getCreatedAt() + ".");
txtOrdDate.setTextSize(18);
txtOrdDate.setTextColor(Color.parseColor("#FFFFFF"));
// Oredr No
TextView txtOrdNo = (TextView) convertView.findViewById(R.id.ColOrNo);
txtOrdNo.setPadding(5, 0, 0, 0);
txtOrdNo.setText(customerDataArrayList.get(position).getOrderNo());
txtOrdNo.setTextSize(18);
txtOrdNo.setTextColor(Color.parseColor("#FFFFFF"));
return convertView;
}
}
同时发布你的getJSONUrl方法
关于android - 如何在android中的两个不同日期从MySQL获取数据并在多列ListView中显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37983162/
我需要将文本放在 中在一个 Div 中,在另一个 Div 中,在另一个 Div 中。所以这是它的样子: #document Change PIN
奇怪的事情发生了。 我有一个基本的 html 代码。 html,头部, body 。(因为我收到了一些反对票,这里是完整的代码) 这是我的CSS: html { backgroun
我正在尝试将 Assets 中的一组图像加载到 UICollectionview 中存在的 ImageView 中,但每当我运行应用程序时它都会显示错误。而且也没有显示图像。 我在ViewDidLoa
我需要根据带参数的 perl 脚本的输出更改一些环境变量。在 tcsh 中,我可以使用别名命令来评估 perl 脚本的输出。 tcsh: alias setsdk 'eval `/localhome/
我使用 Windows 身份验证创建了一个新的 Blazor(服务器端)应用程序,并使用 IIS Express 运行它。它将显示一条消息“Hello Domain\User!”来自右上方的以下 Ra
这是我的方法 void login(Event event);我想知道 Kotlin 中应该如何 最佳答案 在 Kotlin 中通配符运算符是 * 。它指示编译器它是未知的,但一旦知道,就不会有其他类
看下面的代码 for story in book if story.title.length < 140 - var story
我正在尝试用 C 语言学习字符串处理。我写了一个程序,它存储了一些音乐轨道,并帮助用户检查他/她想到的歌曲是否存在于存储的轨道中。这是通过要求用户输入一串字符来完成的。然后程序使用 strstr()
我正在学习 sscanf 并遇到如下格式字符串: sscanf("%[^:]:%[^*=]%*[*=]%n",a,b,&c); 我理解 %[^:] 部分意味着扫描直到遇到 ':' 并将其分配给 a。:
def char_check(x,y): if (str(x) in y or x.find(y) > -1) or (str(y) in x or y.find(x) > -1):
我有一种情况,我想将文本文件中的现有行包含到一个新 block 中。 line 1 line 2 line in block line 3 line 4 应该变成 line 1 line 2 line
我有一个新项目,我正在尝试设置 Django 调试工具栏。首先,我尝试了快速设置,它只涉及将 'debug_toolbar' 添加到我的已安装应用程序列表中。有了这个,当我转到我的根 URL 时,调试
在 Matlab 中,如果我有一个函数 f,例如签名是 f(a,b,c),我可以创建一个只有一个变量 b 的函数,它将使用固定的 a=a1 和 c=c1 调用 f: g = @(b) f(a1, b,
我不明白为什么 ForEach 中的元素之间有多余的垂直间距在 VStack 里面在 ScrollView 里面使用 GeometryReader 时渲染自定义水平分隔线。 Scrol
我想知道,是否有关于何时使用 session 和 cookie 的指南或最佳实践? 什么应该和什么不应该存储在其中?谢谢! 最佳答案 这些文档很好地了解了 session cookie 的安全问题以及
我在 scipy/numpy 中有一个 Nx3 矩阵,我想用它制作一个 3 维条形图,其中 X 轴和 Y 轴由矩阵的第一列和第二列的值、高度确定每个条形的 是矩阵中的第三列,条形的数量由 N 确定。
假设我用两种不同的方式初始化信号量 sem_init(&randomsem,0,1) sem_init(&randomsem,0,0) 现在, sem_wait(&randomsem) 在这两种情况下
我怀疑该值如何存储在“WORD”中,因为 PStr 包含实际输出。? 既然Pstr中存储的是小写到大写的字母,那么在printf中如何将其给出为“WORD”。有人可以吗?解释一下? #include
我有一个 3x3 数组: var my_array = [[0,1,2], [3,4,5], [6,7,8]]; 并想获得它的第一个 2
我意识到您可以使用如下方式轻松检查焦点: var hasFocus = true; $(window).blur(function(){ hasFocus = false; }); $(win
我是一名优秀的程序员,十分优秀!