Java 如何在EclipseAndroid中声明输入日期
我想要输入日期,但我不知道如何在EclipseAndroid中声明日期 这是我的密码Java 如何在EclipseAndroid中声明输入日期,java,android,eclipse,date,android-asynctask,Java,Android,Eclipse,Date,Android Asynctask,我想要输入日期,但我不知道如何在EclipseAndroid中声明日期 这是我的密码 EditText txtdate; 然后 protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_form_lelang); txtdate = (EditText)findViewById(
EditText txtdate;
然后
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_form_lelang);
txtdate = (EditText)findViewById(R.id.txtdate);
这段代码是我的异步任务线程
protected String doInBackground(String... params) {
param.add(new BasicNameValuePair("date", txtdate.getText().toString()));
im在哪里编写代码声明txtdate(日期) package com.example.lelangifan;
导入java.util.ArrayList;
导入java.util.List;
导入org.apache.http.NameValuePair;
导入org.apache.http.message.BasicNameValuePair;
导入org.json.JSONArray;
导入org.json.JSONException;
导入org.json.JSONObject;
导入com.example.lelangifan.Daftar;
导入com.example.lelangifan.ServiceHandler;
导入android.os.AsyncTask;
导入android.os.Bundle;
导入android.app.Activity;
导入android.content.Intent;
导入android.util.Log;
导入android.view.Menu;
导入android.view.view;
导入android.view.view.OnClickListener;
导入android.widget.Button;
导入android.widget.EditText;
公共类FormLelang扩展活动实现OnClickListener{
编辑文本txtjudul;
编辑文本txtharga;
编辑文本txtdate;
按钮BTN创建;
JSONArray tag_besar;
int成功=0;
int cek_用户名=0;
AlertDialogManager alert=新建AlertDialogManager();
专用静态字符串url=”http://172.16.10.14/mobile_lelang/create_lelang.php";
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity\u form\u lelang);
txtjudul=(EditText)findViewById(R.id.txtjudul);
txtharga=(EditText)findViewById(R.id.txtharga);
txtdate=(EditText)findViewById(R.id.txtdate);
btncreate=(按钮)findViewById(R.id.btncreate);
btncreate.setOnClickListener(此);
}
@凌驾
公共布尔onCreateOptions菜单(菜单){
//为菜单充气;这会将项目添加到操作栏(如果存在)。
getMenuInflater().充气(R.menu.daftar,menu);
返回true;
}
公共void onClick(视图){
//TODO自动生成的方法存根
如果(视图==btncreate){
新建createJson().execute();
}
}
类createJson扩展异步任务{
整数形式_cek=0;
@凌驾
受保护的void onPreExecute(){
super.onPreExecute();
if(txtjudul.getText().toString()==null)
{
alert.showAlertDialog(FormLelang.this,“信息”,“Isi Judul”,false);
//T_nama_d.聚焦研究(0);
表格cek=1;
}
}
@凌驾
受保护的字符串doInBackground(字符串…参数){
//TODO自动生成的方法存根
if(txtjudul.getText().length()==0)
{
表格cek=1;
}
else if(txtharga.getText().length()=0)
{
alert.showAlertDialog(FormLelang.this,“Info”,“Harga Kosong”,false);
表格cek=1;
}
else if(txtdate.getText().length()=0)
{
alert.showAlertDialog(FormLelang.this,“信息”,“Isi限制日期”,false);
表格cek=1;
}
if(form_cek==0){
//Log.d(“Form->”,String.valueOf(Form_cek));
ServiceHandler sh=新的ServiceHandler();
List param=new ArrayList();
param.add(新的BasicNameValuePair(“judul”,txtjudul.getText().toString());
add(新的BasicNameValuePair(“harga”,txthagga.getText().toString());
add(新的BasicNameValuePair(“date”,txtdate.getText().toString());
//参数add(新的BasicNameValuePair(“jenis_kelamin”,T_jenis kelamin_d.getSelectedItem().toString());
字符串jsonstrr=sh.makeServiceCall(url,ServiceHandler.POST,param);
试一试{
JSONObject jsonobjj=新的JSONObject(jsonstrr);
tag_besar=jsonobjj.getJSONArray(“数据”);
对于(int j=0;j
它在您的编辑文本中打印日期吗?但是它不工作,在eclipse日期中,我想必须声明它,您是否可以添加完整的源代码?好的。在doinBackground
中创建一个本地字符串,获取edittext的值,并将该字符串用于if-else
语句,然后将它们放入json中。
package com.example.lelangifan;
import java.util.ArrayList;
import java.util.List;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import com.example.lelangifan.Daftar;
import com.example.lelangifan.ServiceHandler;
import android.os.AsyncTask;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
public class FormLelang extends Activity implements OnClickListener {
EditText txtjudul;
EditText txtharga;
EditText txtdate;
Button btncreate;
JSONArray tag_besar;
int success = 0;
int cek_username = 0;
AlertDialogManager alert = new AlertDialogManager();
private static String url ="http://172.16.10.14/mobile_lelang/create_lelang.php";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_form_lelang);
txtjudul = (EditText)findViewById(R.id.txtjudul);
txtharga = (EditText)findViewById(R.id.txtharga);
txtdate = (EditText)findViewById(R.id.txtdate);
btncreate = (Button)findViewById(R.id.btncreate);
btncreate.setOnClickListener(this);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.daftar, menu);
return true;
}
public void onClick(View view) {
// TODO Auto-generated method stub
if(view == btncreate){
new createJson().execute();
}
}
class createJson extends AsyncTask<String, String, String>{
Integer form_cek = 0;
@Override
protected void onPreExecute(){
super.onPreExecute();
if(txtjudul.getText().toString() == null)
{
alert.showAlertDialog(FormLelang.this, "Info", "Isi Judul", false);
//T_nama_d.focusSearch(0);
form_cek = 1;
}
}
@Override
protected String doInBackground(String... params) {
// TODO Auto-generated method stub
if(txtjudul.getText().length() == 0)
{
form_cek = 1;
}
else if(txtharga.getText().length() == 0)
{
alert.showAlertDialog(FormLelang.this, "Info", "Harga Kosong", false);
form_cek = 1;
}
else if(txtdate.getText().length() == 0)
{
alert.showAlertDialog(FormLelang.this, "Info", "Isi Limit Date", false);
form_cek = 1;
}
if(form_cek == 0){
//Log.d("Form->",String.valueOf(form_cek));
ServiceHandler sh = new ServiceHandler();
List<NameValuePair> param = new ArrayList<NameValuePair>();
param.add(new BasicNameValuePair("judul", txtjudul.getText().toString()));
param.add(new BasicNameValuePair("harga", txtharga.getText().toString()));
param.add(new BasicNameValuePair("date", txtdate.getText().toString()));
//param.add(new BasicNameValuePair("jenis_kelamin", T_jeniskelamin_d.getSelectedItem().toString()));
String jsonstrr = sh.makeServiceCall(url, ServiceHandler.POST,param);
try {
JSONObject jsonobjj = new JSONObject(jsonstrr);
tag_besar = jsonobjj.getJSONArray("data");
for(int j = 0; j < tag_besar.length();j++){
JSONObject cc = tag_besar.getJSONObject(j);
success = cc.getInt("success");
}
}
catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return null;
}
protected void onPostExecute(String result){
if(form_cek == 0){
if(success == 1){
alert.showAlertDialog(FormLelang.this, "Info", "Data Berhasil Disimpan", true);
Intent setupIntent = new Intent(getApplicationContext(),MainActivity.class);
startActivityForResult(setupIntent, RESULT_OK);
finish();
}
else
{
alert.showAlertDialog(FormLelang.this, "Info", "Data Gagal Disimpan", false);
}
}
}
}
}