意见反馈栏,留言和联系方式发送给服务器,发送那部分如何实现??加急啊,要交啦。。求助

骑着猪上高速 发布于 2014/12/24 14:27
阅读 372
收藏 0

   刚工作不久,很多不懂,自己也网上查了很多文章,看了好多资料,还是没弄出来,GET和POST用过写不下去了,实在没办法,经常看到这开源论坛,知道有大神在,想请大神帮忙!别笑话我啊,对于大神来说很简单,菜鸟不会就不会,虚心求教,希望得到指点。。。

main.xml布局文件:

<LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical"
        android:padding="5.0dp" >

        <EditText
            android:id="@+id/feedback_content_edit"
            android:layout_width="fill_parent"
            android:layout_height="0.0dp"
            android:layout_weight="1.0"
            android:background="@drawable/setting_edit"
            android:gravity="top"
            android:hint="@string/feedback_content_hint"
            android:paddingBottom="14.0dp"
            android:paddingLeft="12.0dp"
            android:paddingTop="12.0dp"
            android:singleLine="false"
            android:textColor="#ff333333"
            android:textSize="18.0sp" />

        <EditText
            android:id="@+id/feedback_contact_edit"
            android:layout_width="fill_parent"
            android:layout_height="48.0dp"
            android:layout_marginTop="10.0dp"
            android:background="@drawable/setting_edit"
            android:gravity="center_vertical"
            android:hint="@string/feedback_contact_hint"
            android:paddingLeft="12.0dp"
            android:paddingRight="12.0dp"
            android:singleLine="true"
            android:textColor="#ff333333"
            android:textSize="18.0sp" />

        <Button
            android:id="@+id/submit_button"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="5.0dp"
            android:layout_marginTop="10.0dp"
            android:background="@drawable/my_feedback_button"
            android:padding="10.0dp"
            android:text="@string/submit"
            android:textColor="@color/white"
            android:textSize="18.0sp" />
    </LinearLayout>

feedback类文件

 

public class FeedbackActivity extends Activity {

 private EditText mContactEdit = null;
 private EditText mContentEdit = null;
 private ImageView mLeftBtn = null;
 private ImageView mRightBtn = null;
 private Button mSubmitBtn = null;

 @Override
 public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.main);
  initView();
  InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
  imm.toggleSoftInput(InputMethodManager.RESULT_UNCHANGED_SHOWN,
    InputMethodManager.HIDE_NOT_ALWAYS);
 }

 private void initView() {
     mContactEdit = (EditText) findViewById(R.id.feedback_contact_edit);
     mContentEdit = (EditText) findViewById(R.id.feedback_content_edit);
     mLeftBtn = (ImageView) findViewById(R.id.left_btn);
     mRightBtn = (ImageView) findViewById(R.id.right_btn);
     mContentEdit.requestFocus();
     
     mLeftBtn.setVisibility(View.GONE);
     mRightBtn.setOnClickListener(new View.OnClickListener() {
   
   public void onClick(View v) {
    Intent intent = new Intent();
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    intent.setClass(FeedbackActivity.this, FeedbackRecordActivity.class);
    startActivity(intent);
   }
  });
     
     mSubmitBtn = (Button) findViewById(R.id.submit_button);
     mSubmitBtn.setOnClickListener(new View.OnClickListener() {
   
   public void onClick(View v) {
    String content = mContentEdit.getText().toString().trim();
    String contact = mContactEdit.getText().toString().trim();
    if (content.equals("")) {
     Toast.makeText(FeedbackActivity.this, R.string.request_content, Toast.LENGTH_SHORT).show();
     return;
    }
    SendFeedbackTask task = new SendFeedbackTask(FeedbackActivity.this, content, contact);
    task.execute("");
    
   }
  });
    }

 private class SendFeedbackTask extends AsyncTask<Object, Object, Object> {

  private Context mContext = null;
  private String mContact = "";
  private String mContent = "";
  private ProgressDialog mProgDialog = null;

  public SendFeedbackTask(Context context, String content, String contact) {
   mContext = context;
   mContent = content;
   mContact = contact;
  }

  @Override
  protected Object doInBackground(Object... arg0) {
   return Integer.valueOf(new HttpUtils(mContext)
     .sendFeedbackMessage(mContent, mContact));
  }

  @Override
  protected void onPostExecute(Object result) {
   if (mProgDialog != null) {
    mProgDialog.dismiss();
   }
   int resultCode = ((Integer) result).intValue();
   if (resultCode == 0) {
    Toast.makeText(FeedbackActivity.this,
      R.string.feedback_success, Toast.LENGTH_SHORT);
    //FeedbackActivity.this.finish();
   } else {
    Toast.makeText(FeedbackActivity.this, R.string.feedback_failed,
      Toast.LENGTH_SHORT);
   }
   return;
  }

  @Override
  protected void onPreExecute() {
   mProgDialog = new ProgressDialog(FeedbackActivity.this);
   mProgDialog.setMessage(FeedbackActivity.this
     .getString(R.string.waiting));
   mProgDialog.setCancelable(false);
   mProgDialog.show();
  }

   }
}

feedAtion类文件:

 

public class FeedbackAction {
 
 private Context mContext = null;
 private static final int SUCCESS = 0;
 private static final int FAILURE = 1;
 
 public FeedbackAction(Context context) {
  mContext = context;
 }

 /**
  * 此处用于将反馈信息发送给服务器
  * @param content 内容参数
  * @param contact 联系参数
  * @return
  * @return
  */  

 这部分怎么写啊?

 public int sendFeedbackMessage(String content, String contact) {
  return SUCCESS;
 }

}

要添加就最后那部分,运行没问题,就缺少提交到服务器那一块。。。

 

 

加载中
0
飞车兔
飞车兔

android的问题?不懂。

骑着猪上高速
骑着猪上高速
求 Android大神24
返回顶部
顶部