안드로이드 개발 질문/답변
(글 수 45,052)
안녕하세요
전에 리스트뷰 관련해서 질문 올렸다가 커스텀 리스트 아답터 사용 해 보라는 댓글을 보고
인터넷에서 찾아 실습 중인데 오류가 많이 뜨네요.
코드는 나온대고 그대로 쳤는데..
무엇이 문제일까요?
두 xml파일에선 오류가 없습니다.
.java파일에서만 오류가 있네요.
소스를 치면..
main.xml
row.xml
ListExamples.java
Person 들어간 줄에서는 전부 Person cannot be resolved to a type 오류가 뜹니다.
public PersonAdapter(Context context, int textViewResourceId, ArrayList<Person> items){
super(context, textViewResourceId, Items);
this.items=items;
여기 두번째 줄에서 Items에도 'Items cannot be resolved to a type' 오류가 나고요.
전에 리스트뷰 관련해서 질문 올렸다가 커스텀 리스트 아답터 사용 해 보라는 댓글을 보고
인터넷에서 찾아 실습 중인데 오류가 많이 뜨네요.
코드는 나온대고 그대로 쳤는데..
무엇이 문제일까요?
두 xml파일에선 오류가 없습니다.
.java파일에서만 오류가 있네요.
소스를 치면..
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:id="@+id/android:list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
<TextView
android:id="@+id/android:empty"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="tets"
/>
</LinearLayout>row.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="6dip" android:orientation="vertical">
<TextView
android:id="@+id/toptext"
android:layout_width="fill_parent"
android:gravity="center_vertical"
android:layout_height="wrap_content"
android:textSize="18px"
android:textStyle="bold" />
<TextView
android:layout_width="fill_parent"
android:id="@+id/bottomtext"
android:singleLine="true"
android:ellipsize="marquee"
android:layout_height="wrap_content" />
</LinearLayout>ListExamples.java
package com.custom;
import android.app.ListActivity; import java.util.ArrayList; import android.content.Context; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ArrayAdapter; import android.widget.TextView;
public class ListExamples extends ListActivity {
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ArrayList<Person> m_orders=new ArrayList<Person>();
Person p1=new Person("1.1", "신정");
Person p2=new Person("1.3", "시무식");
Person p3=new Person("3.1", "삼일절");
m_orders.add(p1);
m_orders.add(p2);
m_orders.add(p3);
PersonAdapter m_adapter = new PersonAdapter(this, R.layout.row, m_orders);
setListAdapter(m_adapter);
}
private 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;
}
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;
}
}
}
}
Person 들어간 줄에서는 전부 Person cannot be resolved to a type 오류가 뜹니다.
public PersonAdapter(Context context, int textViewResourceId, ArrayList<Person> items){
super(context, textViewResourceId, Items);
this.items=items;
여기 두번째 줄에서 Items에도 'Items cannot be resolved to a type' 오류가 나고요.



