① android客戶端 json解析為list<map<>>怎麼裝入simpleadapter
java">
{
privateList<Map<String,Object>>data;
privateMap<String,Object>map;
privateContextctx;
privateTextViewtvBookName;
privateTextViewtvPerson;
privateTextViewtvCompany;
privateTextViewresult;
privateTextViewtvNum;
privateLinearLayoutlayout_bj;
privateLinearLayoutlayout;
//載入布局
LayoutInflatervi;
LayoutInflatervi1;
publicDataAdapter(Contextcontext,List<Map<String,Object>>data){
ctx=context;
this.data=data;
}
@Override
publicViewgetView(intpostion,Viewarg1,ViewGrouparg2){
//TODOAuto-generatedmethodstub
if(postion<data.size()){
map=data.get(postion);
}
layout=newLinearLayout(ctx);
vi=(LayoutInflater)ctx
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
vi.inflate(R.layout.list_content,layout,true);
//layout.setBackgroundColor(0xffB4B4B4);
layout_bj=(LinearLayout)layout.findViewById(R.id.list_one);
tvBookName=(TextView)layout.findViewById(R.id.book_name);
tvPerson=(TextView)layout.findViewById(R.id.person_name);
tvCompany=(TextView)layout.findViewById(R.id.company_name);
tvNum=(TextView)layout.findViewById(R.id.book_num);
tvBookName.setText(map.get("書名").toString());
tvPerson.setText(map.get("作者").toString());
tvCompany.setText(map.get("出版社").toString());
tvNum.setText(map.get("藏書").toString());
Stringurl=map.get("鏈接").toString();
//添加監聽
addListener(tvBookName,tvPerson,tvCompany,url,layout_bj);
returnlayout;
}
以上是適配器代碼,在主Activity中添加listview即可
listView.setAdapter(newDataAdapter(BookReaultActivity.this,
list))
② android 兩個Activity之間傳遞ArrayList<Map<String, Object>>,代碼該怎麼寫
通過共享appication做處理
先轉換成json,第二個activity再轉換回list
public class SerializableMap implements Serializable {
ArrayList<Map<String, Object>> listMap;
//get set方法
}
最後通過putSerializable("listMap
",SerializableMap獲得listMap);
③ android studio中方法返回的類型是list<map<string,objects>>該return 一個什麼
這個list的類型要帶泛型
④ Android。怎麼訪問list<map<string,object>>裡面的變數,比如。
你得繼承 BaseAdapter 實現一個 adapter 類,override 裡面諸如 getCount ,getItem 方法就好。
⑤ android list和map的區別
List按對象進入的順序保存對象,不做排序或編輯操作)。Map同樣對每個
元素保存一份,但這是基於"鍵"的,Map也有內置的排序,因而不關心元素添加的順序。如果添加元素的順序對你很重要,應該使用
LinkedHashSet或者LinkedHashMap.
⑥ 在android開發中,map可以完全替代bean嗎
map只能存儲鍵值對,或者嵌套使用(感覺略復雜)。
而bean對象卻是可以存儲一個完整的包含多屬性的復雜對象,在界面繪制時一般用list(map<key,value>)來傳遞對應的值,但是請求回調接收時還是用bean來裝載對象的好。
javaBean的話就是有get/set方法,可以對數據進行一些必要的操作,還有javaBean裡面可以添加方法.map的話欄位你不確定,需要額外的寫好那些key是什麼東西。
javaBean欄位可以添加註釋說明,類型也是固定的,那麼使用者就知道該放什麼數據,而map如果存放了多個類型只能是object類型的,使用還得知道具體類型,還要做相應的類型轉換!)
簡單的說:我認為map不能完全替代bean,只是在使用中某些場合可以適當選擇map使用下。
⑦ android,ArrayList<Map<String,Object>>()傳不進值。
目測是IDs[j])等沒有值,map的size()肯定為3啊。。就是3個空的map,它也輸出3
⑧ Android 把伺服器jsno數據解析為list map,怎麼提取其中的變數比如說
UserList很明顯是個List UserList.get(0).get("values")這樣取值首先是得到List里的map
⑨ android 怎麼取list數據
按以下代碼可獲取到list數據:
package com.example.sdtg.sdsw;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.SoapFault;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import org.xmlpull.v1.XmlPullParserException;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Button;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.TextView;
import android.widget.Toast;
public class ListActivity extends Activity {
// 命名空間
// String nameSpace = "http://tempuri.org/";
// 調用的方法名稱
// String methodName = "GetSjSearch";
// EndPoint
// String endPoint = "http://192.168.0.145/webservice2/gswebservice.asmx";
// SOAP Action
// String soapAction = "http://tempuri.org/GetSjSearch";
// List<Map<String, Object>> mList;
ListView ListV;
HashMap<String, Object> map = new HashMap<String, Object>();
private List<Map<String,String>> listItems;
SimpleAdapter mListAdapter;
String name="";
String addr="";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_list);
listItems = new ArrayList<Map<String,String>>();
ListV=(ListView)findViewById(R.id.ListView01);
Handler indicate = new Handler();
//獲取主頁面傳的值
final Intent data = getIntent();
name=data.getStringExtra("Name");
addr=data.getStringExtra("Addr");
new NetAsyncTask().execute();
ListV.setOnItemClickListener(new OnItemClickListener(){
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
//獲得選中項的HashMap對象
TextView viewtmc = (TextView) arg1.findViewById(R.id.textListmc);
TextView viewdz = (TextView) arg1.findViewById(R.id.textlistdz);
TextView viewid = (TextView) arg1.findViewById(R.id.textlistid);
//String playerChanged = c.getText().toString();
Bundle bundle = new Bundle();
bundle.putString("Name", viewtmc.getText().toString());
bundle.putString("Addr", viewdz.getText().toString());
bundle.putString("ID", viewid.getText().toString());
final Intent data = getIntent();
data.putExtras(bundle);
//跳轉回MainActivity
//注意下面的RESULT_OK常量要與回傳接收的Activity中onActivityResult()方法一致
ListActivity.this.setResult(RESULT_OK, data);
//關閉當前activity
ListActivity.this.finish();
}
});
};
class NetAsyncTask extends AsyncTask<Object, Object, String> {
@Override
protected void onPostExecute(String result) {
if (result.equals("success")) {
mListAdapter = null;
mListAdapter = new SimpleAdapter(ListActivity.this, listItems, R.layout.item,new String[]{"title", "info", "img"}, new int[]{R.id.textListmc, R.id.textlistdz, R.id.textlistid});
ListV.setAdapter(mListAdapter);
}
super.onPostExecute(result);
}
@Override
protected String doInBackground(Object... params) {
// 命名空間
String nameSpace = "http://tempuri.org/";
// 調用的方法名稱
String methodName = "GetSjSearch";
// EndPoint
String endPoint = "http://192.168.0.145/webservice2/gswebservice.asmx";
// SOAP Action
String soapAction = "http://tempuri.org/GetSjSearch";
// 指定WebService的命名空間和調用的方法名
SoapObject rpc = new SoapObject(nameSpace, methodName);
// 設置需調用WebService介面需要傳入的兩個參數mobileCode、userId
rpc.addProperty("name", name);
rpc.addProperty("address", addr);
// 生成調用WebService方法的SOAP請求信息,並指定SOAP的版本
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
// SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER12);
envelope.bodyOut = rpc;
// 設置是否調用的是dotNet開發的WebService
envelope.dotNet = true;
// 等價於envelope.bodyOut = rpc;
envelope.setOutputSoapObject(rpc);
HttpTransportSE transport = new HttpTransportSE(endPoint);
try {
// 調用WebService
transport.call(soapAction, envelope);
} catch (Exception e) {
e.printStackTrace();
}
SoapObject object;
// 開始調用遠程方法
try {
object = (SoapObject) envelope.getResponse();
int count = object.getPropertyCount();
// 得到伺服器傳回的數據
int count1 = object.getPropertyCount();
if(count1>0)
{
for (int i = 0; i < count1; i++) {
Map<String,String> listItem = new HashMap<String, String>();
SoapObject soapProvince = (SoapObject)object.getProperty(i);
listItem.put("title", soapProvince.getProperty("DJXX_NSRMC").toString());
listItem.put("info", soapProvince.getProperty("DJXX_ZCDJ").toString());
//listItem.put("img", soapProvince.getProperty("DJXX_NSRSBH").toString());
listItems.add(listItem);
}}
} catch (IOException e) {
e.printStackTrace();
//return "IOException";
}
return "success";
}
}
}
⑩ android如何將一個list<map<list<string1>,list<String>>>轉換成json
map1.put("name","小明");
map1.put("age","23");
map1.put("sex","男");
list.add(map1);
map2.put("name","小王");
map2.put("age","24");
map2.put("sex","女");
list.add(map2);
map3.put("name","小張");
map3.put("age","22);