public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
String[] arr = {"apple", "banana", "melon", "blueberry"};
ListView listView = (ListView)findViewById(R.id.list_view);
MyArrayAdapter adapter = new MyArrayAdapter(this, arr);
listView.setAdapter(adapter);
}
}
class MyArrayAdapter extends ArrayAdapter<String> {
private final Context context;
private String[] values;
public MyArrayAdapter(Context context, String[] values) {
super(context, R.layout.list_item, values);
this.context = context;
this.values = values;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if(convertView == null) {
convertView = LayoutInflater.from(context).inflate(R.layout.list_item, parent, false);
}
TextView textView = (TextView)convertView.findViewById(R.id.video_info_label);
textView.setText(values[position]);
return convertView;
}
}
주석 처리한 부분 (ArrayAdapter<String> dapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, arr);) 으로 돌리면 왼쪽 결과가 나오고
(MyArrayAdapter adapter = new MyArrayAdapter(this, arr);) 이걸로 돌리면 오른쪽 결과가 나옵니다.
여기서 뭘 어케 해야 되는걸까요? ㅜㅜ