0

代码根据此示例进行更改。相关文件在下面指定。我没有使用该示例的 imageicon 部分,因为我不需要它。

待定.java

public class Pending {

public String title;
public Pending(){
    super();
}

public Pending(String title) {
    super();

    this.title = title;
}

}

PendingAdatapter.java

public PendingAdapter(Context context, int layoutResourceId, Pending[] data) {

    super(context, layoutResourceId, data);
    this.layoutResourceId = layoutResourceId;
    this.context = context;
    this.data = data;

}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    View row = convertView;
   PendingHolder holder = null;

   if(row == null)
   {
       LayoutInflater inflater = ((Activity)context).getLayoutInflater();
       row = inflater.inflate(layoutResourceId, parent, false);

       holder = new PendingHolder();

       holder.txtTitle = (TextView)row.findViewById(R.id.txtTitle);

       row.setTag(holder);
   }
   else
   {
       holder = (PendingHolder)row.getTag();
   }

   Pending weather = data[position];
   holder.txtTitle.setText(weather.title);

   return row;

}

static class PendingHolder
{

    TextView txtTitle;
}

MainActivity.java

WayDataBase way1=new WayDataBase(Dashboard.this);
    Pending weather_data[] = new Pending[]
            {

                new Pending(way1.returnFormName().toString())
            };

    PendingAdapter adapter = new PendingAdapter(this, 
            R.layout.listview_item_row, weather_data);
    lstvw=(ListView)findViewById(R.id.forms_list);

    View header = (View)getLayoutInflater().inflate(R.layout.listview_header_row, null);
    lstvw.addHeaderView(header);

    lstvw.setAdapter(adapter);

数据库的returnFormname函数

public ArrayList<String> returnFormName()
{

    openOrCreateDatabase();
    createlandtTable();
    createrefertable();
    createassettable();
    createofficeusetable();
    ArrayList<String> form = new ArrayList<String>();

    int appcount=0,refercount=0,assetcount=0,officecount=0;
    appcount=db.rawQuery("select * from "+TableNameis+";" ,null).getCount();
    refercount=db.rawQuery("select * from "+ReferenceTable+";" ,null).getCount();
    assetcount=db.rawQuery("select * from "+AssetTable+";" ,null).getCount();
    officecount=db.rawQuery("select * from "+OfficeUse+";" ,null).getCount();
    if(appcount==0)
    {
        form.add("Applicant");
    }
    if(refercount==0)
    {
        form.add("Reference");
    }
    if(assetcount==0)
    {
        form.add("Asset Details");
    }
    if(officecount==0)
    {
        form.add("Office Use");
    }

    return form;
}
4

2 回答 2

0

你的问题是这条线formname.add(way1.returnFormName().toString());。我不知道WayDataBase返回什么,但你想要做的是将每个值添加way1formname. 您所做的是以way1.returnFormName()字符串形式返回对象的单个表示,这就是toString()所做的。

从中获取每个值way1.returnFormName()并将其添加到formname自身。

注意:要将intor转换double为 a String,只需将空字符串连接到它。前任。

int number = 5;
String some;
some = number +"";
于 2013-04-15T06:30:46.087 回答
0

像这样更改您的代码

MainActivity.java

WayDataBase way1=new WayDataBase(Dashboard.this);
ArrayList<String> weather_data = way1.returnFormName();    

PendingAdapter adapter = new PendingAdapter(this, R.layout.listview_item_row, weather_data);
lstvw=(ListView)findViewById(R.id.forms_list);

View header = (View)getLayoutInflater().inflate(R.layout.listview_header_row, null);
lstvw.addHeaderView(header);

lstvw.setAdapter(adapter);

PendingAdatapter.java

public PendingAdapter(Context context, int layoutResourceId, ArrayList<String> data) {
    super(context, layoutResourceId, data);
    this.layoutResourceId = layoutResourceId;
    this.context = context;
    this.data = data;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
   View row = convertView;
   PendingHolder holder = null;

   if(row == null)
   {
      LayoutInflater inflater = ((Activity)context).getLayoutInflater();
      row = inflater.inflate(layoutResourceId, parent, false);

      holder = new PendingHolder();

      holder.txtTitle = (TextView)row.findViewById(R.id.txtTitle);

      row.setTag(holder);
   }
   else
   {
      holder = (PendingHolder)row.getTag();
   }

   holder.txtTitle.setText(data.get(position));
   return row;
}
于 2013-04-15T08:16:52.977 回答