在初始化充气机时填充我的 customList 时出现错误。LogCat 错误:
android.view.InflateException: Binary XML file line #20: Error inflating class
我成功填充了一个hashmap<string, string>
。然后我将它添加到arrayList<HashMap<string, string>.
.. 所有这些都在后台线程中。
然后我得到我的列表' list=(ListView)findViewById(R.id.list);
'和 setAdapter。
更新了我的问题 - 如果我从 contact_list_row.xml 中删除图像视图,它会起作用!这让我头疼!
当我运行以下行时出现错误
vi = inflater.inflate(R.layout.contact_list_row, null);
有趣的是,一旦我收到“应用程序已停止”错误并退出活动并再次按下它,就会填充自定义列表视图。
class refreshThread extends AsyncTask<String, String, String>
{
/**
* Before starting background thread Show Progress Dialog
* */
@Override
protected void onPreExecute()
{
super.onPreExecute();
rDialog = new ProgressDialog(Cool_Activity.this);
rDialog.setMessage("Analysing your buddys. Please wait...");
rDialog.setIndeterminate(false);
rDialog.setCancelable(false);
rDialog.show();
}
@SuppressWarnings("unchecked")
@Override
protected String doInBackground(String... args)
{
//What to output in each listitem in UI
HashMap<String, String> map = new HashMap<String, String>();
map.put("id", "1");
map.put("contact", contact);
map.put("Sent", "Sent: "+"0.1");
map.put("Received", "Received: "+String.format("%.1f", score));
map.put("duration", type);
map.put("thumb_url", "http://upload.wikimedia.org/wikipedia/commons/d/d3/Albert_Einstein_Head.jpg");
map.put("sent_value", "0.01");
map.put("rec_value", score.toString());
// adding HashList to ArrayList
resultsList.add(map);
//}
return null;
}
/**
* After completing background task Dismiss the progress dialog
* **/
protected void onPostExecute(String file_url)
{
// dismiss the dialog after getting all questions
rDialog.dismiss();
// updating UI from Background Thread
runOnUiThread(new Runnable()
{
public void run()
{
/**
* Updating stats ui
* */
list=(ListView)findViewById(R.id.list);
// Getting adapter by passing xml data ArrayList
adapter=new Contacts_LazyAdapter(Cool_Activity.this, resultsList);
list.setAdapter(adapter);
// Click event for single list row
/* list.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,int position, long id) {
}
});*/
}
});
}
}
我的适配器逻辑....
public class Contacts_LazyAdapter extends BaseAdapter {
private Activity activity;
private ArrayList <HashMap<String, String>> data;
private static LayoutInflater inflater=null;
public Contacts_LazyAdapter(Activity a, ArrayList<HashMap<String, String>> d) {
activity = a;
data=d;
inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
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.contact_list_row, null);
TextView contact= (TextView)vi.findViewById(R.id.textView_name); // contact
TextView sent = (TextView)vi.findViewById(R.id.TextView_SentResult); // sent result
TextView received = (TextView)vi.findViewById(R.id.TextView_ReceivedResult); // received result
TextView duration = (TextView)vi.findViewById(R.id.duration); // possible future change ...
ImageView sent_image=(ImageView)vi.findViewById(R.id.image_app); //get sent personalitymage
ImageView rec_image=(ImageView)vi.findViewById(R.id.rec_image); // get received personality image
HelpfulMethods helpful = new HelpfulMethods();
HashMap<String, String> contact_info = new HashMap<String, String>();
contact_info = data.get(position);
// Setting all values in listview
contact.setText(contact_info.get(Contacts_CompositeListViewActivity.KEY_CONTACT));
sent.setText(contact_info.get(Contacts_CompositeListViewActivity.KEY_SENT));
received.setText(contact_info.get(Contacts_CompositeListViewActivity.KEY_RECEIVED));
duration.setText(contact_info.get(Contacts_CompositeListViewActivity.KEY_DURATION));
helpful.getDrawableFile((float) Double.parseDouble(contact_info.get(Contacts_CompositeListViewActivity.KEY_SENT_VALUE)), sent_image);
helpful.getDrawableFile((float) Double.parseDouble(contact_info.get(Contacts_CompositeListViewActivity.KEY_REC_VALUE)), rec_image);
return vi;
}
}
Contact_List_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="@drawable/list_selector"
android:orientation="horizontal"
android:padding="5dip" >
<!-- ListRow Left sied Thumbnail image -->
<LinearLayout
android:id="@+id/thumbnail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginRight="5dip"
android:background="@drawable/image_bg"
android:padding="3dip" >
<ImageView
android:id="@+id/image_app"
android:layout_width="50dip"
android:layout_height="50dip"
android:src="@drawable/red" />
</LinearLayout>
<!-- Title Of Song -->
<TextView
android:id="@+id/textView_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@id/thumbnail"
android:layout_toRightOf="@id/thumbnail"
android:text="Niamh"
android:textColor="#040404"
android:textSize="15dip"
android:textStyle="bold"
android:typeface="sans" />
<!-- Artist Name -->
<TextView
android:id="@+id/TextView_SentResult"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_below="@id/textView_name"
android:layout_marginTop="1dip"
android:layout_toRightOf="@id/thumbnail"
android:text="Sent: 17.5"
android:textColor="#343434"
android:textSize="18dip" />
<!-- Rightend Duration -->
<TextView
android:id="@+id/duration"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignTop="@id/textView_name"
android:layout_marginRight="5dip"
android:gravity="right"
android:text="5:45"
android:textColor="#10bcc9"
android:textSize="10dip"
android:textStyle="bold"
android:visibility="invisible" />
<!-- Rightend Arrow -->
<ImageView
android:id="@+id/imageView_icon"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:src="@drawable/arrow_blue"
android:visibility="invisible" />
<LinearLayout
android:id="@+id/thumbnail2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@id/duration"
android:layout_toLeftOf="@id/duration"
android:background="@drawable/image_bg"
android:padding="3dip" >
<ImageView
android:id="@+id/rec_image"
android:layout_width="50dip"
android:layout_height="50dip"
android:layout_centerVertical="true"
android:src="@drawable/red" />
</LinearLayout>
<TextView
android:id="@+id/TextView_ReceivedResult"
android:layout_width="120dp"
android:layout_height="wrap_content"
android:layout_alignBaseline="@id/TextView_SentResult"
android:layout_alignBottom="@id/TextView_SentResult"
android:layout_marginLeft="22dp"
android:layout_toRightOf="@id/textView_name"
android:text="Received: 16.5"
android:textColor="#343434"
android:textSize="18dip" />
</RelativeLayout>