package com.example.it.myapplication_network;
import android.content.DialogInterface;
import android.net.Network;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import com.example.it.myapplication_network.Network.NetworkGet;
import com.example.it.myapplication_network.Network.NetworkInsert;
import java.util.ArrayList;
public class MainActivity extends AppCompatActivity {
private Button refreshBtn, addBtn;
private ListView listView;
private Custom_Adapter adapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
listView = (ListView) findViewById(R.id.listView);
adapter = new Custom_Adapter(MainActivity.this, R.layout.adapter_userinfo, new ArrayList<UserInfo>());
listView.setAdapter(adapter);
refreshBtn = (Button) findViewById(R.id.btnRefresh);
refreshBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
new NetworkGet((Custom_Adapter) listView.getAdapter()).execute("");
}
});
// addBtn = (Button) findViewById(R.id.btn_add);
// addBtn.setOnClickListener(new View.OnClickListener() {
// @Override
// public void onClick(View v) {
// final View v = getLayoutInflater().inflate(R.layout.dialog_add, null);
// new AlertDialog.Builder(MainActivity.this)
// .setTitle("멤버 추가")
// .setView(v)
// .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
// @Override
// public void onClick(DialogInterface dialog, int which) {
// String id = ((EditText)v.findViewById(R.id.edtID)).getText().toString();
// String name = ((EditText)v.findViewById(R.id.edtName)).getText().toString();
// String phone = ((EditText)v.findViewById(R.id.edtPhone)).getText().toString();
// String grade = ((EditText)v.findViewById(R.id.edtGrade)).getText().toString();
//
// new NetworkInsert(adapter).execute(id,name,phone,grade);
// }
// })
// .setNegativeButton(android.R.string.oanoel, new DialogInterface.OnClickListener() {
// @Override
// public void onClick(DialogInterface dialog, int which) {
// dialogInterface.cancel();
// }
// })
// .setCancelable(false)
// .show();
// }
// });
new NetworkGet((Custom_Adapter) listView.getAdapter()).execute(""); // 전체 불러오기
}
}
package com.example.it.myapplication_network;
public class UserInfo {
String id, name, phone, grade, writeTime;
public UserInfo (String id, String name, String phone, String grade, String writeTime) {
this.id = id;
this.name = name;
this.phone = phone;
this.grade = grade;
this.writeTime = writeTime;
}
}
package com.example.it.myapplication_network;
import android.app.Activity;
import android.content.Context;
import android.content.DialogInterface;
import android.support.v7.app.AlertDialog;
import android.text.Layout;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
import com.example.it.myapplication_network.Network.NetworkDelete;
import java.util.ArrayList;
public class Custom_Adapter extends BaseAdapter {
private Activity mAct;
LayoutInflater mInflater;
ArrayList<UserInfo> mUserInfoObjArr;
int mListLayout;
public Custom_Adapter(Activity a, int listLayout, ArrayList<UserInfo> userInfoObjArrayListT) {
mAct = a;
mListLayout = listLayout;
mUserInfoObjArr = userInfoObjArrayListT;
mInflater = (LayoutInflater) a.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
public void setDatas(ArrayList<UserInfo> arrayList) {
mUserInfoObjArr = arrayList;
}
@Override
public int getCount() {
return 0;
}
@Override
public Object getItem(int position) {
return null;
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
convertView = mInflater.inflate(mListLayout, parent, false);
}
final TextView tvID = (TextView) convertView.findViewById(R.id.tv_id);
tvID.setText(mUserInfoObjArr.get(position).id);
final TextView tvName = (TextView) convertView.findViewById(R.id.tv_name);
tvName.setText(mUserInfoObjArr.get(position).name);
final TextView tvPhone = (TextView) convertView.findViewById(R.id.tv_phone);
tvPhone.setText(mUserInfoObjArr.get(position).phone);
final TextView tvGrade = (TextView) convertView.findViewById(R.id.tv_grade);
tvGrade.setText(mUserInfoObjArr.get(position).grade);
final TextView tvWriteTime = (TextView) convertView.findViewById(R.id.tv_write_time);
tvWriteTime.setText(mUserInfoObjArr.get(position).writeTime);
Button updateButton = (Button) convertView.findViewById(R.id.btnUpdate);
updateButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
}
});
Button deleteButton = (Button) convertView.findViewById(R.id.btn_delete);
deleteButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String userID = tvID.getText().toString();
AlertDialog.Builder ad = new AlertDialog.Builder(mAct);
ad.setTitle("삭제하기");
ad.setMessage("사용자 ID : " + userID + "를 정말 삭제하시겠습니까?");
ad.setNegativeButton("삭제", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
new NetworkDelete(Custom_Adapter.this).execute(tvID.getText().toString());
}
});
ad.setPositiveButton("취소", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Toast.makeText(mAct, "취소하였습니다.", Toast.LENGTH_SHORT).show();
}
});
ad.show();
}
});
return convertView;
}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/activity_main"
android:orientation="vertical" >
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="새로고침"
android:id="@+id/btnRefresh" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="추가"
android:id="@+id/btn_add" />
<ListView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/listView" />
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TableLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/tbl1">
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/tv_id"
android:layout_width="60dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:text="id" />
<TextView
android:id="@+id/tv_name"
android:layout_width="40dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:gravity="center"
android:text="name" />
<TextView
android:id="@+id/tv_phone"
android:layout_width="70dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:gravity="center"
android:text="phone" />
<TextView
android:id="@+id/tv_grade"
android:layout_width="20dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:gravity="center"
android:text="grade" />
<TextView
android:id="@+id/tv_write_time"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:gravity="center"
android:text="write time" />
</TableRow>
</TableLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/tbl1"
android:orientation="horizontal" >
<Button
android:id="@+id/btn_delete"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:text="삭제" />
<Button
android:id="@+id/btnUpdate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="@id/btn_delete"
android:text="수정" />
</RelativeLayout>
</RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="5dp" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center_vertical" >
<TextView
android:layout_height="match_parent"
android:layout_gravity="right|center_vertical"
android:text="ID : "
android:layout_width="57dp" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="left|center_vertical"
android:hint="ID"
android:id="@+id/edtID"
android:paddingLeft="5dp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center_vertical" >
<TextView
android:layout_height="match_parent"
android:gravity="right|center_vertical"
android:text="NAME : "
android:layout_width="57dp" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="left|center_vertical"
android:hint="NAME"
android:id="@+id/edtName"
android:paddingLeft="5dp"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center_vertical" >
<TextView
android:layout_width="57dp"
android:layout_height="match_parent"
android:text="PHONE : "
android:gravity="right|center_vertical"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="left|center_vertical"
android:hint="PHONE"
android:id="@+id/edtPhone"
android:paddingLeft="5dp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center_vertical" >
<TextView
android:layout_width="57dp"
android:layout_height="match_parent"
android:gravity="right|center_vertical"
android:text="GRADE : " />
<EditText
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="left|center_vertical"
android:hint="GRADE"
android:id="@+id/edtGrade"
android:paddingLeft="5dp" />
</LinearLayout>
</LinearLayout>