0
일부 소스 코드를 잃어 버렸고 이전에 어떻게 작동했는지 잊어 버렸습니다. 그런 다음 http://www.androidhive.info/2012/02/android-custom-listview-with-image-and-text/안드로이드 프래그먼트에서 ListView를 사용하는 방법
public class Feed extends Fragment {
// All static variables
static final String URL = "=========================";
// XML node keys
static final String KEY_SONG = "song"; // parent node
static final String KEY_ID = "id";
static final String KEY_TITLE = "title";
static final String KEY_ARTIST = "date";
static final String KEY_DURATION = "time";
static final String KEY_THUMB_URL = "thumb_url";
ListView list;
LazyAdapter adapter;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
//This layout contains your list view
View view = inflater.inflate(R.layout.feedview, container, false);
ArrayList<HashMap<String, String>> songsList = new ArrayList<HashMap<String, String>>();
XMLParser parser = new XMLParser();
String xml = parser.getXmlFromUrl(URL); // getting XML from URL
org.w3c.dom.Document doc = parser.getDomElement(xml); // getting DOM element
NodeList nl = doc.getElementsByTagName(KEY_SONG);
// looping through all song nodes <song>
for (int i = 0; i < nl.getLength(); i++) {
// creating new HashMap
HashMap<String, String> map = new HashMap<String, String>();
Element e = (Element) nl.item(i);
// adding each child node to HashMap key => value
map.put(KEY_ID, parser.getValue(e, KEY_ID));
map.put(KEY_TITLE, parser.getValue(e, KEY_TITLE));
map.put(KEY_ARTIST, parser.getValue(e, KEY_ARTIST));
map.put(KEY_DURATION, parser.getValue(e, KEY_DURATION));
map.put(KEY_THUMB_URL, parser.getValue(e, KEY_THUMB_URL));
// adding HashList to ArrayList
songsList.add(map);
}
ListView listview =(ListView)view.findViewById(R.id.listView1);
adapter=new LazyAdapter(this, songsList);
listview.setAdapter(adapter);
return view;
}
가 나는 LazyAdapter.java 클래스과 같이 있습니다 :
이 기사에서 볼 수 있듯이 사용자 지정 목록보기로드하는 Feed.java 클래스가public class LazyAdapter extends BaseAdapter {
private Activity activity;
private ArrayList<HashMap<String, String>> data;
private static LayoutInflater inflater=null;
public ImageLoader imageLoader;
public LazyAdapter(Activity a, ArrayList<HashMap<String, String>> d) {
activity = a;
data=d;
inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
imageLoader=new ImageLoader(activity.getApplicationContext());
}
public int getCount() {
return data.size();
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
View vi=convertView;
if(convertView==null)
vi = inflater.inflate(R.layout.list_row, null);
TextView title = (TextView)vi.findViewById(R.id.title); // title
TextView artist = (TextView)vi.findViewById(R.id.date); // date
TextView duration = (TextView)vi.findViewById(R.id.time); // time
TextView address = (TextView)vi.findViewById(R.id.address); // address
TextView notes = (TextView)vi.findViewById(R.id.notes); // notes
HashMap<String, String> song = new HashMap<String, String>();
song = data.get(position);
// Setting all values in listview
title.setText(song.get(Feed.KEY_TITLE));
artist.setText(song.get(Feed.KEY_ARTIST));
duration.setText(song.get(Feed.KEY_DURATION));
return vi;
}
을}
Feed.java에서 ""오류가 발생합니다. "adapter = new LazyAdapter (this, songsList);" 오류 : "adapter = new LazyAdapter (this, songsList);" LazyAdapter 대신이 라인에서 볼 수 있듯이 조각의, 액티비티를 찾고 있기 때문에
나는이 있다고 생각 :public LazyAdapter(Activity a, ArrayList<HashMap<String, String>> d) {
activity = a;
data=d;
inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
imageLoader=new ImageLoader(activity.getApplicationContext());
가 어떻게 그게 내 조각 Feed.java 작업을 얻을 수 있습니까 ??
감사!
당신을 순전히 감사에
에 선
을 변경! – user2913654
XML을 받고 있는지 확인하십시오. 그것을 보려면 로그를 작성하십시오. – Rohit5k2
게시 된 질문을 확실히 수정했습니다. 나는 지금 무관 한 다른 문제에 대해서만 일하고있다. XML에 있어야합니다. 피드에 아무것도 표시되지 않습니다. – user2913654