我的所有代码都正常工作,除了当填充微调器时,我失去了单击该行上的列表项的能力.我仍然可以从该行上的微调器中选择值,但触摸该行上的任何其他位置都没有任何作用.有些行不会将数据返回到微调器,并且它们继续正常运行,因此我认为它与连接到微调器的适配器有关.
此外,我知道我将不得不考虑列表视图回收,但我还没有那么远.
我希望有人能在我完全疯了之前指出这里有什么问题.
这是ListvIEw xml
<ListVIEw androID:ID="@+ID/androID:List" androID:layout_wIDth="fill_parent" androID:layout_height="fill_parent"/><TextVIEw androID:ID="@+ID/androID:empty" androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:text="@string/empty"/></linearLayout>
这是行xml
<linearLayout xmlns:androID="http://schemas.androID.com/apk/res/androID" androID:orIEntation="vertical" androID:layout_wIDth="fill_parent" androID:layout_height="fill_parent"> <linearLayout androID:orIEntation="horizontal" androID:layout_wIDth="fill_parent" androID:layout_height="wrap_content"> <CheckBox androID:ID="@+ID/pl_selected" androID:layout_wIDth="fill_parent" androID:layout_height="wrap_content" androID:focusableIntouchMode="false" androID:clickable="false" androID:focusable="false" androID:layout_weight="1"/> <TextVIEw androID:ID="@+ID/name" androID:layout_wIDth="fill_parent" androID:layout_height="wrap_content" androID:layout_weight="1" androID:focusableIntouchMode="false" androID:clickable="false" androID:focusable="false"/> <TextVIEw androID:ID="@+ID/name2" androID:layout_wIDth="fill_parent" androID:layout_height="wrap_content" androID:layout_weight="1" androID:focusableIntouchMode="false" androID:clickable="false" androID:focusable="false"/></linearLayout><linearLayout androID:orIEntation="horizontal" androID:layout_wIDth="fill_parent" androID:layout_height="wrap_content"> <TextVIEw androID:ID="@+ID/pl_tv1" androID:text="@string/pl_tv1" androID:layout_wIDth="fill_parent" androID:layout_height="wrap_content" androID:layout_weight="1" androID:focusableIntouchMode="false" androID:clickable="false" androID:focusable="false" androID:visibility="gone"/> <Spinner androID:ID="@+ID/pl_spin1" androID:layout_wIDth="fill_parent" androID:layout_height="wrap_content" androID:layout_weight="1" androID:visibility="gone" androID:focusableIntouchMode="false" androID:focusable="false"/></linearLayout><linearLayout androID:orIEntation="horizontal" androID:layout_wIDth="fill_parent" androID:layout_height="wrap_content"> <TextVIEw androID:ID="@+ID/pl_tv2" androID:text="@string/pl_tv2" androID:layout_wIDth="fill_parent" androID:layout_height="wrap_content" androID:layout_weight="1" androID:focusableIntouchMode="false" androID:clickable="false" androID:focusable="false" androID:visibility="gone"/> <Spinner androID:ID="@+ID/pl_spin2" androID:layout_wIDth="fill_parent" androID:layout_height="wrap_content" androID:layout_weight="1" androID:visibility="gone" androID:focusableIntouchMode="false" androID:focusable="false"/></linearLayout></linearLayout>
以下是大多数不相关的东西的活动:
import androID.Widget.SimpleCursorAdapter;import mdhsoft.band.Tab.DbAdapter;import mdhsoft.band.Tab.R;import androID.os.Bundle;import androID.app.ListActivity;import androID.database.Cursor;import androID.vIEw.Menu;import androID.vIEw.MenuItem;import androID.vIEw.VIEw;import androID.vIEw.VIEwGroup;import androID.Widget.CheckBox;import androID.Widget.ListVIEw;import androID.Widget.Spinner;import androID.Widget.TextVIEw;public class PLActivity extends ListActivity { private static final int DONE_ID = Menu.FirsT; private DbAdapter mDbHelper;private int mPlID;private CheckBox mCheckBox;private Spinner mSpin1;private Spinner mSpin2;private TextVIEw mtv1;private TextVIEw mtv2;private int mItemID; private SimpleCursorAdapter mAllitems;private Cursor mSCursor;private Cursor mcurSpin1;private Cursor mcurSpin2; public voID onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentVIEw(R.layout.pl_List); Bundle extras = getIntent().getExtras(); mPlID = extras.getInt(DbAdapter.KEY_PLID); mDbHelper = new DbAdapter(this); mDbHelper.open(); fillData(); registerForContextMenu(getListVIEw()); }private voID fillData() { mSCursor = mDbHelper.fetchAllPl(mPlID); startManagingCursor(mSCursor); String[] from = new String[] {"pl_selected",DbAdapter.KEY_Sname,DbAdapter.KEY_Sname2}; int[] to = new int[]{R.ID.pl_selected,R.ID.name,R.ID.name2}; mAllitems = new SimpleCursorAdapter(this,R.layout.pl_row,mSCursor,from,to); mAllitems.setVIEwBinder(new SimpleCursorAdapter.VIEwBinder() { public boolean setVIEwValue(VIEw vIEw,Cursor cursor,int columnIndex) { if(columnIndex == 3) { CheckBox cb = (CheckBox) vIEw; cb.setChecked(cursor.getInt(3) > 0); VIEwGroup row = (VIEwGroup)vIEw.getParent(); if (cursor.getInt(3) > 0) { mcurSpin1 = (Spinner) row.findVIEwByID(R.ID.pl_spin1); mcurSpin2 = (Spinner) row.findVIEwByID(R.ID.pl_spin2); mtv1 = (TextVIEw) row.findVIEwByID(R.ID.pl_tv1); mtv2 = (TextVIEw) row.findVIEwByID(R.ID.pl_tv2); mcurSpin1.setVisibility(VIEw.VISIBLE); mtv1.setVisibility(VIEw.VISIBLE); mcurSpin2.setVisibility(VIEw.VISIBLE); mtv2.setVisibility(VIEw.VISIBLE); PopulateSpinner1(); PopulateSpinner2(); } return true; } return false; } }); setlistadapter(mAllitems);}private voID PopulateSpinner1(){ mcurSpin1 = mDbHelper.fetchSByItemID(mItemID); startManagingCursor(mcurSpin1); String[] from = new String[]{DbAdapter.KEY_Sname}; int[] to = new int[]{androID.R.ID.text1}; SimpleCursorAdapter adapter = new SimpleCursorAdapter(this,androID.R.layout.simple_spinner_item,mcurSpin1,to ); adapter.setDropDownVIEwResource( androID.R.layout.simple_spinner_dropdown_item); mSpin1.setAdapter(adapter);}private voID PopulateSpinner2(){ mcurSpin2 = mDbHelper.fetchMByItemID(mItemID); startManagingCursor(mcurSpin2); String[] from = new String[]{DbAdapter.KEY_Mname}; int[] to = new int[]{androID.R.ID.text1}; SimpleCursorAdapter adapter = new SimpleCursorAdapter(this,mcurSpin2,to ); adapter.setDropDownVIEwResource( androID.R.layout.simple_spinner_dropdown_item); mSpin2.setAdapter(adapter);}@OverrIDeprotected voID onListItemClick(ListVIEw l,VIEw v,int position,long ID) { super.onListItemClick(l,v,position,ID); VIEwGroup row = (VIEwGroup)v; mSCursor.movetoposition(position); mItemID = mSCursor.getInt(mSCursor.getColumnIndex(DbAdapter.KEY_SID)); mCheckBox = (CheckBox) row.findVIEwByID(R.ID.pl_selected); mcurSpin1 = (Spinner) row.findVIEwByID(R.ID.pl_spin1);mcurSpin2 = (Spinner) row.findVIEwByID(R.ID.pl_spin1);mtv1 = (TextVIEw) row.findVIEwByID(R.ID.pl_tv1);mtv2 = (TextVIEw) row.findVIEwByID(R.ID.pl_tv2); if (mCheckBox.isChecked()) { mCheckBox.setChecked(false); mcurSpin1.setVisibility(VIEw.GONE); mtv1.setVisibility(VIEw.GONE); mcurSpin2.setVisibility(VIEw.GONE); mtv2.setVisibility(VIEw.GONE);} else { mCheckBox.setChecked(true); mcurSpin1.setVisibility(VIEw.VISIBLE); mtv1.setVisibility(VIEw.VISIBLE); mcurSpin2.setVisibility(VIEw.VISIBLE); PopulateSpinner1(); PopulateSpinner2(); } }}
在此先感谢您提供任何帮助.
解决方法 您可以尝试将androID:descendantFocussability = blocksDescendants添加到最顶部的线性布局.这可能会有所帮助. 总结以上是内存溢出为你收集整理的当listrow中填充了微调器时,android onListItemClick无法正常工作全部内容,希望文章能够帮你解决当listrow中填充了微调器时,android onListItemClick无法正常工作所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)