我正在尝试填充一个 ListView ,其中的行包含一个复选框、四个 TextView 和两个微调器。每行微调器中的值需要不同,因为它们与该行上的实际项目直接相关。只是为了让它稍微复杂一点,微调器和它们旁边的两个文本字段是不可见的 (setVisibility(View.GONE)),除非选中该复选框。我只想要列表项可点击(而不是复选框),并且微调器在显示后需要可点击。
我的所有代码都正常工作,除了当微调器被填充时我失去了单击该行上的列表项的能力。我仍然可以从该行的微调器中选择值,但触摸该行的其他任何地方都没有任何作用。有些行不会将数据返回给微调器,它们会继续正常运行,所以我相信这与连接到微调器的适配器有关。
我也知道我将不得不考虑 ListView 的回收,但我还没有做到这一点。
我希望有人能在我完全发疯之前指出这里的错误。
这是 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>
下面是去掉了大部分无关内容的 Activity :
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, from, 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,
android.R.layout.simple_spinner_item, mcurSpin2, from, to );
adapter.setDropDownViewResource( android.R.layout.simple_spinner_dropdown_item);
mSpin2.setAdapter(adapter);
}
@Override
protected 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 添加到最顶部的线性布局。这可能会有所帮助。
关于当列表行中填充微调器时,android onListItemClick 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10695451/
我在从html页面生成PDF时遇到问题。我正在使用PDFkit。在安装它的过程中,我注意到我需要wkhtmltopdf。所以我也安装了它。我做了PDFkit的文档所说的一切......现在我在尝试加载PDF时遇到了这个错误。这里是错误:commandfailed:"/usr/local/bin/wkhtmltopdf""--margin-right""0.75in""--page-size""Letter""--margin-top""0.75in""--margin-bottom""0.75in""--encoding""UTF-8""--margin-left""0.75in""-
我在我的项目目录中完成了compasscreate.和compassinitrails。几个问题:我已将我的.sass文件放在public/stylesheets中。这是放置它们的正确位置吗?当我运行compasswatch时,它不会自动编译这些.sass文件。我必须手动指定文件:compasswatchpublic/stylesheets/myfile.sass等。如何让它自动运行?文件ie.css、print.css和screen.css已放在stylesheets/compiled。如何在编译后不让它们重新出现的情况下删除它们?我自己编译的.sass文件编译成compiled/t
我正在使用的第三方API的文档状态:"[O]urAPIonlyacceptspaddedBase64encodedstrings."什么是“填充的Base64编码字符串”以及如何在Ruby中生成它们。下面的代码是我第一次尝试创建转换为Base64的JSON格式数据。xa=Base64.encode64(a.to_json) 最佳答案 他们说的padding其实就是Base64本身的一部分。它是末尾的“=”和“==”。Base64将3个字节的数据包编码为4个编码字符。所以如果你的输入数据有长度n和n%3=1=>"=="末尾用于填充n%
我花了三天的时间用头撞墙,试图弄清楚为什么简单的“rake”不能通过我的规范文件。如果您遇到这种情况:任何文件夹路径中都不要有空格!。严重地。事实上,从现在开始,您命名的任何内容都没有空格。这是我的控制台输出:(在/Users/*****/Desktop/LearningRuby/learn_ruby)$rake/Users/*******/Desktop/LearningRuby/learn_ruby/00_hello/hello_spec.rb:116:in`require':cannotloadsuchfile--hello(LoadError) 最佳
是否有类似“RVMuse1”或“RVMuselist[0]”之类的内容而不是键入整个版本号。在任何时候,我们都会看到一个可能包含5个或更多ruby的列表,我们可以轻松地键入一个数字而不是X.X.X。这也有助于rvmgemset。 最佳答案 这在RVM2.0中是可能的=>https://docs.google.com/document/d/1xW9GeEpLOWPcddDg_hOPvK4oeLxJmU3Q5FiCNT7nTAc/edit?usp=sharing-知道链接的任何人都可以发表评论
关闭。这个问题需要detailsorclarity.它目前不接受答案。想改进这个问题吗?通过editingthispost添加细节并澄清问题.关闭8年前。Improvethisquestion在首页我有:汽车:VolvoSaabMercedesAudistatic_pages_spec.rb中的测试代码:it"shouldhavetherightselect"dovisithome_pathit{shouldhave_select('cars',:options=>['volvo','saab','mercedes','audi'])}end响应是rspec./spec/request
在Rails4.0.2中,我使用s3_direct_upload和aws-sdkgems直接为s3存储桶上传文件。在开发环境中它工作正常,但在生产环境中它会抛出如下错误,ActionView::Template::Error(noimplicitconversionofnilintoString)在View中,create_cv_url,:id=>"s3_uploader",:key=>"cv_uploads/{unique_id}/${filename}",:key_starts_with=>"cv_uploads/",:callback_param=>"cv[direct_uplo
我有一个驼峰式字符串,例如:JustAString。我想按照以下规则形成长度为4的字符串:抓取所有大写字母;如果超过4个大写字母,只保留前4个;如果少于4个大写字母,则将最后大写字母后的字母大写并添加字母,直到长度变为4。以下是可能发生的3种情况:ThisIsMyString将产生TIMS(大写字母);ThisIsOneVeryLongString将产生TIOV(前4个大写字母);MyString将生成MSTR(大写字母+tr大写)。我设法用这个片段解决了前两种情况:str.scan(/[A-Z]/).first(4).join但是,我不太确定如何最好地修改上面的代码片段以处理最后一种
使用Ruby1.9.2运行IDE提示说需要gemruby-debug-base19x并提供安装它。但是,在尝试安装它时会显示消息Failedtoinstallgems.Followinggemswerenotinstalled:C:/ProgramFiles(x86)/JetBrains/RubyMine3.2.4/rb/gems/ruby-debug-base19x-0.11.30.pre2.gem:Errorinstallingruby-debug-base19x-0.11.30.pre2.gem:The'linecache19'nativegemrequiresinstall
我知道全局变量$!包含最新的异常对象,但我对下面的语法感到困惑。谁能帮助我理解以下语法?rescue$! 最佳答案 此构造可防止异常停止您的程序并使堆栈跟踪冒泡。它还会将该异常作为值返回,这很有用。a=get_me_datarescue$!在此行之后,a将保存请求的数据或异常。然后您可以分析该异常并采取相应措施。defget_me_dataraise'Nodataforyou'enda=get_me_datarescue$!puts"Executioncarrieson"pa#>>Executioncarrieson#>>#更现实的