网创优客建站品牌官网
为成都网站建设公司企业提供高品质网站建设
热线:028-86922220
成都专业网站建设公司

定制建站费用3500元

符合中小企业对网站设计、功能常规化式的企业展示型网站建设

成都品牌网站建设

品牌网站建设费用6000元

本套餐主要针对企业品牌型网站、中高端设计、前端互动体验...

成都商城网站建设

商城网站建设费用8000元

商城网站建设因基本功能的需求不同费用上面也有很大的差别...

成都微信网站建设

手机微信网站建站3000元

手机微信网站开发、微信官网、微信商城网站...

建站知识

当前位置:首页 > 建站知识

android表单,android表单校验

android能根据json动态生成一个form表单吗?

你是做web开发的吧?

十余年的广昌网站建设经验,针对设计、前端、开发、售后、文案、推广等六对一服务,响应快,48小时及时工作处理。网络营销推广的优势是能够根据用户设备显示端的尺寸不同,自动调整广昌建站的显示方式,使网站能够适用不同显示终端,在浏览器中调整网站的宽度,无论在任何一种浏览器上浏览网站,都能展现优雅布局与设计,从而大程度地提升浏览体验。创新互联公司从事“广昌网站设计”,“广昌网站推广”以来,每个客户项目都认真落实执行。

问题要发到 电脑/网络—软件开发—移动开发下比较准确。

android上是没有form表单的概念的,通常用listView列表来显示。

前几天给别人写了一个这样的demo,如果有需要,可以留下邮箱发给你

android客户端如何提交表单数据给web服务器

1.服务器端的准备

为了完成该实例,我们需要在服务器端做以下准备工作:

(1)我们需要在MyEclipse中创建一个Web工程,用来模拟服务器端的Web服务,这里,我将该工程命名为了“myhttp”。

(2)修改该工程的“index.jsp”文件,添加两个输入框和一个提交按钮,作为该Web工程的显示页面。运行Tomcat,在浏览器中访问该Web工程,可以看到如图1所示的界面。

Web工程的显示页面

(3)在该Web工程中,创建一个继承自HttpServlet的LoginAction类,并实现其中的doPost()方法,用来响应图1所示页面的用户操作。具体实现如下:

由上述代码可以看出,当我们在图1所示的页面输入用户名“admin”,密码“123”时,点击提交按钮,会得到“Login succeeded!”的提示信息,如图2所示。若用户名、密码错误,则会得到“Login failed!”的提示信息。

2.客户端实现

在Android客户端,我们需要完成的工作是:以POST方式发送用户名密码到上述服务器,并获得服务器的验证信息。

我们分以下几个步骤来完成。

2.1 UI界面

在Android工程中,我们需要完成一个简单的UI界面,用来完成用户名密码的输入、发送POST请求、显示服务器的验证结果,完成后的界面如图3所示。

在MainActivity中,我们需要获取两个EditText控件的输入,“提交”按键的监听,以及服务器验证结果的TextView内容显示。具体实现代码如下:

2.2发送POST请求到服务器

可以看到上述代码中,我们调用了HttpUtils类的静态方法submitPostData()完成了发送POST请求到服务器,并将该方法的返回值(服务器的响应结果)显示在了TextView控件中。

通过以上的代码可以看出,在该方法中,其实完成了3件事:

(1)将用户名密码封装成请求体,这是通过调用getRequestData()方法来实现的(后面会讲到这个方法的具体实现)。

(2)设置HttpURLConnection对象的各种参数(其实是设置HTTP协议请求体的各项参数),然后通过httpURLConnection.getOutputStream()方法获得服务器输出流outputStream,再使用outputStream.write()方法将请求体内容发送给服务器。

(3)判断服务器的响应码,通过httpURLConnection.getInputStream()方法获得服务器的响应输入流,然后再调用dealResponseResult()方法处理服务器的响应结果。

2.3封装请求体

使用POST请求时,POST的参数不是放在URL字符串里,而是放在HTTP请求数据中,所以我们需要对POST的参数进行封装。

针对该实例而言,我们发送的URL请求是:,但是我们需要将POST的参数(也就是username和password)封装到该请求中,形成如下的形式:

