我正在使用微调器开发Android应用程序。
我有这个问题:
这是微调器数组适配器代码:
public class OrderArticlesAdaper extends ArrayAdapter<Article>
{
private Context mContext;
private int layoutResourceId;
private ArrayList<Article> articles;
public OrderArticlesAdaper(Context context, int listItemResourceId,
ArrayList<Article> dbArticles)
{
super(context, listItemResourceId, dbArticles);
this.mContext = context;
this.layoutResourceId = listItemResourceId;
this.articles = dbArticles;
}
public ArrayList<Article> getArticles()
{
return this.articles;
}
@Override
public int getCount()
{
return articles.size();
}
@Override
public View getView(int position, View convertView, ViewGroup parent)
{
Log.v("OrderArticlesAdaper", "getView.postion: " + position);
View row = convertView;
if (row == null)
{
LayoutInflater inflater = ((Activity)mContext).getLayoutInflater();
row = inflater.inflate(layoutResourceId, parent, false);
}
Article article = articles.get(position);
if (article != null)
{
TextView formNameView = (TextView)row.findViewById(android.R.id.text1);
formNameView.setText(new Long(article.getArticleId()).toString());
}
return row;
}
}
这是加载微调器数据的asynctask:
private class LoadEReportAsyncTask extends AsyncTask<String, Void, Boolean>
{
private Context mContext;
private ProgressDialog loadingDialog;
private EReport eReport;
private QAP qap;
public LoadEReportAsyncTask(Context context)
{
Log.v("LoadEReportAsyncTask", "constructor");
eReport = null;
qap = null;
this.mContext = context;
loadingDialog = new ProgressDialog(mContext);
loadingDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
loadingDialog.setMessage(getString(R.string.msg_loading_ereport));
loadingDialog.setCancelable(false);
loadingDialog.show();
}
@Override
protected Boolean doInBackground(String... params)
{
Log.v("LoadEReportAsyncTask", "doInBackground");
DBManager dbMan;
dbMan = new DBManager(mContext);
// Es un nuevo EReport, por lo tanto lo creo en la base de datos.
if (eReportId == -1)
{
// Time In
TextView aux = (TextView)((EReportFinalInspecActivity) mContext).findViewById(R.id.timeInVal);
Calendar c = Calendar.getInstance();
SimpleDateFormat df3 = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss");
String timeIn = df3.format(c.getTime());
aux.setText(timeIn);
eReport = new EReport();
eReport.setOrderId(orderId);
eReport.setQapId(qapId);
eReport.setTimeIn(timeIn);
eReportId = dbMan.insertEReport(eReport);
}
else
{
eReport = dbMan.getEReport(eReportId);
}
qap = dbMan.getQPA(params[0]);
ordersArticles = dbMan.getOrderArticles(orderId);
selectedArticles = new ArrayList<Article>(ordersArticles.size());
return true; // TODO: Controlar los errores
}
protected void onPostExecute(Boolean result)
{
Log.v("LoadEReportAsyncTask", "onPostExecute");
EReportFinalInspecActivity act = (EReportFinalInspecActivity) mContext;
if (result)
{
Toast.makeText(getApplicationContext(), getString(R.string.msg_ereport_got_correct), Toast.LENGTH_SHORT).show();
act.fillEReport(eReport, qap);
Spinner articleSpin = (Spinner) act.findViewById(R.id.articlesSpiner);
OrderArticlesAdaper spinAdapter = new OrderArticlesAdaper(mContext, android.R.layout.simple_spinner_item, ordersArticles);
spinAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
articleSpin.setAdapter(spinAdapter);
// TODO: Esto hay que cambiarlo porque siempre habrá QAP.
if (qap != null)
act.eReportHasQAP(true, qap.getName());
else
act.eReportHasQAP(false, null);
}
else
{
Toast.makeText(getApplicationContext(), getString(R.string.msg_ereport_problem), Toast.LENGTH_LONG).show();
}
loadingDialog.dismiss();
}
}
我做错了什么?
答案 0 :(得分:1)
尝试:
formNameView.setText(Long.toString(article.getArticleId()));
修改强>
这只是猜测,但也许Android正在使用Article.toString()填充微调器下拉文本视图,因为您的适配器处理Article类型的对象。
要对此进行测试,请覆盖文章类中的toString。
public class Article {
...
@Override
public String toString() {
mArticleId.toString(); // This is the private field holding the long id.
}
}
答案 1 :(得分:0)
这不是干净的方式,但你可以尝试
formNameView.setText(article.getArticleId()+"");