- 浏览: 3903478 次
- 性别:
- 来自: 北京
文章分类
最新评论
-
hinuliba:
...
字体背景颜色的高度修改 -
KANGOD:
最后的 -createDialog() 私有方法是怎么回事,没 ...
简单的实现listView中item多个控件以及点击事件 -
sswangqiao:
呵呵,呵呵
onActivityResult传值的使用 -
yumeiqiao:
感觉你所的不清楚 lstView.setOnTouchLi ...
listview中viewflipper的问题 -
lizhou828:
果然是大神啊!!!
Animation动画效果的实现
listView显示对象以及access any RESTFull service that uses JSON
- 博客分类:
- android
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<ListView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/lstText"
/>
</LinearLayout>
listitems.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="0dip" android:layout_weight="1"
android:layout_height="fill_parent">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/txtAlertText" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/txtAlertDate" />
</LinearLayout>
</LinearLayout>
package josecgomez.com.android.dev.webservice;
import java.util.List;
import josecgomez.com.android.dev.webservice.objects.alerts;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;
public class AlertsAdapter extends ArrayAdapter<alerts> {
int resource;
String response;
Context context;
//Initialize adapter
public AlertsAdapter(Context context, int resource, List<alerts> items) {
super(context, resource, items);
this.resource=resource;
}
@Override
public View getView(int position, View convertView, ViewGroup parent)
{
LinearLayout alertView;
//Get the current alert object
alerts al = getItem(position);
//Inflate the view
if(convertView==null)
{
alertView = new LinearLayout(getContext());
String inflater = Context.LAYOUT_INFLATER_SERVICE;
LayoutInflater vi;
vi = (LayoutInflater)getContext().getSystemService(inflater);
vi.inflate(resource, alertView, true);
}
else
{
alertView = (LinearLayout) convertView;
}
//Get the text boxes from the listitem.xml file
TextView alertText =(TextView)alertView.findViewById(R.id.txtAlertText);
TextView alertDate =(TextView)alertView.findViewById(R.id.txtAlertDate);
//Assign the appropriate data from our alert object above
alertText.setText(al.alerttext);
alertDate.setText(al.alertdate);
return alertView;
}
}
package josecgomez.com.android.dev.webservice; import java.lang.reflect.Type; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import josecgomez.com.android.dev.webservice.objects.alerts; import android.app.Activity; import android.os.Bundle; import android.util.Log; import android.widget.ListView; import com.google.gson.Gson; import com.google.gson.reflect.TypeToken; public class main extends Activity { /** Called when the activity is first created. */ //ListView that will hold our items references back to main.xml ListView lstTest; //Array Adapter that will hold our ArrayList and display the items on the ListView AlertsAdapter arrayAdapter; //List that will host our items and allow us to modify that array adapter ArrayList<alerts> alrts=null; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); //Initialize ListView lstTest= (ListView)findViewById(R.id.lstText); //Initialize our ArrayList alrts = new ArrayList<alerts>(); //Initialize our array adapter notice how it references the listitems.xml layout arrayAdapter = new AlertsAdapter(main.this, R.layout.listitems,alrts); //Set the above adapter as the adapter of choice for our list lstTest.setAdapter(arrayAdapter); //Instantiate the Web Service Class with he URL of the web service not that you must pass WebService webService = new WebService("http://www.sumasoftware.com/alerts/GetAlerts.php"); //Pass the parameters if needed , if not then pass dummy one as follows Map<String, String> params = new HashMap<String, String>(); params.put("var", ""); //Get JSON response from server the "" are where the method name would normally go if needed example // webService.webGet("getMoreAllerts", params); String response = webService.webGet("", params); try { //Parse Response into our object Type collectionType = new TypeToken<ArrayList<alerts>>(){}.getType(); //JSON expects an list so can't use our ArrayList from the lstart List<alerts> lst= new Gson().fromJson(response, collectionType); //Now that we have that list lets add it to the ArrayList which will hold our items. for(alerts l : lst) { alrts.add(l); } //Since we've modified the arrayList we now need to notify the adapter that //its data has changed so that it updates the UI arrayAdapter.notifyDataSetChanged(); } catch(Exception e) { Log.d("Error: ", e.getMessage()); } } }
Please note that the attached jar file contains a compiled copy of the GSON library available at http://code.google.com/p/google-gson/.
以上是转帖 http://www.josecgomez.com/2010/05/04/android-accessing-restfull-json-services-library/
http://www.josecgomez.com/2010/04/30/android-accessing-restfull-web-services-using-json/
发表评论
-
URI 转path
2019-06-26 10:41 1227转自知乎Matisse package com.zhihu ... -
权限申请
2017-09-22 13:25 1225public class PermissionActivit ... -
onPreviewFrame 相机输出格式转换yuv420p保存成图片
2015-11-25 15:59 7486在最近项目中,因为特殊需要,底层相机往外输出了i420 也 ... -
new Android's Runtime Permission
2015-11-03 21:05 1192targetSdkVersion 23 开始 使用运行时权 ... -
自定义listview 边缘效果
2015-02-28 10:58 1702static void ChangeEdgeEffect( ... -
发射打开wifi
2015-01-07 10:25 1374WifiManager wifiManager = (Wif ... -
RecyclerView
2014-11-05 13:08 1212http://www.grokkingandroid.com ... -
获取点击区域
2014-04-28 09:39 1520@Override public void getHitR ... -
speex 和libogg 编译
2014-04-03 16:17 6369下载: http://www.speex.org/down ... -
rsync 同步
2014-03-28 17:06 1801两台android 设备 进行rsy ... -
流转字符串
2014-03-11 09:49 1478public static String convertSt ... -
java simplexml 序列化
2014-03-06 13:22 5885<?xml version="1.0&quo ... -
获取其他程序的特定资源
2014-03-05 09:33 1658try { PackageManager man ... -
检测来电属于哪个sim卡
2014-02-07 10:41 1676public class IncomingCallInter ... -
使用 NDK r9 编译ffmpeg
2014-01-16 13:32 167651. 环境 ubuntu 我的是13.10 ndk r9 ... -
android h264含so
2014-01-13 11:24 1509http://download.csdn.net/downlo ... -
xml转义字符
2013-12-18 09:29 1558" " ' & ... -
字体背景颜色的高度修改
2013-12-11 10:31 4145当使用android:lineSpacingExtra= ... -
屏保的实现
2013-12-07 10:27 2722最近需要做一个屏保,开始以为很简单,因为系统本身就带了屏保功 ... -
PreferenceActivity下嵌套PreferenceScreen在其它布局中
2013-11-21 16:32 9102今天在修改系统代码的时候,系统代码用了PreferenceA ...
相关推荐
C#-ACCESS采用ListView显示SqlDataReader数据集,及直接访问模式的插入、修改、删除等操作
使用本地 json 数据,给listview setDate,实现页面显示。操作简单,实现listview仿购物车金额的 累加。
三个按钮实现了从安卓端发送数据到后台,后台传送用户名和密码,用JSON解析数据,然后再listView中显示
json从网上下载解析,用baseadapter,listview显示
JSON解析采用AsyncTask异步加载图片并用listview显示 这是项目中URL
android 自定义listview分组显示本地json格式数据,主要是listview可以自定义成下拉刷新(此demo不包含上下拉,应用者自己完善),组头和组所属的数据的item点击事件是分开的
通过httpclient获取到JSON数据,展示到ListView
android框架解析JSON数据放入ListView的例子
适合新手参考,简单实用,因为我也是新手,所以用的都是比较基础的方法实现。...okhttp方法获取服务器JSON数据或者获取本地android studio内的txt文本解析,然后显示在listview上,listview增加了上滑加载更多的功能
VB中,Listview中的数据如何存入 access 的表中这个是很经典的例子,大家做软件可能用到,欢迎下载
供初学VB的朋友学习。程序中通过vb连接Access数据库操作Listview表格。
适合基础巩固学习 解析服务器json数据 ListView列表上拉加载 下拉刷新 自己做的程序 解释很全 经过验证 绝对运行成功 学习的好例子 希望对您有绝对的好帮助
此为进行数据展示的listviewDemo
Android连接后台mysql数据库,并将数据库中的数据展示在Android客户端
对于listview显示图片快速滑动出现oom等异常的优化
通过httpclient获取到JSON数据展示到ListView.zip
ListView 通过adapter传递对象
listview 实现隐藏显示headerview
使用listview 实时的显示 在线新闻,网络实时更新,listview滑动 顺畅,网络下载非常快,速度流畅,使用apache连接网络。
winform 用listview 显示多个图片