안드로이드 개발 질문/답변
(글 수 45,052)
basedapter구현인데 뭐가잘못됬는지모르겠더군요..코드에 어디가 잘못됬는지좀 봐주시면합니다..
layout/main.xml
layout/profileview.xml
정말최소한의 구성만으로 일단 작동되길바랄뿐인데 대체어디가잘못된건지모르겠더군요;;고수님들 지적좀 부탁드립니다.
layout/main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ListView android:layout_width="wrap_content"
android:layout_height="wrap_content" android:id="@+id/list"></ListView>
</LinearLayout>
layout/profileview.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:id="@+id/LinearLayout01"
android:layout_width="fill_parent" android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout android:orientation="horizontal">
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/name"></TextView>
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/telephone"></TextView>
</LinearLayout>
</LinearLayout>ListActivity.class package com.listTest;
import java.util.ArrayList;
import android.app.Activity;
import android.os.Bundle;
import android.widget.ListView;
public class ListActivity extends Activity {
private ArrayList<Profile> profiles=null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Profile p1=new Profile("aaa", "111");
Profile p2=new Profile("bbb", "222");
Profile p3=new Profile("ccc", "333");
Profile p4=new Profile("ddd", "444");
profiles=new ArrayList<Profile>();
profiles.add(p1);
profiles.add(p2);
profiles.add(p3);
profiles.add(p4);
ProfileListAdapter adapter=new ProfileListAdapter(this,R.layout.profileview,profiles);
ListView
listView=(ListView)findViewById(R.id.list);
listView.setAdapter(adapter);
}
}Profile.class package com.listTest;
public class Profile {
private String name;
private String telephone;
public Profile(String name, String telephone) {
this.name = name;
this.telephone = telephone;
}
public String getName() {
return name;
}
public String getTelephone() {
return telephone;
}
}
ProfileListAdapter.class package com.listTest;
import java.util.ArrayList;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
public class ProfileListAdapter extends BaseAdapter{
private LayoutInflater inflater;
private ArrayList<Profile> profiles;
private int layout;
public ProfileListAdapter(Context context,int layout,ArrayList<Profile> profiles) {
this.inflater=(LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
this.layout=layout;
this.profiles=profiles;
}
@Override
public int getCount() {
return profiles.size();
}
@Override
public String getItem(int pos) {
return profiles.get(pos).getName();
}
@Override
public long getItemId(int pos) {
return pos;
}
@Override
public View getView(int pos, View convertView, ViewGroup parent) {
if(convertView==null){
convertView=inflater.inflate(layout,parent,false);
}
Profile profile=profiles.get(pos);
TextView
name=(TextView)convertView.findViewById(R.id.name);
name.setText(profile.getName());
TextView
telephone=(TextView)convertView.findViewById(R.id.telephone);
telephone.setText(profile.getTelephone());
return convertView;
}
}AndroidManifest.xml <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.listTest"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".ListActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-sdk android:minSdkVersion="9" />
</manifest>
정말최소한의 구성만으로 일단 작동되길바랄뿐인데 대체어디가잘못된건지모르겠더군요;;고수님들 지적좀 부탁드립니다.



