จาก code ด้านล่าง ผมจะใส่ ScrollView เฉพาะในส่วนของ Detail ยังไงครับ.
package com.example.travelthailand;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.StatusLine;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONException;
import org.json.JSONObject;
import android.os.Bundle;
import android.os.StrictMode;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Intent;
import android.util.Log;
import android.view.View;
import android.view.Menu;
import android.widget.Button;
import android.widget.TextView;
public class ViewReview extends Activity {
@SuppressLint(“NewApi”)
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_viewreview);
// Permission StrictMode
if (android.os.Build.VERSION.SDK_INT > 9) {
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
}
showInfo();
// btnBack
final Button btnBack = (Button) findViewById(R.id.btnEdit);
// Perform action on click
btnBack.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent newActivity = new Intent(ViewReview.this,ReviewActivity.class);
startActivity(newActivity);
}
});
}
public void showInfo()
{
// txtMemberID,txtMemberID,txtUsername,txtPassword,txtName,txtEmail,txtTel
final TextView tTitle = (TextView)findViewById(R.id.txtTitle);
final TextView tName = (TextView)findViewById(R.id.txtPostBy);
final TextView tDate = (TextView)findViewById(R.id.txtPostDate);
final TextView tDetail = (TextView)findViewById(R.id.txtPostDetail);
String url = “http://www.xxx.com/mobile_viewreview.php”;
Intent intent= getIntent();
final String PostID = intent.getStringExtra(“PostID”);
Log.d(“post id”, PostID);
List params = new ArrayList();
params.add(new BasicNameValuePair(“sPostID”, PostID));
String resultServer = getHttpPost(url,params);
String strPostID = “”;
String strTitle = “”;
String strName = “”;
String strDate = “”;
String strDetail = “”;
JSONObject c;
try {
c = new JSONObject(resultServer);
strPostID = c.getString(“PostID”);
strTitle = c.getString(“PostTitle”);
strName = c.getString(“PostName”);
strDate = c.getString(“PostDate”);
strDetail = c.getString(“PostDetail”);
if(!strPostID.equals(“”))
{
tTitle.setText(strTitle);
tName.setText(strName);
tDate.setText(strDate);
tDetail.setText(strDetail);
}
else
{
tTitle.setText(“-“);
tName.setText(“-“);
tDate.setText(“-“);
tDetail.setText(“-“);
}
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public String getHttpPost(String url,List params) {
StringBuilder str = new StringBuilder();
HttpClient client = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(url);
try {
httpPost.setEntity(new UrlEncodedFormEntity(params));
HttpResponse response = client.execute(httpPost);
StatusLine statusLine = response.getStatusLine();
int statusCode = statusLine.getStatusCode();
if (statusCode == 200) { // Status OK
HttpEntity entity = response.getEntity();
InputStream content = entity.getContent();
BufferedReader reader = new BufferedReader(new InputStreamReader(content));
String line;
while ((line = reader.readLine()) != null) {
str.append(line);
}
} else {
Log.e(“Log”, “Failed to download result..”);
}
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return str.toString();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
ลองแก้ในหน้า activity_viewreview โดยจัดให้ TextView tDetail อยู่ใน ScrollView