我正在设计教师反馈活动。下面是我的片段活动,我从webservice获取教师姓名作为对象,并在listview中显示它们。并且每个教师都有评级栏。
我想在对象数组中收集评级和教员姓名的值,并且当我点击提交按钮时想要将每个教师的反馈发送到webservice存储。我该怎么办?
FragmentTab2.java
public class TabFragment2 extends android.support.v4.app.Fragment implements View.OnClickListener {
ListView FacultyList;
View rootView;
LinearLayout courseEmptyLayout;
FacultyListAdapter facultyListAdapter;
Button upButton;
String feedbackresult,programtype,programname;
Boolean FeedBackResponse;
String FacultiesList[];
public ArrayList<Faculty> facultylist = new ArrayList<Faculty>();
SharedPreferences pref;
FacultyListAdapter adapter;
SessionSetting session;
public TabFragment2(){
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
pref = getActivity().getSharedPreferences("prefbook", getActivity().MODE_PRIVATE);
programtype = pref.getString("programtype", "NOTHINGpref");
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
rootView = inflater.inflate(R.layout.activity_studenttab2, container, false);
upButton = (Button) rootView.findViewById(R.id.btnSubmit);
session = new SessionSetting(getActivity());
new FacultySyncerBg().execute("");
courseEmptyLayout = (LinearLayout) rootView.findViewById(R.id.feedback_empty_layout);
FacultyList = (ListView) rootView.findViewById(R.id.feedback_list);
facultyListAdapter = new FacultyListAdapter(getActivity());
FacultyList.setEmptyView(rootView.findViewById(R.id.feedback_list));
FacultyList.setAdapter(facultyListAdapter);
return rootView;
}
//FEEDBACK SUBMISSION BUTTON
@Override
public void onClick(View v) {
new SendFeedbackSyncerBg().execute("");
}
public class FacultyListAdapter extends BaseAdapter {
private final Context context;
public FacultyListAdapter(Context context) {
this.context = context;
if (!facultylist.isEmpty())
courseEmptyLayout.setVisibility(LinearLayout.GONE);
}
@Override
public View getView(final int position, View convertView,
ViewGroup parent) {
final ViewHolder TabviewHolder;
if (convertView == null) {
TabviewHolder = new ViewHolder();
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.list_item_feedback,
parent, false);
TabviewHolder.FacultyName = (TextView) convertView.findViewById(R.id.FacultyName);//facultyname
TabviewHolder.rating = (RatingBar) convertView.findViewById(R.id.rating);//rating starts
TabviewHolder.Submit = (Button) convertView.findViewById(R.id.btnSubmit);
// Save the holder with the view
convertView.setTag(TabviewHolder);
} else {
TabviewHolder = (ViewHolder) convertView.getTag();
}
final Faculty mFac = facultylist.get(position);//*****************************NOTICE
TabviewHolder.FacultyName.setText(mFac.getEmployeename());
TabviewHolder.rating.setRating(mFac.getRatingStar());
// TabviewHolder.ModuleName.setText(mFac.getSubject());
TabviewHolder.rating.setOnRatingBarChangeListener(new RatingBar.OnRatingBarChangeListener() {
public void onRatingChanged(RatingBar ratingBar, float rating,
boolean fromUser) {
feedbackresult =String.valueOf(rating);
TabviewHolder.rating.setRating(Float.parseFloat(feedbackresult));
Log.d("feedback","feedback is: "+ feedbackresult);
}
});
return convertView;
}
/*private RatingBar.OnRatingBarChangeListener onRatingChangedListener(final ViewHolder holder, final int position) {
return new RatingBar.OnRatingBarChangeListener() {
@Override
public void onRatingChanged(RatingBar ratingBar, float v, boolean b) {
FacultyName item = getItem(position);
item.setRatingStar(v);
Log.i("Adapter", "star: " + v);
}
};
}*/
@Override
public int getCount() {
return facultylist.size();
}
@Override
public Object getItem(int position) {return facultylist.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
}
static class ViewHolder {
TextView FacultyName;
RatingBar rating;
Button Submit;
}
private class FacultySyncerBg extends AsyncTask<String, Integer, Void> {
ProgressDialog progressDialog;
@Override
protected void onPreExecute() {
progressDialog= ProgressDialog.show(getActivity(), "Faculty Feedback!","Fetching Faculty List", true);
}
@Override
protected Void doInBackground(String... params) {
//CALLING WEBSERVICE
Faculty(programtype);
return null;
}
@Override
protected void onPostExecute(Void result) {
if (!facultylist.isEmpty()) {
// FacultyList.setVisibiltity(View.VISIBLE) ;
courseEmptyLayout.setVisibility(LinearLayout.GONE);
if (FacultyList.getAdapter() != null)
{
if (FacultyList.getAdapter().getCount() == 0)
{
FacultyList.setAdapter(facultyListAdapter);
}
else
{
facultyListAdapter.notifyDataSetChanged();
}
}
else
{
FacultyList.setAdapter(facultyListAdapter);
}
}else
{
courseEmptyLayout.setVisibility(LinearLayout.VISIBLE);
// FacultyList.setVisibiltity(View.GONE) ;
}
progressDialog.dismiss();
}
}
这是我的对象类
Faculty.java
public class Faculty {
private float ratingStar;
String employeeid;
String employeename;
//public List<Faculty> facultylist= new ArrayList<>();
public Faculty()
{
}
public Faculty(int ratingStar,String employeeid,String employeename)
{
this.ratingStar = ratingStar;
this.employeeid =employeeid;
this.employeename =employeename;
}
public float getRatingStar() {
return ratingStar;
}
public void setRatingStar(float ratingStar) {
this.ratingStar = ratingStar;
}
public void setEmployeeid(String employeeid)
{
this.employeeid = employeeid;
}
public String getEmployeeid()
{
return this.employeeid;
}
public void setEmployeename(String employeename)
{
this.employeename = employeename;
}
public String getEmployeename()
{
return this.employeename;
}
}
任何形式的知识和信息都会感激不尽
修改
我的评分列表如下所示。