안드로이드 개발 질문/답변
(글 수 45,052)
제가 아직 기본 적인 개념이 부족한지라 어려움이 많네요 ㅠㅠㅠㅠ
리스트를 불러와서 버튼을 하나생성후 이벤트를 발생하려고 합니다.
문제는 리스트는 아래와 같이 불러와지는데 버튼이 생성되질 않터라구요...ㅜㅜ
혹시 ListActivity에서 버튼이벤트처리하는 예제가 있을까요?
고수님들 답변좀 (_ _);
public class M_SaveList extends ListActivity
{
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.save_list);
String[] mStrings = new String[] {"Item 1", "Item 2", "Item 3", "Item 4", "Item 5", "Item 6"};
this.setListAdapter(new ArrayAdapter(this, android.R.layout.simple_list_item_1, mStrings));
Button save_del = (Button)findViewById(R.id.save_del);
save_del.setOnClickListener(new Button.OnClickListener()
{
public void onClick(View v)
{
finish();
}
});
}
}
xml 입니다
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView android:id="@+id/save_view"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
<ListView android:id="@android:id/list"
android:layout_height="wrap_content"
android:layout_width="fill_parent"/>
<Button android:id="@+id/save_del"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:text="삭제" />
</LinearLayout>
2010.09.22 18:18:29
답변감사합니다 ... 리스트액티비티로 db정보를 불러와서 삭제여부를 묻는 것을 사용하고 싶어서 그런데요
그냥 activity로도 가능한가요?? 방식을 좀 알고싶습니다 ㅠ
그냥 activity로도 가능한가요?? 방식을 좀 알고싶습니다 ㅠ
2010.09.23 09:27:47
일단 버튼 안보이는 점은
<TextView android:id="@+id/save_view"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
여기 height 가 fill_parent이기 때문인듯 하구요....
ListActivity하고 그냥 Activity하고 차이는 그다지 없습니다.
지정된 리소스ID로 리스트가 존재해야하는게 ListActivity인거죠.... 그 ID로 몇가지 관리가 이루어지기 때문인데요...
그 관리를 Activity에서 직접 하면 되는거죠...
DB에서 긁어오는 것은 Adapter를 CursorAdapter를 이용하면 됩니다.
<TextView android:id="@+id/save_view"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
여기 height 가 fill_parent이기 때문인듯 하구요....
ListActivity하고 그냥 Activity하고 차이는 그다지 없습니다.
지정된 리소스ID로 리스트가 존재해야하는게 ListActivity인거죠.... 그 ID로 몇가지 관리가 이루어지기 때문인데요...
그 관리를 Activity에서 직접 하면 되는거죠...
DB에서 긁어오는 것은 Adapter를 CursorAdapter를 이용하면 됩니다.
굳이 ListAcitivity를 상속받을 필요가 없어 보이는데요.
그냥 Activity를 사용하시고, xml에 정의한 Button이나 ListView를 사용해도 될듯 합니다만...