是否可以将窗口小部件宽度指定为可用屏幕宽度的一半,并使用声明性xml进行操作?
我希望我的应用程序将应用程序DB存档到SD卡.在我的代码中,我检查目录是否canWrite()
存在,如果不存在,则抛出一个IOException
.在这个特定的实例中,我试图将db文件复制到SD卡上的根目录,但它正在抛出一个IOException
.如何更改文件夹/文件的权限才能写入?
当Items布局有可点击/可编辑的小部件(RadioButton,EditText或CheckBox)时,是否可以在ListView上使用OnItemClickListener?
我在AlertDialog中使用ListView来显示项目列表.当用户点击其中一个项目时,我希望关闭对话框.我不会在对话框上有任何操作按钮.关于如何实现这一目标的任何想法?
我使用以下代码为AutoCompleteTextView设置适配器(SimpleCursorAdapter)
mComment = (AutoCompleteTextView) findViewById(R.id.comment);
Cursor cComments = myAdapter.getDistinctComments();
scaComments = new SimpleCursorAdapter(this,R.layout.auto_complete_item,cComments,new String[] {DBAdapter.KEY_LOG_COMMENT},new int[]{R.id.text1});
mComment.setAdapter(scaComments);
Run Code Online (Sandbox Code Playgroud)
auto_complete_item.xml
<?xml version="1.0" encoding="utf-8"?>
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
Run Code Online (Sandbox Code Playgroud)
而thi是实际控件的xml
<AutoCompleteTextView
android:id="@+id/comment"
android:hint="@string/COMMENT"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="18dp"/>
Run Code Online (Sandbox Code Playgroud)
下拉列表似乎正常工作,并显示项目列表.当我从列表中做出选择时,我在textview中得到一个sqlite对象('android.database.sqlite.SQLiteCursor @'...).任何人都知道会导致这种情况,或者如何解决这个问题?
谢谢
好的我能够挂钩OnItemClick事件,但AutoCompleteTextView小部件的TextView.setText()部分在此之后更新.OnItemSelected()事件永远不会被触发,并且在首次显示下拉项时会触发onNothingSelected()事件.
mComment.setOnItemClickListener( new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
// TODO Auto-generated method stub
SimpleCursorAdapter sca = (SimpleCursorAdapter) arg0.getAdapter();
String str = getSpinnerSelectedValue(sca,arg2,"comment");
TextView txt = (TextView) arg1;
txt.setText(str);
Toast.makeText(ctx, "onItemClick", Toast.LENGTH_SHORT).show();
}
});
mComment.setOnItemSelectedListener(new OnItemSelectedListener() …
Run Code Online (Sandbox Code Playgroud) 我收到了从spinner.getSelectedItem().toString()调用返回的文本'android.database.sqlite.SQLiteCursor@435b9ba0'.我不知道为什么.微调器绑定到SimpleCursorAdapter.
这是代码
cCategories = (Cursor) myAdapter.getAllCategories();
this.startManagingCursor(cCategories);
SimpleCursorAdapter scaCategories = new SimpleCursorAdapter(this, R.layout.track_category_item,cCategories,new String[] {DBAdapter.KEY_CATEGORIES_NAME},new int[]{R.id.text1});
scaCategories.setDropDownViewResource(R.layout.track_category_dropdown_item);
mCatSpinner = (Spinner) findViewById(R.id.thecategory);
mCatSpinner.setAdapter(scaCategories);
if(mCatSpinner.isSelected() != true) {
mCatSpinner.setSelection(0);
}
Run Code Online (Sandbox Code Playgroud)
和xml track_category_item.xml
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@android:id/text1"
style="?android:attr/spinnerItemStyle"
android:ellipsize="marquee"
android:singleLine="true">
</TextView>
Run Code Online (Sandbox Code Playgroud)
track_category_dropdown_item.xml
<CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/text1"
style="?android:attr/spinnerDropDownItemStyle"
android:singleLine="true"
android:layout_width="fill_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:ellipsize="marquee" />
Run Code Online (Sandbox Code Playgroud)
spinner xml看起来像这样
<Spinner
android:id="@+id/thecategory"
android:prompt="@string/SELECT_CATEGORY"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_x="15px"
android:layout_y="133px" >
</Spinner>
Run Code Online (Sandbox Code Playgroud)
并且返回的光标是
public Cursor getAllCategories()
{
return db.query(DATABASE_CATEGORIES_TABLE, new String[] {
KEY_CATEGORIES_ROWID,
KEY_CATEGORIES_NAME,
KEY_CATEGORIES_DEFAULT},
null,
null,
null,
null,
null);
} …
Run Code Online (Sandbox Code Playgroud) 我正在使用以下xml将输入限制为仅在EditText小部件中为数字。android:digits属性使用以下数组资源。除了我无法输入数字4(即使它在数组中)的事实之外,其他所有功能都运行良好。有任何想法吗?
<EditText
android:id="@+id/mynumber"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="40dp"
android:textStyle="bold"
android:gravity="center_horizontal"
android:layout_centerHorizontal="true"
android:textColor="#aaffaa"
android:numeric="integer"
android:digits="@array/digits"
android:background="#00000000"
android:inputType="phone"
android:focusable="true"
android:singleLine="true" />
Run Code Online (Sandbox Code Playgroud)
字符串数组资源摘录:
<string-array name="digits">
<item>0</item>
<item>1</item>
<item>2</item>
<item>3</item>
<item>4</item>
<item>5</item>
<item>6</item>
<item>7</item>
<item>8</item>
<item>9</item>
</string-array>
Run Code Online (Sandbox Code Playgroud) 在这个链接的图像中,我经常在许多应用程序中看到右侧的按钮.在我的Moto Droid上,它在设置应用程序中被广泛使用.它也用作默认的AlertDialog图标.我可以通过android.r.drawable使用它吗?
将设备放入汽车文档时,是否可以自动启动应用程序?像谷歌地图一样,我知道它利用了码头中的磁铁.我在哪里查看API来实现这一目标?
谢谢
帕特里克
我有以下布局xml.我试图将TextView放在左边,将Radiobutton放到右边.我怎么能做到这一点?
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/txtVehName"
android:hint="@string/VEH_NAME"
android:textSize="18sp"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
</TextView>
<RadioButton
android:id="@+id/rbDefault"
android:text=""
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</RadioButton>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
谢谢
帕特里克