在我的项目中我有动态列表视图需要在按下按钮时将列表项发送到服务器我对此做了大量研究但是我找不到任何解决方案这个概率不知道从哪里开始这里我发布我的代码
这是我的自定义listadapter:
package first.service.precision.servicefirst;
import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;
import java.util.List;
/**
* Created by 4264 on 25-11-2015.
*/
public class MyListAdapter extends ArrayAdapter<LeadRequirementsView> {
private List<LeadRequirementsView> listData;
private LayoutInflater layoutInflater;
public MyListAdapter(Context context, int resource,List<LeadRequirementsView> listdata) {
super(context, resource, listdata);
this.listData=listdata;
layoutInflater = LayoutInflater.from(context);
}
@Override
public void add(LeadRequirementsView object) {
super.add(object);
}
@Override
public int getCount() {
return listData.size();
}
@Override
public LeadRequirementsView getItem(int position) {
return listData.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
View mview = convertView;
if (mview == null) {
convertView = layoutInflater.inflate(R.layout.list_ld_requirements,null);
TextView req = (TextView) convertView.findViewById(R.id.txt);
req.setText("Select Lead Information");
holder = new ViewHolder();
holder.headlineView = (TextView) convertView.findViewById(R.id.sbu);
holder.reporterNameView = (TextView) convertView.findViewById(R.id.bu);
holder.reportedDateView = (TextView) convertView.findViewById(R.id.sbuu);
holder.ldstatusView = (TextView) convertView.findViewById(R.id.sc);
holder.ldtype = (TextView) convertView.findViewById(R.id.ssc);
holder.ldsource = (TextView) convertView.findViewById(R.id.rq);
// add.lv.setVisibility(View.INVISIBLE);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
// add.lv.setVisibility(View.VISIBLE);
holder.headlineView.setText("Strategic Business Unit: " + listData.get(position).getSbuName());
holder.reportedDateView.setText("Business Unit: " + listData.get(position).getBuName());
holder.ldstatusView.setText("Sub Business Unit: " + listData.get(position).getServiceCategoryName());
holder.ldtype.setText("Service Category: " + listData.get(position).getServiceSubCategoryName());
// holder.ldsource.setText("Service Sub Category: " + listData.get(position).g);
convertView.setBackgroundColor(Color.parseColor("#E5E5E5"));
// holder.headlineView.setText("Requirements: " +listData.get(position).getReq());
return convertView;
}
static class ViewHolder {
public TextView headlineView;
public TextView reporterNameView;
public TextView reportedDateView;
public TextView ldstatusView;
public TextView ldtype;
public TextView ldsource;
public TextView req;
}
}
这是我将适配器设置为listview的片段:
package first.service.precision.servicefirst;
import android.app.Fragment;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.Spinner;
import android.widget.TextView;
import com.squareup.otto.Bus;
import java.util.ArrayList;
import java.util.List;
/**
* Created by 4264 on 16-10-2015.
*/
public class Add extends Fragment implements View.OnClickListener {
public static ListView lv;
public static LeadRequirementsView _LeadRequirements;
static MyListAdapter myListAdapter;
// String TAG="Add";
static Bus bus;
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
try {
View rootView = inflater.inflate(R.layout.activity_btn_add, container, false);
//bus.register(getActivity());
//Lead Source
Spinner ldsource = (Spinner) rootView.findViewById(R.id.lead_source);
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
getActivity().getBaseContext(), R.array.dropbox1, R.layout.spinnerlayout);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
ldsource.setAdapter(adapter);
//Lead Type
Spinner ldtype = (Spinner) rootView.findViewById(R.id.ldtype);
ArrayAdapter<CharSequence> adapter1 = ArrayAdapter.createFromResource(
getActivity().getBaseContext(), R.array.dropbox2, R.layout.spinnerlayout);
adapter1.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
ldtype.setAdapter(adapter1);
//Lead Status
Spinner ldstatus = (Spinner) rootView.findViewById(R.id.ldstatus);
TextView txt = (TextView) rootView.findViewById(R.id.spinnerTarget);
ArrayAdapter<CharSequence> adapter2 = ArrayAdapter.createFromResource(
getActivity().getBaseContext(), R.array.dropbox3, R.layout.spinnerlayout);
adapter2.setDropDownViewResource(android.R.layout.simple_selectable_list_item);
ldstatus.setAdapter(adapter2);
lv = (ListView) rootView.findViewById(android.R.id.list);
List<LeadRequirementsView> leadRequirementsViewList = new ArrayList<>();
myListAdapter = new MyListAdapter(getActivity(), android.R.id.list, leadRequirementsViewList);
lv.setAdapter(myListAdapter);
return rootView;
} catch (Exception e) {
throw e;
}
}
public void updateListView(LeadRequirementsView object) {
myListAdapter.add(object);
LeadRequirements leadRequirements=new LeadRequirements();
myListAdapter.notifyDataSetChanged();
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
Button btnrequirements = (Button) getActivity().findViewById(R.id.btnrequirements);
btnrequirements.setOnClickListener(this);
Button btnactnt = (Button) getActivity().findViewById(R.id.btnacnt);
btnactnt.setOnClickListener((View.OnClickListener) this);
Button btnprimary = (Button) getActivity().findViewById(R.id.btnprimary);
btnprimary.setOnClickListener((View.OnClickListener) this);
Button btnsecondary = (Button) getActivity().findViewById(R.id.btnsecondary);
btnsecondary.setOnClickListener((View.OnClickListener) this);
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.btnrequirements:
Fragment newFragment = new NewRequirements();
FragmentTransaction transaction = getFragmentManager().beginTransaction();
transaction.add(R.id.content_frame, newFragment, "NewRequire");
transaction.addToBackStack(null);
transaction.commit();
break;
case R.id.btnacnt:
FragmentManager fm = getFragmentManager();
SelectAccountDialog selectAccountDialog = new SelectAccountDialog();
// selectAccountDialog.setRetainInstance(true);
selectAccountDialog.show(fm, "fragment_name");
//ft.addToBackStack(null);
break;
case R.id.btnprimary:
FragmentManager fmm = getFragmentManager();
// FragmentTransaction ftt=fmm.beginTransaction();
SelectAccountDialog selectAccountDialog1 = new SelectAccountDialog();
//selectAccountDialog1.setRetainInstance(true);
selectAccountDialog1.show(fmm, "fragment_name");
// ftt.addToBackStack(null);
break;
case R.id.btnsecondary:
FragmentManager fm2 = getFragmentManager();
// FragmentTransaction fttt=fm2.beginTransaction();
SelectAccountDialog selectAccountDialog2 = new SelectAccountDialog();
//selectAccountDialog2.setRetainInstance(true);
selectAccountDialog2.show(fm2, "fragment_name");
// fttt.addToBackStack(null);
break;
}
}
}
我的疑问是我从另一个片段数据动态填充listview,但我不知道如何使用改造将这些列表项发送到服务器,任何人都可以帮助我吗?