资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

android表单,android表单框架

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手机软件表单中中输入的数据存入服务器端的数据库(比如Mysql之类的)里面应该怎样设计啊!急!

我也是搞手机交互开发的,一般手机端POST数据到服务器端(如:PHP),然后由服务器端处理数据存入数据库。

就想当HTML页面提交数据到PHP然后存入数据库是一样的道理。

android、iPhone等都一样道理。

android 举报账号功能的实现

1、在android中找到后台接口//userController.java,前端接收一个usersReportd对象。

2、举报页面包含一个form表单,其中有一个picker组件用于选择举报的原因,一个textarea组件用于输入用户举报描述,一个submitReport方法提交表单信息即可举报账号。

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能根据json动态生成一个form表单吗?

你是做web开发的吧?

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

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

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


本文题目:android表单,android表单框架
文章来源:http://cdkjz.cn/article/dsdggie.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

大客户专线   成都:13518219792   座机:028-86922220