public class ListExample extends ListActivity{
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ArrayList<Person> m_orders = new ArrayList<Person>();
ListView list = (ListView)findViewById(R.id.list);
Person p1 = new Person("삼악산", "강원 춘천시 서면 덕두원리 118-6");
Person p2 = new Person("남이섬", "강원 춘천시 남산면 방하리 198");
Person p3 = new Person("소양댐", "강원도 춘천시 신북읍 천전리 산4번지");
Person p4 = new Person("의암댐", "강원 춘천시 신동면(新東面) 의암리");
Person p5 = new Person("용화산", "강원 춘천시 사북면 고성리 산102 외14 ");
Person p6 = new Person("구곡폭포", "강원 춘천시 남산면 강촌1리 432번지");
Person p7 = new Person("청평사", "강원도 춘천시 북산면 청평리 674");
Person p8 = new Person("봉의산성", "강원 춘천시 소양로 1가 산1-1");
m_orders.add(p1);
m_orders.add(p2);
m_orders.add(p3);
m_orders.add(p4);
m_orders.add(p5);
m_orders.add(p6);
m_orders.add(p7);
m_orders.add(p8);
PersonAdapter m_adapter = new PersonAdapter(this, R.layout.row, m_orders);
setListAdapter(m_adapter);
list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view, int position, long id){
if(position == 0){
Intent a= new Intent(ListExample.this,Chug1.class);
startActivity(a);
}
}
});
}
}
class PersonAdapter extends ArrayAdapter<Person> {
private ArrayList<Person> items;
public PersonAdapter(Context context, int textViewResourceId, ArrayList<Person> items) {
super(context, textViewResourceId, items);
this.items = items;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View v = convertView;
if (v == null) {
LayoutInflater vi = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = vi.inflate(R.layout.row, null);
}
Person p = items.get(position);
if (p != null) {
TextView tt = (TextView) v.findViewById(R.id.toptext);
TextView bt = (TextView) v.findViewById(R.id.bottomtext);
if (tt != null){
tt.setText(p.getName());
}
if(bt != null){
bt.setText("주소: "+ p.getNumber());
}
}
return v;
}
private LayoutInflater getSystemService(String layoutInflaterService) {
// TODO Auto-generated method stub
return null;
}
}
class Person {
private String Name;
private String Number;
public Person(String _Name, String _Number){
this.Name = _Name;
this.Number = _Number;
}
public String getName() {
return Name;
}
public String getNumber() {
return Number;
}
}
이건 매니 페스트 부분
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.dayyoung.test"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".MainActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".Chug1"
android:label="@string/app_name"> </activity>
</application>
</manifest>
실행해보면 응용프로그램이 예상치 않게 종료되었습니다. 이렇게 뜨네요 ㅜㅜ
며칠째 이거 갖고 헤매고 있습니다 onItemSelected 이걸로 해봐도 안되고 뭐가 문제 일까요??
매니페스트를 잘못 올렸네요
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.androidhuman.ListExample"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".ListExample"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".Chug1"
android:label="@string/app_name"></activity>
</application>
<uses-sdk android:minSdkVersion="3" />
</manifest> 이건데 역시 실행이 안됩니다.



