마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

리스트뷰 실행이 안돼요 어디가 잘못된건가요?

0 추천
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>
익명사용자 님이 2016년 10월 15일 질문
리스트뷰가 실행이 안된다는게 무슨 뜻인지 설명 좀 해주세요?
혹 버튼 클릭시 아이템을 추가하려고 하는데 안되신다는 건지요? 그렇다면, 어댑터에 데이터를 추가하셔야 겠죠? 현재는 그런 코드가 안보이네요.
제가 좀 착각을 했는데, 자바가 레퍼런스라 aitems에 데이터를 추가하고adapter.notifyDataSetChanged를 호출해도 리스트뷰에 아이템이 추가되어야 합니다.

1개의 답변

0 추천
버튼을 누르게 되면 두개의 값을 읽어와서 리스트에 추가가 되야하는데

추가가 안되고 그대로 튕겨버려요 어디부분이 문제인가요?

리스트는 평범한 리스트에 텍스트 두개를 읽어서 하는게 문제인가요?
익명사용자 님이 2016년 10월 16일 답변
에러 메세지가 있으신가요?
...