adapter를 사용 ListView 작업을 하고 있습니다.
문제는 뿌려주는 작업인 getView(오버라이드한)메소드가 불러와지지 않는다는 것입니다.
생성은 되는데 getView만 불러와지지 않습니다.
무슨 문제인지좀 봐주세요
arItem = new ArrayList<MyItem>();
MyItem mi;
mi = new MyItem("가나다", 5);
mi = new MyItem("라마바", 1);
mi = new MyItem("아자차", 15);
MyListAdapter myAdapter = new MyListAdapter(this, R.layout.traffic_list_row, arItem);
ListView myList;
myList = (ListView)findViewById(R.id.list);
myList.setAdapter(myAdapter);
}
class MyListAdapter extends BaseAdapter {
Context maincon;
LayoutInflater inflater;
ArrayList<MyItem> arSrc;
int layout;
public MyListAdapter(Context context, int alayout, ArrayList<MyItem> aarSrc) {
maincon = context;
inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
arSrc = aarSrc;
layout = alayout;
Log.e(TAG_NAME, "★dd"); //여기는 불러와집니다.
}
@Override
public int getCount() {
return arSrc.size();
}
@Override
public Object getItem(int position) {
return arSrc.get(position).Name;
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
Log.e(TAG_NAME, "★"); //여기가 불러와지지 앖습니다.
final int pos = position;
if(convertView == null) {
convertView = inflater.inflate(layout, parent, false);
}
TextView txt1 = (TextView)findViewById(R.id.roadname);
txt1.setText(arSrc.get(position).Name);
TextView txt2 = (TextView)findViewById(R.id.camcount);
txt2.setText("[" + arSrc.get(position).Icon + "]");
return null;
}
class MyItem {
String Name;
int Icon;
MyItem(String aName, int aIcon) {
Name = aName;
Icon = aIcon;
}
public String getName() {
return Name;
}
public int getIcon() {
return Icon;
}
}
xml 파일입니다.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="#ffffff">
<ListView
android:id="@+id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
</LinearLayout>
행을 표현할 xml파일입니다.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="6dp"
android:orientation="horizontal"
android:gravity="center_vertical">
<TextView
android:id="@+id/roadname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="22dp"/>
<TextView
android:id="@+id/camcount"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="right"
android:textSize="16dp" />
<ImageView
android:id="@+id/depth"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/list_depth"/>
</LinearLayout>
도와주세요 이것땜에 하루종일 골머리를 앓고 있습니다.
ㅠㅠ




arItem 리스트에 MyItem항목들이 add 되지 않았습니다. arItem.add(mi);를 해주면 getView 에 들어오실겁니다.
arItem = new ArrayList<MyItem>();
MyItem mi;
mi = new MyItem("가나다", 5);
여기에다
arItem.add(mi);
mi = new MyItem("라마바", 1);
arItem.add(mi);
mi = new MyItem("아자차", 15);
arItem.add(mi);
MyListAdapter myAdapter = new MyListAdapter(this, R.layout.traffic_list_row, arItem);