2.4处理响应结果

最后,我们再来看一看对服务器返回结果的处理是怎样的。因为在本实例中,服务器的返回结果是字符串“Login succeeded!”或“Login failed!”,所以这里我们需要做的就是将服务器的返回结果输入流转化成字符串。当然了,如果服务器返回的是图片,那么,我们就需要就得到的输入流转化成Bitmap图片了。如下代码是上面代码中用到的dealResponseResult()方法的具体实现。

2.5运行效果

android平板 怎么设计好看的表单

1.来说下主程序MainActivity.java

public class MainActivity extends Activity {

private TableLayout table;

private Button select;

EmployeeDao dao = new EmployeeDao(this);

private Button add;

private Button update;

int selectedRow = 0;

int ActivityID=1;

ListEmployee list = new ArrayListEmployee();

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

table = (TableLayout) this.findViewById(R.id.table);

table.setBackgroundColor(Color.GREEN);

//table.set

add = (Button) this.findViewById(R.id.add);

update = (Button) this.findViewById(R.id.update);

select = (Button) this.findViewById(R.id.select);

// 点击查询按钮处理事件

// Toast.makeText(this, "已查询过了!", Toast.LENGTH_SHORT).show();

select.setOnClickListener(new selectListener());

// 点击添加按钮事件处理,跳转到另一个activity

add.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View v) {

Intent i = new Intent();

i.setClass(MainActivity.this, AddAndUpdateActivity.class);

Bundle bundle=new Bundle();

ActivityID=1;

bundle.putInt("ID", ActivityID);

i.putExtras(bundle);

startActivity(i);

}

});

// 更新员工信息

update.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View v) {

Intent i = new Intent();

i.setClass(MainActivity.this, AddAndUpdateActivity.class);

Bundle bundle=new Bundle();

ActivityID=2;

bundle.putInt("ID", ActivityID);

bundle.putInt("emID", selectedRow);

i.putExtras(bundle);

startActivity(i);

}

});

}

// 查询信息监听类

private class selectListener implements View.OnClickListener {

@Override

public void onClick(View v) {

list = dao.getAll();

if (list.size() != 0) {

for (int i = 0; i list.size(); i++) {

TableRow row = new TableRow(MainActivity.this);

Employee em = list.get(i);// 查找所有员工信息

// 设置行标记

row.setId(em.getId());

row.setPadding(6, 1, 6, 1);

row.setGravity(Gravity.CENTER);

row.setBackgroundColor(Color.WHITE);

TextView view1 = new TextView(MainActivity.this);

view1.setText(Integer.toString(em.getId()));

view1.setGravity(Gravity.CENTER);//文本居中

view1.setTextSize((float) 18);文本大小

view1.setTextColor(Color.RED);

view1.setPadding(10, 2, 10, 2);//边框左、上、右、下

row.addView(view1);添加一行

TextView view2 = new TextView(MainActivity.this);

view2.setText(em.getName());

view2.setTextSize((float) 18);

view2.setPadding(10, 2, 10, 2);

row.addView(view2);

TextView view3 = new TextView(MainActivity.this);

view3.setText(Integer.toString(em.getAge()));

view3.setTextSize((float) 18);

view3.setGravity(Gravity.CENTER);

view3.setPadding(10, 2, 10, 2);

row.addView(view3);

TextView view4 = new TextView(MainActivity.this);

view4.setText(em.getPosition());

view4.setTextSize((float) 18);

view4.setPadding(10, 2, 10, 2);

row.addView(view4);

TextView view5 = new TextView(MainActivity.this);

view5.setText(em.getDepartment());

view5.setTextSize((float) 18);

view5.setPadding(10, 2, 10, 2);

row.addView(view5);

TextView view6 = new TextView(MainActivity.this);

view6.setText(em.getWorkdate());

view6.setTextSize((float) 18);

view6.setPadding(10, 2, 10, 2);

row.addView(view6);

TextView view7 = new TextView(MainActivity.this);

SimpleDateFormat format=new SimpleDateFormat("yyyy-MM-dd");

Date date = null;

try {

date = format.parse(em.getWorkdate());

} catch (ParseException e) {

e.printStackTrace();

}

float d= (float)((new Date().getTime()-date.getTime())/(24*60*60*1000)/365);//计算工龄

String dd=Integer.toString((int) d+1);

view7.setText(dd);

view7.setTextSize((float) 18);

view7.setPadding(10, 2, 10, 2);

row.addView(view7);

table.addView(row);

row.setOnClickListener(new View.OnClickListener() {//点击某行触发事件

@Override

public void onClick(View v) {

System.out.println("行标记:" + v.getId());

for (int i = 0; i table.getChildCount(); i++) {

if (table.getChildAt(i).getId() != v.getId())

table.getChildAt(i).setBackgroundColor(Color.WHITE);

// 选中时,高亮显示即设置背景色

v.setBackgroundColor(Color.YELLOW);

}

selectedRow = v.getId();

AlertDialog.Builder dialog = new AlertDialog.Builder(

MainActivity.this);

dialog.setTitle("请确认:");

dialog.setMessage("是否删除这条记录?");

dialog.setPositiveButton("确定",

new DialogInterface.OnClickListener() {

@Override

public void onClick(

DialogInterface dialog,int which) {

EmployeeDao dao = new EmployeeDao(MainActivity.this);

dao.delete(selectedRow);

Toast.makeText(MainActivity.this,

"删除成功", Toast.LENGTH_SHORT).show();

Intent i = new Intent();

i.setClass(MainActivity.this,MainActivity.class);

startActivity(i);

}

});

dialog.setNegativeButton("取消",

new DialogInterface.OnClickListener() {

@Override

public void onClick(DialogInterface dialog,

int which) {

dialog.cancel();

} });

dialog.show();

}

});

}

}

}

}

}

