其實我已經創建了一個customListview,在這裏我想動態地添加項目..但在我的情況下,第一個項目插入任何問題,但當我嘗試插入第二個項目..我給一個錯誤,我會發送在code..if有誰知道請建議吧..Listview問題
代碼main.xml中
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:id="@+id/relativeLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<ListView
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:id="@+id/historyFrmLstView2"
android:layout_alignParentLeft="true"
android:layout_below="@+id/historyFrmLstView1"
android:layout_marginTop="20dip"
android:layout_marginBottom="10dip">
</ListView>
</RelativeLayout>
代碼ListView.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:id="@+id/relativeLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:padding="5dip"
android:background="#00000000">
<TextView
android:textSize="18dp"
android:layout_height="wrap_content"
android:textColor="#000000"
android:background="@drawable/history_scroll_title_label_bg"
android:layout_width="wrap_content"
android:id="@+id/txtHistoryDisplay"
android:layout_below="@+id/txtViewHeading"
android:layout_marginTop="0dip"
android:layout_marginLeft="2dip">
</TextView>
</RelativeLayout>
代碼main.java
public void displayHistory()
{
String strDisplay[] = {" "};
historyFrmLstView2 = (ListView) findViewById(R.id.historyFrmLstView2);
int iHistCount = CycleManager.getSingletonObject().getHistoryCount();
int i;
SimpleDateFormat sdFormatter = new SimpleDateFormat("dd-MMMM-yyyy");
for (i=0; i<iHistCount; i++)
{
strDisplay[i] = "";
Date dtHist = CycleManager.getSingletonObject().getHistoryDate(iHistCount);
strDisplay[i]=sdFormatter.format(dtHist.getTime());
aHistFrmAdpter2 = new HistoryFrmCustomAdapter2(this,strDisplay);
historyFrmLstView2.setAdapter(aHistFrmAdpter2);
}
}
代碼定製Adapter.java
public class HistoryFrmCustomAdapter2 extends BaseAdapter
{
public String heading1[];
public Activity context;
public LayoutInflater inflater;
public HistoryFrmCustomAdapter2(Activity context,String[] heading1)
{
super();
this.context = context;
this.heading1=heading1;
this.inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
public int getCount()
{
return heading1.length;
}
public Object getItem(int position)
{
return null;
}
public long getItemId(int position)
{
return 0;
}
public static class ViewHolder
{
TextView txtHistoryDisplay;
}
public View getView(int position, View convertView, ViewGroup parent)
{
ViewHolder holder;
if(convertView==null)
{
holder = new ViewHolder();
convertView = inflater.inflate(R.layout.histryfrm_listview2, null);
holder.txtHistoryDisplay =(TextView) convertView.findViewById(R.id.txtHistoryDisplay);
convertView.setTag(holder);
}
else
holder=(ViewHolder)convertView.getTag();
holder.txtHistoryDisplay.setText(heading1[position]);
return convertView;
}
}
什麼錯誤....是否強制關閉? –
什麼是錯誤? – Sarmad
葉它強制關閉錯誤 – AndroidDev