package com.example.a.wiho;
import android.app.ListActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.Toast;
import java.util.ArrayList;
public class PlusActivity extends ListActivity {
private ArrayList<String> aitems;
private ArrayAdapter<String> aadapter;
private EditText et_name;
private EditText et_pw;
private Button button;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_plus);
et_name = (EditText)findViewById(R.id.et_name);
et_pw = (EditText)findViewById(R.id.et_pw);
button = (Button)findViewById(R.id.button);
aitems = new ArrayList<String>();
aadapter = new ArrayAdapter<String>(this, R.layout.alist_item, aitems);
ListView alv = (ListView) findViewById(R.id.alv_data);
alv.setAdapter(aadapter);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (et_name.getText().toString().equals("")) {
Toast.makeText(PlusActivity.this, "이름을 입력하세요.", Toast.LENGTH_SHORT).show();
} else {
aitems.add(et_name.getText().toString());
aitems.add(et_pw.getText().toString());
et_name.setText("");
et_pw.setText("");
aadapter.notifyDataSetChanged();
}
}
});
}
}
<?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" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<EditText
android:id="@+id/et_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="2"
android:hint="Wifiname"
android:layout_alignParentTop="true"
android:layout_toLeftOf="@+id/button"
android:layout_toStartOf="@+id/button" />
<EditText
android:id="@+id/et_pw"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="2"
android:hint="Password"
android:layout_gravity="center_vertical"
android:layout_below="@+id/et_name"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_toLeftOf="@+id/button"
android:layout_toStartOf="@+id/button" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:onClick="mOnClick"
android:text="추가"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:drawableBottom="@android:drawable/ic_input_add"
android:id="@+id/button"
android:layout_alignBottom="@+id/et_pw" />
</RelativeLayout>
<ListView
android:id="@+id/alv_data"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>