ListView를 어댑터와 함께 사용하는 방법을 배우고 있습니다. 여기에 게시 할 코드는 Here 의 자습서 중 하나입니다.이 클래스는 ListView를 초기화하고 어댑터에 데이터를 제공하는 클래스입니다 (자습서의 MainActvity 클래스와 동등 함).ListView 및 어댑터를 사용하여 빈 활동이 있습니다.
setContentView(R.layout.searchresultrowlayout);
try {
jsonarray1=searchscreen.searchresults();
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
ArrayList<HashMap<String, String>> propertylist=new ArrayList<HashMap<String, String>>();
for(int i=0;i<jsonarray1.length();i++){
HashMap<String,String> propertymap=new HashMap<String,String>();
try {
jsonobject=jsonarray1.getJSONObject(i);
Log.d("json", jsonobject.getString("id"));
propertymap.put("propertytype",jsonobject.getString("propertytype"));
propertylist.add(propertymap);
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
list=(ListView)findViewById(R.id.list);
adapter=new PropertySearchArrayAdapter(this,propertylist);
// Log.d("adapter", propertylist.get(1).get("price").toString());
list.setAdapter(adapter);
list.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
}
});
이 내 어댑터 클래스
public class PropertySearchArrayAdapter extends BaseAdapter{
private Activity activity;
private ArrayList<HashMap<String,String>> data;
private static LayoutInflater inflater=null;
//public ImageLoader imageloader;
public PropertySearchArrayAdapter(Activity context, ArrayList<HashMap<String,String>> d){
activity=context;
data=d;
inflater=(LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
@Override
public View getView(int position,View convertview, ViewGroup parent){
View rowview=convertview;
if(convertview==null){
rowview=inflater.inflate(R.layout.searchlist_row, null);}
//ViewHolder viewholder=new ViewHolder();
TextView propertyType=(TextView) rowview.findViewById(R.id.propertytype); //propertytype
HashMap<String,String> property= new HashMap<String,String>();
property= data.get(position);
propertyType.setText(property.get("propertytype"));
Log.d("adaptertext", property.get("propertytype"));
return rowview;
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return 0;
}
@Override
public Object getItem(int arg0) {
// TODO Auto-generated method stub
return null;
}
@Override
public long getItemId(int arg0) {
// TODO Auto-generated method stub
return 0;
}
}
입니다 이러한 XMLS
searchresultrowlayout
<?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:orientation="vertical" >
<ListView
android:id="@+id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:divider="#b5b5b5"
android:dividerHeight="1dp"
android:listSelector="@drawable/list_selector" />
</LinearLayout>
searchlist_row
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#FFFFFF"
android:orientation="horizontal"
android:padding="5dip" >
<!-- Property type-->
<TextView
android:id="@+id/propertytype"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#040404"
android:typeface="sans"
android:textSize="15dip"
android:textStyle="bold"/>
</RelativeLayout>
입니다
다른 XML list_selector, gradient_bg.xml, gradient_bg_hover.xml 자체는 tutorial에서 가져 왔습니다.
내 문제는 목록보기 (버튼 클릭시 이전 활동의 의도에 의한)를 표시해야하는 내 활동을 푸시 할 때 나타나는 화면이 완전히 검게 표시됩니다. 도와주세요.
예외 추적 스택 추적 및 게시가있을 수 있습니다. – Pragnani
답장을 보내 주셔서 감사 드리며 예외 나 경고가 없습니다. – user1581539
목록에 데이터가 포함되어 있습니까? ..? – Pragnani