package aa.hub;
import android.app.Activity;
import android.app.ListActivity;
import android.database.Cursor;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
public class PrayerName extends ListActivity implements OnClickListener {
String[] arr;
DbHandlerProfile dbHandlerProfile;
DbHandlerPrayerName dbHandlerPrayerName;
Cursor Profilecursor;
Cursor Prayernamecursor;
EditText edtprayername;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.prayername);
findViewById(R.id.btnSavePrayerName).setOnClickListener(this);
findViewById(R.id.btnResetPrayerName).setOnClickListener(this);
}
public void onClick(View v) {
if (v.getId() == R.id.btnSavePrayerName) {
while (Profilecursor.moveToNext()) {// 프로필 개수만큼 루프를 돈다
}
} else if (v.getId() == R.id.btnResetPrayerName) {
}
}
@Override
protected void onResume() {
super.onResume();
try {
dbHandlerProfile = DbHandlerProfile.open(this);
Profilecursor = dbHandlerProfile.selectAsc();
setString();
Toast.makeText(this, "setstring", 0).show();
} catch (Exception e) {
Toast.makeText(this, " 틀을 불러오는데 실패" + e.getMessage(), 0)
.show();
Log.i("disp", " 틀을 불러오는데 실패" + e.getMessage());
} finally {
if (Profilecursor != null)
Profilecursor.close();
if (dbHandlerProfile != null)
dbHandlerProfile.close();
}
}
private void setString() {
arr = new String[Profilecursor.getCount()];
int count = 0;
while (Profilecursor.moveToNext()) {
String name = Profilecursor.getString(1);
String grade = Profilecursor.getString(2);
arr[count] = name + "(" + grade + "기)";
count++;
}
this.setListAdapter(new MyListAdapter(this));
}
class MyListAdapter extends ArrayAdapter { <<<<<<<<<<<---------------------이부분
Activity context;
MyListAdapter(Activity context) {
super(context, R.layout.group_element_row, arr);
this.context = context;
}
// 행마다 뷰를 리턴하는 메소드
public View getView(int position, View convertView, ViewGroup parent) {
// 레이아웃 인플레이터 생성
// xml 레이아웃 파일을 읽어들이는 기능을 가지고 있음
LayoutInflater inflater = context.getLayoutInflater();
View row = inflater.inflate(R.layout.group_element_row, null);
// 레이블을 리소스에서 읽음
TextView NamenGrade = (TextView) row
.findViewById(R.id.txtName_Grade_PrayerName);
NamenGrade.setText(arr[position]);
return row;
}
}
}
Arrayadapter를 상속하는 클래스를 만드는 부분에서 에러가납니다......
class MyListAdapter extends ArrayAdapter<String>{
...
...
}
이렇게<String>을 붙여주면 또 괜찮던데 이게 무슨 차이인가요??




ArrayAdapter는 기본 어댑터입니다. 셀에 오브젝트 하나만 들어가는.. 커스텀하고싶으심 BaseAdapter를 상속받으세요
<String>이 들어가는 이유는 기본 어댑터에 스트링값을 넣겠다는 이야깁니다. 사실 어댑터개념은 안드로이드보다는 디자인패턴에 가까워서 그쪽을 검색해서 공부하는게 도움이 될겁니다. Adapter를 잘 만들어놓으면 여기저기 붙여도 상관없죠. ListView쓰다가 맘에안들면 GridView로 바로 갈아끼워도 되고.