불러올 값은 ListView 내의 class로 구성된 아이템 중 하나의 변수입니다.



우선 각 row에 들어가는 값의 클래스는 아래와 같이 선언되어 있습니다.


/************************************Class fileList*****************************/
/*각 데이터의 정보가 저장된다, 여기서는 파일이름과 파일의 경로를 포함한다.*/
/*String filename : 파일의 이름만 저장												*/
/*String path : 파일의 이름을 포함하는 파일의 경로를 저장						*/
/************************************Class fileList*****************************/ 
class fileList {		// 각 데이터의 정보가 저장된다, 여기서는 파일이름과 파일의 경로를 포함한다.
	String filename;
	String path;

	public fileList(String name, String filepath) {
		filename = name;
		path = filepath;
	}

	public String getFileName() { return filename; }
	public String getPath() { return path; }
}


두 개의 String 변수 filename과 path이죠.





이 클래스를 기반으로 구글링으로 찾아서 수정한 Custom Adapter입니다.


filename과 path는 각각 TextView 안에 들어있습니다.


/********************************    fileAdapter    ***************************/
/*fileList 클래스를 이용하여 만든 어댑터, 이를 이용하여 ListView에 List 목록을 올릴 수 있다.*/
/********************************    fileAdapter    ***************************/
private class fileAdapter extends ArrayAdapter<fileList> {
	private ArrayList<fileList> listitem;

	public fileAdapter(Context context, int textViewResourceId, ArrayList<fileList> items) {
		super(context, textViewResourceId, items);
		listitem = items;
	}

	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.listview, null);
		}
		fileList f_l = listitem.get(position);
		if (f_l != null) {
			TextView filename = (TextView) v.findViewById(R.id.name);
			TextView filepath = (TextView) v.findViewById(R.id.path);

			if (filename != null){
				filename.setText(f_l.getFileName());                           
			}
			if(filepath != null){
				filepath.setText(f_l.getPath());
			}
		}
		return v;
	}
}





여기서 문제인데요, onCreate 내에서 Listener를 이용하여 터치한 row의 각 name과 path를 뽑아내고 싶습니다.


mp3list = (ListView)findViewById(android.R.id.list);		
mp3list.setAdapter(new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1));
mp3list.setTextFilterEnabled(true); 

mp3list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
	public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
		// ???????????????
		SelectDialog(sender);		// dialog를 여는 함수, 인수는 무시하세요
		//FileDb.InputData(name.getText().toString(), path.getText().toString());
	}
});




이렇게도 해봤습니다.


>> onCreate 내부

mp3list = (ListView)findViewById(android.R.id.list);
mp3list.setAdapter(new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1));
mp3list.setTextFilterEnabled(true); 
mp3list.setOnItemClickListener(this);

>> 외부에 함수 생성

public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
	// ??????????????????????????????
	//Toast.makeText(this, name, 1000).show();	//테스트용 토스트
	//Toast.makeText(this, path, 1000).show();	//테스트용 토스트
	SelectDialog(name, path);	// dialog를 여는 함수, 인수는 무시하세요
	//FileDb.InputData(name.getText().toString(), path.getText().toString());
}



물음표 된 부분에서 몇 가지 시도해 본 것은...



1.


Object sender = mp3list.getItemAtPosition(position);


혹은


parent.getItemAtPosition(position);


getItemAtPosition으로 Object는 구했는데, 여기서 하위 함수 목록을 보아도 어떻게 해야 클래스를 불러올 수 있을지 모르겠습니다.



2.


String name = view.findViewById(R.id.name).toString();


String path = view.findViewById(R.id.path).toString();


여기서도 findViewById 하위 함수로 getText가 나오지 않는것이 좀 이상하더군요 ;


제가 알기론 안드로이드 레퍼런스에서 확인했을 때, 두 번째 변수 View는


viewThe view within the AdapterView that was clicked (this will be a view provided by the adapter)

이렇게 되어있어서 선택한 row 내의 각각의 뷰(filename과 path의 TextView)를 나타낸다고 생각했는데 제가 잘못 이해한 것 같네요..





이 문제로 거의 3일동안 진도를 못나가고 있어요 ㅠㅠ


무엇이 문제인지와 고쳐야 할 부분 지적해 주시면 감사하겠습니다.