2.然后是添加和更新的界面,两个功能使用同一个xml文件布局

RelativeLayout

android:background="#2691f2"

tools:context=".AddAndUpdateActivity"

TextView

android:id="@+id/t"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_centerHorizontal="true"

android:textSize="25sp"

android:text="@string/addinfo"

android:textColor="#bc4b86" /

LinearLayout

android:layout_width="fill_parent"

android:layout_height="match_parent"

android:layout_below="@+id/t"

android:orientation="vertical"

TextView

android:layout_width="wrap_content"

android:layout_height="30dp" /

LinearLayout

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:orientation="horizontal"

TextView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="@string/name" /

EditText

android:id="@+id/nm"

android:inputType="text"

android:layout_width="150dp"

android:layout_height="wrap_content"

android:layout_marginLeft="25dp" /

/LinearLayout

LinearLayout

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:orientation="horizontal"

TextView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="@string/age" /

EditText

android:id="@+id/ag"

android:inputType="text"

android:layout_width="150dp"

android:layout_height="wrap_content"

android:layout_marginLeft="25dp" /

/LinearLayout

LinearLayout

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:orientation="horizontal"

TextView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="@string/position" /

EditText

android:id="@+id/pzs"

android:inputType="text"

android:layout_width="150dp"

android:layout_height="wrap_content"

android:layout_marginLeft="25dp" /

/LinearLayout

LinearLayout

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:orientation="horizontal"

TextView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="@string/dptmt" /

EditText

android:id="@+id/dptmt"

android:inputType="text"

android:layout_width="150dp"

android:layout_height="wrap_content"

android:layout_marginLeft="25dp" /

/LinearLayout

LinearLayout

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:orientation="horizontal"

TextView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="@string/date" /

EditText

android:id="@+id/wkdt"

android:inputType="text"

android:layout_width="150dp"

android:layout_height="wrap_content" /

/LinearLayout

TextView

android:layout_width="wrap_content"

android:layout_height="20dp" /

Button

android:id="@+id/addnew"

android:layout_width="60dp"

android:layout_height="40dp"

android:layout_gravity="center_horizontal"

android:text="@string/add"

/Button

/LinearLayout

/RelativeLayout


新闻名称:android表单,android表单校验
网站路径:http://bjjierui.cn/article/dscopph.html

其他资讯