Android-编辑需求demo实现

       看了几集Android视频,没什么感觉,做完demo后大概了解了Android中一个功能实现的逻辑流程,Android主要做的是前台,在手机上显示效果。后台的接口方法都是写好的,相当于别人发布的服务,通过访问他们的URL读取数据来显示。

       首先建立Androidproject,然后建包的格式:bean(主要放公共URL和实体java)、ui包中放activity对象,res下的layout中放各个xml页面,最后Mainfest.xml配置一下通信权限,如果里面有多个activity,要设置访问首页。

Android-编辑需求demo实现_第1张图片Android-编辑需求demo实现_第2张图片

Activity.java:

package com.example.shizhan.ui;

import com.alibaba.fastjson.JSON;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.Request.Method;
import com.android.volley.toolbox.StringRequest;
import com.android.volley.toolbox.Volley;
import com.example.shizhan.R;
import com.example.shizhan.bean.DemandInfoVo;
import com.example.shizhan.bean.DemandinfoEntity;
import com.example.shizhan.bean.URL;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

public class EditxuqiuActivity extends Activity implements OnClickListener {

	private TextView txtxuqiuzhuti;
	private TextView txtcoursetype;
	private TextView txtshangkedidian;
	private TextView txtshangkeshijian;
	private TextView txtyusuan;
	private TextView txtmiaoshu;
	private TextView txtname;
	private TextView txtlianxifangshi;
	private TextView txtguoqishijian;
	private LinearLayout linertehme;

	private RequestQueue mQueue;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_editxuqiu);
		mQueue = Volley.newRequestQueue(EditxuqiuActivity.this);

		initView();

		GetOrderData();
	}
     
	//绑定控件
	public void initView() {
		txtxuqiuzhuti = (TextView) findViewById(R.id.editxuqiu_xuqiuzhutiid);
		txtcoursetype = (TextView) findViewById(R.id.editxuqiu_personid);
		txtshangkedidian = (TextView) findViewById(R.id.editxuqiu_shangkedidianid);
		txtshangkeshijian = (TextView) findViewById(R.id.editxuqiu_shangkeshijianid);
		txtyusuan = (TextView) findViewById(R.id.editxuqiu_yusuanid);
		txtmiaoshu = (TextView) findViewById(R.id.editxuqiu_miaoshuid);
		txtname = (TextView) findViewById(R.id.editxuqiu_nameid);
		txtlianxifangshi = (TextView) findViewById(R.id.editxuqiu_lianxifangshiid);
		txtguoqishijian = (TextView) findViewById(R.id.editxuqiu_guoqishijianid);
		linertehme = (LinearLayout) findViewById(R.id.editxuqiu_linear);

		linertehme.setOnClickListener(this);
	}

	//网络请求,读数据库
	public void GetOrderData() {

		String urlString = URL.EDITXUQIU_URL;
		StringRequest stringRequest = new StringRequest(Method.GET, urlString,
				new Response.Listener<String>() {
					@Override
					public void onResponse(String response) {
						DemandInfoVo demandInfoVo = null;
						// json 转换为实体
						demandInfoVo = JSON.parseObject(response.toString(),
								DemandInfoVo.class);

						DemandinfoEntity demandinfoEntity = demandInfoVo
								.getDemandInfo();

						setData(demandinfoEntity);
					}
				}, new Response.ErrorListener() {
					@Override
					public void onErrorResponse(VolleyError error) {

						Toast.makeText(getBaseContext(), "请求失败?",
								Toast.LENGTH_LONG).show();
					}
				});
		mQueue.add(stringRequest);
	}

	//查询出来数据给页面控件赋值
	public void setData(DemandinfoEntity demandinfoEntity) {
		txtxuqiuzhuti.setText(demandinfoEntity.getDemandITheme());
		txtcoursetype.setText(demandinfoEntity.getCourseType());
		txtshangkedidian.setText(demandinfoEntity.getPlace());
		txtshangkeshijian.setText(demandinfoEntity.getOpenTime());
		txtyusuan.setText(demandinfoEntity.getBudget());
		txtmiaoshu.setText(demandinfoEntity.getMoreDescribe());
		txtname.setText(demandinfoEntity.getContactWay());
		txtlianxifangshi.setText(demandinfoEntity.getContacts());
		txtguoqishijian.setText(demandinfoEntity.getOverdueDate());
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.editxuqiu_linear:
			Intent intent = new Intent();
			intent.setClass(EditxuqiuActivity.this, MessageActivity.class);
			startActivity(intent);
			break;
		default:
			break;

		}
	}

}
URL.java:

package com.example.shizhan.bean;

public class URL {

	private static String urlPrefix = "http://120.25.249.94/jrkj/GetJrkjData.ashx?op=";

	/**
	 * 注册
	 */
	public final static String REGISTER_URL = urlPrefix + "RegistUser";
	
	/**
	 * 编辑需求URL
	 */
	public final static String EDITXUQIU_URL = urlPrefix + "queryOneDemandInfo";
	
	/**
	 * 消息URL
	 */
	public final static String MESSAGE_URL = urlPrefix + "queryMessageRelationData";
}
Mainfest.xml:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.shizhan"
    android:versionCode="1"
    android:versionName="1.0" >

    <!-- 设置通信权限 -->
    <uses-permission android:name="android.permission.INTERNET" />

    <uses-sdk
        android:minSdkVersion="7"
        android:targetSdkVersion="21" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@android:style/Theme.Light.NoTitleBar" >
        <activity
            android:name="com.example.shizhan.MainActivity"
            android:label="@string/app_name" >

            <!--
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
            -->
        </activity>

        <!-- 注册 -->
        <activity
            android:name="com.example.shizhan.ui.RegesiterActivity"
            android:label="@string/app_name" >

            <!-- 设置启动开启页面 -->
        </activity>

        <!-- 编辑需求界面 -->
        <activity
            android:name="com.example.shizhan.ui.EditxuqiuActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <!-- 消息界面 -->
        <activity
            android:name="com.example.shizhan.ui.MessageActivity"
            android:label="@string/app_name" >

            <!--
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
            -->
        </activity>
    </application>

</manifest>
      多多动下你的手指,神奇一直都在发生着!



你可能感兴趣的:(Android-编辑需求demo实现)