mahasiswa_list.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<!-- Main ListView
Jangan lupa selalu berikan id value sebagai list(@android:id/list)
-->
<ListView
android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
desain_list.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/list_selector"
android:orientation="horizontal"
android:padding="5dip" >
<!-- ListRow Left sied Thumbnail image -->
<LinearLayout android:id="@+id/thumbnail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="3dip"
android:layout_alignParentLeft="true"
android:background="@drawable/image_bg"
android:layout_marginRight="5dip">
<ImageView
android:id="@+id/list_imagelkp"
android:layout_width="50dip"
android:layout_height="50dip"
android:src="@drawable/gprofile"/>
</LinearLayout>
<!-- Deskripsi LP2M ARAY-->
<TextView
android:id="@+id/txtNamalkp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/thumbnail"
android:layout_toRightOf="@+id/thumbnail"
android:text="From zero to hero"
android:textColor="#FF0000"
android:textSize="15dip"
android:textStyle="bold"
android:typeface="sans" />
<!-- Judul LP2M ARAY-->
<TextView
android:id="@+id/txtDeskripsilkp"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/txtNamalkp"
android:layout_marginTop="1dip"
android:layout_toRightOf="@+id/thumbnail"
android:text="Just gona stand there and ..."
android:textColor="#343434"
android:textSize="10dip"
android:textStyle="bold" />
<!-- Bar LP2M ARAY -->
<TextView
android:id="@+id/kode_k"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignTop="@id/txtNamalkp"
android:layout_marginRight="5dip"
android:gravity="right"
android:text="5:45"
android:textColor="#000"
android:textSize="10dip"
android:textStyle="bold"
android:visibility="gone" />
<!-- Rightend Arrow -->
<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/arrow"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"/>
</RelativeLayout>
MahasiswaList.java
package com.lp2maray.json;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.apache.http.NameValuePair;
import android.app.ListActivity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.TextView;
public class MahasiswaList extends ListActivity {
String ip="";
private ProgressDialog pDialog;
JSONParser jParser = new JSONParser();
JSONArray myJSON = null;
ArrayList<HashMap<String, String>> arrayList;
private static final String TAG_SUKSES = "sukses";
private static final String TAG_record = "record";
private static final String TAG_kode_mahasiswa = "kode_mahasiswa";
private static final String TAG_telepon = "telepon";
private static final String TAG_nama = "nama";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.mahasiswa_list);
arrayList = new ArrayList<HashMap<String, String>>();
ip=jParser.getIP();
new load().execute();
ListView lv = getListView();
lv.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,int position, long id) {
String pk = ((TextView) view.findViewById(R.id.kode_k)).getText().toString();
Intent i = new Intent(getApplicationContext(), Mahasiswa.class);
i.putExtra("pk", pk);
startActivityForResult(i, 100);
}});
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == 100) {// jika result code 100
Intent intent = getIntent();
finish();
startActivity(intent);
}
}
class load extends AsyncTask<String, String, String> {
@Override
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(MahasiswaList.this);
pDialog.setMessage("Load data. Silahkan Tunggu...");
pDialog.setIndeterminate(false);
pDialog.setCancelable(false);
pDialog.show();
}
protected String doInBackground(String... args) {
List<NameValuePair> params = new ArrayList<NameValuePair>();
JSONObject json = jParser.makeHttpRequest(ip+"mahasiswa/mahasiswa_show.php", "GET", params);
Log.d("show: ", json.toString());
try {
int sukses = json.getInt(TAG_SUKSES);
if (sukses == 1) {
myJSON = json.getJSONArray(TAG_record);
for (int i = 0; i < myJSON.length(); i++) {
JSONObject c = myJSON.getJSONObject(i);
String kode_mahasiswa= c.getString(TAG_kode_mahasiswa);
String telepon= c.getString(TAG_telepon);
String nama = c.getString(TAG_nama);
HashMap<String, String> map = new HashMap<String, String>();
map.put(TAG_kode_mahasiswa, kode_mahasiswa);
map.put(TAG_nama, nama);
map.put(TAG_telepon, telepon);
arrayList.add(map);
}
} else {
Intent i = new Intent(getApplicationContext(),Mahasiswa.class);
i.putExtra("pk", "");
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(i);
}
}
catch (JSONException e) {e.printStackTrace();}
return null;
}
protected void onPostExecute(String file_url) {
pDialog.dismiss();
runOnUiThread(new Runnable() {
public void run() {
ListAdapter adapter = new SimpleAdapter(MahasiswaList.this, arrayList,R.layout.desain_list, new String[] { TAG_kode_mahasiswa,TAG_nama,TAG_telepon},new int[] { R.id.kode_k, R.id.txtNamalkp, R.id.txtDeskripsilkp});
setListAdapter(adapter);
}
});}
}
public boolean onCreateOptionsMenu(Menu menu) {
menu.add(0, 1, 0, "Add New").setIcon(R.drawable.add);
return true;
}
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case 1:
Intent i = new Intent(getApplicationContext(), Mahasiswa.class);
i.putExtra("pk", "");
startActivityForResult(i, 100);
return true;
}
return false;
}
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
finish();
return true;
}
return super.onKeyDown(keyCode, event);
}
}
++++++++++++++++++++++++++++++++
mahasiswa.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<ScrollView
android:layout_marginBottom="50dip"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#999999"
>
<TableLayout android:id="@+id/TableLayout01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:background="#fff">
<TextView
android:id="@+id/txtMarquee"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textSize="14sp"
android:typeface="sans"
android:textColor="#ffffff"
android:background="#000000"
android:singleLine="true"
android:ellipsize="marquee"
android:marqueeRepeatLimit="marquee_forever">
</TextView>
<ImageView
android:id="@+id/myGambar" android:layout_centerHorizontal="true"
android:src="@drawable/admin"
android:layout_width="100dp"
android:layout_height="100dp"
/>
<TableRow android:id="@+id/TableRow01" android:layout_width="wrap_content" android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="kode_mahasiswa"
android:textColor="#000000" />
<EditText
android:id="@+id/txtkode_mahasiswa"
android:textColor="#000000"
android:hint="kode_mahasiswa" />
</TableRow>
<TableRow android:id="@+id/TableRow02" android:layout_width="wrap_content" android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#000000"
android:text="nama" />
<EditText android:id="@+id/txtnama"
android:textColor="#000000"
/>
</TableRow>
<TableRow android:id="@+id/TableRow03" android:layout_width="wrap_content" android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#000000"
android:text="telepon" />
<EditText android:id="@+id/txttelepon"
android:textColor="#000000"
android:hint="telepon"
/>
</TableRow>
<TableRow android:id="@+id/TableRow04" android:layout_width="wrap_content" android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#000000"
android:text="email" />
<EditText android:id="@+id/txtemail"
android:textColor="#000000"
android:hint="email"
/>
/>
</TableRow>
<TableRow android:id="@+id/TableRow05" android:layout_width="wrap_content" android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#000000"
android:text="keterangan" />
<TextView android:text="" />
</TableRow>
<EditText android:id="@+id/txtketerangan"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:lines="2"
android:textColor="#000000"
android:hint="keterangan"
android:gravity="top"/>
<TableRow android:id="@+id/TableRow06" android:layout_width="wrap_content" android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:textColor="#000000"
android:layout_height="wrap_content"
android:text="status" />
<EditText android:id="@+id/txtstatus"
android:textColor="#000000"
android:hint="status"
/>
</TableRow>
<Button android:id="@+id/btnproses"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Proses"
android:layout_weight="1"/>
<Button android:id="@+id/btnhapus"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Hapus"
android:visibility="gone"
android:layout_weight="1"/>
</TableLayout>
</ScrollView>
</RelativeLayout>
Mahasiswa.java
package com.lp2maray.json;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.text.Html;
import android.text.TextUtils;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class Mahasiswa extends Activity {
String ip="";
String kode_mahasiswa;
String kode_mahasiswa0="";
EditText txtKode_mahasiswa;
EditText txtNama;
EditText txtTelepon;
EditText txtEmail;
EditText txtKeterangan;
EditText txtStatus;
Button btnProses;
Button btnHapus;
private ProgressDialog pDialog;
JSONParser jsonParser = new JSONParser();
private static final String TAG_SUKSES = "sukses";
private static final String TAG_record = "record";
private static final String TAG_nama = "nama";
private static final String TAG_telepon = "telepon";
private static final String TAG_email = "email";
private static final String TAG_keterangan = "keterangan";
private static final String TAG_status = "status";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.mahasiswa);
ip=jsonParser.getIP();
callMarquee();
txtKode_mahasiswa = (EditText) findViewById(R.id.txtkode_mahasiswa);
txtNama= (EditText) findViewById(R.id.txtnama);
txtEmail= (EditText) findViewById(R.id.txtemail);
txtTelepon= (EditText) findViewById(R.id.txttelepon);
txtKeterangan = (EditText) findViewById(R.id.txtketerangan);
txtStatus= (EditText) findViewById(R.id.txtstatus);
btnProses= (Button) findViewById(R.id.btnproses);
btnHapus = (Button) findViewById(R.id.btnhapus);
Intent i = getIntent();
kode_mahasiswa0 = i.getStringExtra("pk");
if(kode_mahasiswa0.length()>0){
new get().execute();
btnProses.setText("Update Data");
btnHapus.setVisibility(View.VISIBLE);
}
else{
btnProses.setText("Add New Data");
btnHapus.setVisibility(View.GONE);
}
btnProses.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
kode_mahasiswa= txtKode_mahasiswa.getText().toString();
String lnama= txtNama.getText().toString();
String lemail= txtEmail.getText().toString();
String ltelepon= txtTelepon.getText().toString();
String lketerangan= txtKeterangan.getText().toString();
String lstatus= txtStatus.getText().toString();
if(kode_mahasiswa.length()<1){lengkapi("kode_mahasiswa");}
else if(lnama.length()<1){lengkapi("nama");}
else if(lemail.length()<1){lengkapi("email");}
else if(ltelepon.length()<1){lengkapi("telpon");}
else{
if(kode_mahasiswa0.length()>0){
new update().execute();
}
else{
new save().execute();
}
}//else
}});
btnHapus.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
new del().execute();
}});
}
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
class get extends AsyncTask<String, String, String> {
@Override
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(Mahasiswa.this);
pDialog.setMessage("Load data detail. Silahkan tunggu...");
pDialog.setIndeterminate(false);
pDialog.setCancelable(true);
pDialog.show();
}
protected String doInBackground(String... params) {
int sukses;
try {
List<NameValuePair> params1 = new ArrayList<NameValuePair>();
params1.add(new BasicNameValuePair("kode_mahasiswa", kode_mahasiswa0));
String url=ip+"mahasiswa/mahasiswa_detail.php";
Log.v("detail",url);
JSONObject json = jsonParser.makeHttpRequest(url, "GET", params1);
Log.d("detail", json.toString());
sukses = json.getInt(TAG_SUKSES);
if (sukses == 1) {
JSONArray myObj = json.getJSONArray(TAG_record); // JSON Array
final JSONObject myJSON = myObj.getJSONObject(0);
runOnUiThread(new Runnable() {
public void run() {
try {
txtKode_mahasiswa.setText(kode_mahasiswa0);
txtNama.setText(myJSON.getString(TAG_nama));
txtTelepon.setText(myJSON.getString(TAG_telepon));
txtEmail.setText(myJSON.getString(TAG_email));
txtKeterangan.setText(myJSON.getString(TAG_keterangan));
txtStatus.setText(myJSON.getString(TAG_status));
}
catch (JSONException e) {e.printStackTrace();}
}});
}
else{
// jika id tidak ditemukan
}
} catch (JSONException e) {
e.printStackTrace();
}
return null;
}
protected void onPostExecute(String file_url) {pDialog.dismiss();}
}
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
class save extends AsyncTask<String, String, String> {
@Override
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(Mahasiswa.this);
pDialog.setMessage("Menyimpan data ...");
pDialog.setIndeterminate(false);
pDialog.setCancelable(true);
pDialog.show();
}
protected String doInBackground(String... args) {
kode_mahasiswa = txtKode_mahasiswa.getText().toString();
String lnama= txtNama.getText().toString();
String lemail= txtEmail.getText().toString();
String ltelepon= txtTelepon.getText().toString();
String lketerangan= txtKeterangan.getText().toString();
String lstatus= txtStatus.getText().toString();
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("kode_mahasiswa0", kode_mahasiswa0));
params.add(new BasicNameValuePair("kode_mahasiswa", kode_mahasiswa));
params.add(new BasicNameValuePair("nama", lnama));
params.add(new BasicNameValuePair("email", lemail));
params.add(new BasicNameValuePair("telepon", ltelepon));
params.add(new BasicNameValuePair("keterangan", lketerangan));
params.add(new BasicNameValuePair("status", lstatus));
String url=ip+"mahasiswa/mahasiswa_add.php";
Log.v("add",url);
JSONObject json = jsonParser.makeHttpRequest(url,"POST", params);
Log.d("add", json.toString());
try {
int sukses = json.getInt(TAG_SUKSES);
if (sukses == 1) {
Intent i = getIntent();
setResult(100, i);
finish();
} else {
// gagal update data
}
} catch (JSONException e) {
e.printStackTrace();
}
return null;
}
protected void onPostExecute(String file_url) {pDialog.dismiss();}
}
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
class update extends AsyncTask<String, String, String> {
@Override
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(Mahasiswa.this);
pDialog.setMessage("Mengubah data ...");
pDialog.setIndeterminate(false);
pDialog.setCancelable(true);
pDialog.show();
}
protected String doInBackground(String... args) {
kode_mahasiswa = txtKode_mahasiswa.getText().toString();
String lnama= txtNama.getText().toString();
String lemail= txtEmail.getText().toString();
String ltelepon= txtTelepon.getText().toString();
String lketerangan= txtKeterangan.getText().toString();
String lstatus= txtStatus.getText().toString();
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("kode_mahasiswa0", kode_mahasiswa0));
params.add(new BasicNameValuePair("kode_mahasiswa", kode_mahasiswa));
params.add(new BasicNameValuePair("nama", lnama));
params.add(new BasicNameValuePair("email", lemail));
params.add(new BasicNameValuePair("telepon", ltelepon));
params.add(new BasicNameValuePair("keterangan", lketerangan));
params.add(new BasicNameValuePair("status", lstatus));
String url=ip+"mahasiswa/mahasiswa_update.php";
Log.v("update",url);
JSONObject json = jsonParser.makeHttpRequest(url,"POST", params);
Log.d("add", json.toString());
try {
int sukses = json.getInt(TAG_SUKSES);
if (sukses == 1) {
Intent i = getIntent();
setResult(100, i);
finish();
} else {
// gagal update data
}
} catch (JSONException e) {
e.printStackTrace();
}
return null;
}
protected void onPostExecute(String file_url) {pDialog.dismiss();}
}
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
class del extends AsyncTask<String, String, String> {
@Override
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(Mahasiswa.this);
pDialog.setMessage("Menghapus data...");
pDialog.setIndeterminate(false);
pDialog.setCancelable(true);
pDialog.show();
}
protected String doInBackground(String... args) {
int sukses;
try {
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("kode_mahasiswa", kode_mahasiswa0));
String url=ip+"mahasiswa/mahasiswa_del.php";
Log.v("delete",url);
JSONObject json = jsonParser.makeHttpRequest(url, "GET", params);
Log.d("delete", json.toString());
sukses = json.getInt(TAG_SUKSES);
if (sukses == 1) {
Intent i = getIntent();
setResult(100, i);
finish();
}
}
catch (JSONException e) {e.printStackTrace();}
return null;
}
protected void onPostExecute(String file_url) {pDialog.dismiss();}
}
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
public void lengkapi(String item){
new AlertDialog.Builder(this)
.setTitle("Lengkapi Data")
.setMessage("Silakan lengkapi data "+item +" !")
.setNeutralButton("Tutup", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dlg, int sumthin) {
finish();
}}).show();
}
void callMarquee(){
Calendar cal = Calendar.getInstance();
int jam = cal.get(Calendar.HOUR);
int menit= cal.get(Calendar.MINUTE);
int detik= cal.get(Calendar.SECOND);
int tgl= cal.get(Calendar.DATE);
int bln= cal.get(Calendar.MONTH);
int thn= cal.get(Calendar.YEAR);
String stgl=String.valueOf(tgl)+"-"+String.valueOf(bln)+"-"+String.valueOf(thn);
String sjam=String.valueOf(jam)+":"+String.valueOf(menit)+":"+String.valueOf(detik);
TextView txtMarquee=(TextView)findViewById(R.id.txtMarquee);
txtMarquee.setSelected(true);
String kata="Selamat Datang @lp2maray.com Aplikasi Android "+stgl+"/"+sjam+" #";
String kalimat=String.format("%1$s",TextUtils.htmlEncode(kata));
txtMarquee.setText(Html.fromHtml(kalimat+kalimat+kalimat));
}
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
finish();
return true;
}
return super.onKeyDown(keyCode, event);
}
}
+++++++++++++++
JSONParser .java
package com.lp2maray.json;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.util.List;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.utils.URLEncodedUtils;
import org.apache.http.impl.client.DefaultHttpClient;
import org.json.JSONException;
import org.json.JSONObject;
import android.util.Log;
public class JSONParser {
static InputStream is = null;
static JSONObject jObj = null;
static String json = "";
public JSONParser() {}
String getIP() {
return "http://172.20.10.4/2017/masterCSSmysqliAndroid/";
}
public JSONObject makeHttpRequest(String url, String method,List<NameValuePair> params) {
try {
if(method == "POST"){
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(url);
httpPost.setEntity(new UrlEncodedFormEntity(params));
HttpResponse httpResponse = httpClient.execute(httpPost);
HttpEntity httpEntity = httpResponse.getEntity();
is = httpEntity.getContent();
}
else if(method == "GET"){
DefaultHttpClient httpClient = new DefaultHttpClient();
String paramString = URLEncodedUtils.format(params, "utf-8");
url += "?" + paramString;
HttpGet httpGet = new HttpGet(url);
HttpResponse httpResponse = httpClient.execute(httpGet);
HttpEntity httpEntity = httpResponse.getEntity();
is = httpEntity.getContent();
}
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(is, "iso-8859-1"), 8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
is.close();
json = sb.toString();
} catch (Exception e) {
Log.e("Buffer Error", "Error converting result " + e.toString());
}
try {
jObj = new JSONObject(json);
} catch (JSONException e) {
Log.e("JSON Parser", "Error parsing data " + e.toString());
}
return jObj;
}
}
Tidak ada komentar:
Posting Komentar