我在另一个Activity类中使用了相同的模式,它完美地运行.但是在这个类(也是一个Activity)中,从不调用getVIEw.我通过记录fbFrIEndMatchAdapter.getCount()确认适配器中有9个项目.我已经尝试将数据源更改为String []变量,但这对getVIEw的(缺少)没有影响.
我很感激任何建议!我已经彻底研究过了.这个问题有很多种,但都没有解决我的问题.这就是我发布新问题的原因.
//Here is the ArrayList data source deFinition.//It is loaded using a for loop with 9 values.private List<String> fbFrIEndMatchAdapter=new ArrayList<String>();// Here is the Custom Array AdapterArrayAdapter<String> fbFrIEndMatchAdapter = new ArrayAdapter<String>(this, R.layout.row_left, R.ID.ListVIEwname, fbFrIEndPotentialMatchArrayList) { @OverrIDe public VIEw getVIEw(final int dialogposition, VIEw convertVIEw, VIEwGroup ListParent) { LayoutInflater inflater = getLayoutInflater(); VIEw fbFrIEndMatchDialogVIEwRow = inflater.inflate(R.layout.row_left, ListParent, false); Log.d(BBTAG, String.format("BBSetup getVIEw[%s] name=%s", dialogposition, buddydisplayname )); return fbFrIEndMatchDialogVIEwRow; } // [END getVIEw] @OverrIDe public String getItem(int position) { return fbFrIEndPotentialMatchArrayList.get(position); }};//Here is the dialog that includes the ArrayAdapter:AlertDialog fbFrIEndsMatchDialog = new AlertDialog.Builder(new ContextthemeWrapper(context, R.style.PetesspinnerReplacement)) .setTitle("Select Correct Facebook FrIEnd") //FYI overrIDden by custom Title .setAdapter(fbFrIEndMatchAdapter, new DialogInterface.OnClickListener() { @OverrIDe public voID onClick(DialogInterface dialog, int selectedFBFrIEnd) { buddyFBUIDs[buddyNumber] = fbFrIEndUIDsList.get(selectedFBFrIEnd); } }) .setMessage("No matches found") .setCancelable(true) .setPositivebutton("Set as Facebook FrIEnd", new DialogInterface.OnClickListener() { @OverrIDe public voID onClick(DialogInterface dialog, int iFrIEnd) { dialog.dismiss(); } }) .setNegativebutton("FrIEnd Not Listed", new DialogInterface.OnClickListener() { @OverrIDe public voID onClick(DialogInterface dialog, int ID) { dialog.dismiss(); buddyFBUIDs[buddyNumber] = "n/a"; //record lack of FB uID } }) .create(); //build dialogfbFrIEndsMatchDialog.show(); // Now show dialog
解决方法:
我建议不要试图为此内联一个ArrayAdapter子类,因为我相信ArrayAdapter对你的布局和数据结构做了一些假设,可能会让你失望.编写自己的自定义适配器非常简单,我几乎建议不要使用ArrayAdapter(除了最简单的用例).只需子类化BaseAdapter和四个必需的方法,然后使用它.像这样的东西:
private class MatchAdapter extends BaseAdapter { private List<String> mItems; private LayoutInflater mInflater; public MatchAdapter (Context c, List<String> items) { mItems = items; //Cache a reference to avoID looking it up on every getVIEw() call mInflater = LayoutInflater.from(c); } @OverrIDe public int getCount () { return mItems.size(); } @OverrIDe public long getItemID (int position) { return position; } @OverrIDe public Object getItem (int position) { return mItems.get(position); } @OverrIDe public VIEw getVIEw (int position, VIEw convertVIEw, VIEwGroup parent) { //If there's no recycled vIEw, inflate one and tag each of the vIEws //you'll want to modify later if (convertVIEw == null) { convertVIEw = mInflater.inflate (R.layout.row_left, parent, false); //This assumes layout/row_left.xml includes a TextVIEw with an ID of "textvIEw" convertVIEw.setTag (R.ID.textvIEw, convertVIEw.findVIEwByID(R.ID.textvIEw)); } //RetrIEve the tagged vIEw, get the item for that position, and //update the text TextVIEw textVIEw = (TextVIEw) convertVIEw.getTag(R.ID.textvIEw); String textItem = (String) getItem(position); textVIEw.setText(textItem); return convertVIEw; }}
总结 以上是内存溢出为你收集整理的android – 自定义ArrayAdapter getView没有被调用 – 为什么不呢?全部内容,希望文章能够帮你解决android – 自定义ArrayAdapter getView没有被调用 – 为什么不呢?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)