並排列表listview
阿新 • • 發佈:2019-02-13
list = data.getList(); int number = list.size(); if (number == 0) { return; } address = list.get(0); setsubList(); ArrayAdapter adapter = new ArrayAdapter(context, R.layout.textview_item_layout, list); listView.setAdapter(adapter); listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { address = list.get(position); setsubList(); } }); } /** * 設定自列表 */ protected void setsubList() { final Listimport android.support.v4.app.Fragment; import com.xiebao.addtrad.fragment.AddressListhalfFragment; import com.xiebao.fatherclass.AbstractListFragmentActivity; public class AddressListActivity extends AbstractListFragmentActivity{ @Override protected Fragment setFragment() { // TODO Auto-generated method stub return AddressListhalfFragment.instance(getBundle()); } }import java.util.HashMap; import java.util.List; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.ListView; import android.widget.TextView; import com.google.gson.Gson; import com.xiebao.R; import com.xiebao.addtrad.adapter.GridAddressAdapter; import com.xiebao.bean.Address; import com.xiebao.bean.AddressList; import com.xiebao.fatherclass.FatherFragment; import com.xiebao.util.IConstant; import com.xiebao.util.save.SaveUserInfoUtil; import com.xiebao.view.TopBarView; /** * @ClassName: * @Description:選擇地區,並排listview * @author gongxibo * @date 建立時間:2016年1月16日 下午2:02:36 */ public class AddressListhalfFragment extends FatherFragment { /** * 地區,下一級地區 */ private ListView listView, sublistView; private Address address; private TextView provinceName; /** * 上個頁面傳過來的地址 */ private Address fromaddress; public static FatherFragment instance(Bundle bundle) { FatherFragment frag = new AddressListhalfFragment(); frag.setArguments(bundle); return frag; } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View root = inflater.inflate(R.layout.address_listhalf_layout, container, false); topBarView = (TopBarView) root.findViewById(R.id.topBarView); provinceName = findView(root, R.id.province_name); listView = findView(root, R.id.list_view); sublistView = findView(root, R.id.sublist_view); return root; } @Override public void onActivityCreated(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onActivityCreated(savedInstanceState); initView(); initListener(); } private void initListener() { getAreaData(); } private void initView() { fromaddress=(Address) getArguments().getSerializable(GridAddressAdapter.AREA); topBarView.renderView(R.string.area_text); provinceName.setText(fromaddress.getName()); provinceName.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { saveAddress(fromaddress); } }); } /** * 獲取地址資料 */ private void getAreaData() { final HashMap hashMap = new HashMap(); // session id 暫定為fm253j45fsl2bk63csu2ln2p87 hashMap.put("sid", SaveUserInfoUtil.getUserSid(context)); // 使用者名稱,暫定為bbbbb hashMap.put("username", SaveUserInfoUtil.getUserName(context)); // String // area=getArguments().getString(IConstant.AREA_ID,String.valueOf(0)); // 區域id String areaid =fromaddress.getId(); hashMap.put("area_id", areaid); String url = super.getUrl(IConstant.AREA_LIST, hashMap); super.volley_post(url); } @Override protected void correcttResponse(String response) { // TODO Auto-generated method stub setData(response); } private void setData(String response) { Gson gson = new Gson(); AddressList data = gson.fromJson(response, AddressList.class); final List