Tom*_*ble 4 java xml eclipse android android-layout
我正在尝试在Eclipse上为我的Android手机编写一个光盘高尔夫评分应用程序.我想为最多6名玩家设置它,但大多数人会将其用于游戏.数据存储在sqlite数据库中,我使用SimpleCursorAdapter来填充已经评分过的漏洞的数据.这是代码:
private void fillData() {
Cursor notesCursor = mDbHelper.fetchAllNotes();
startManagingCursor(notesCursor);
// Create an array to specify the fields we want to display in the list (only TITLE)
String[] from = new String[]{DiscGolfDbAdapter.KEY_HOLE,
DiscGolfDbAdapter.KEY_PAR,
DiscGolfDbAdapter.KEY_TOM_HOLE,
DiscGolfDbAdapter.KEY_TOM_GAME,
DiscGolfDbAdapter.KEY_CRAIG_HOLE,
DiscGolfDbAdapter.KEY_CRAIG_GAME,
DiscGolfDbAdapter.KEY_TOMS_POSITION,
DiscGolfDbAdapter.KEY_SKIP_PLAYER
};
// and an array of the fields we want to bind those fields to (in this case just text1)
int[] to = new int[]{R.id.schole, R.id.scpar, R.id.scth, R.id.sctg, R.id.scch, R.id.sccg, R.id.sctp,
R.id.skip};
// Now create a simple cursor adapter and set it to display
SimpleCursorAdapter notes =
new SimpleCursorAdapter(this, R.layout.hole_info, notesCursor, from, to);
setListAdapter(notes);
}
Run Code Online (Sandbox Code Playgroud)
从搜索互联网我发现我认为应该有两个可行的东西,但不是.
首先,我尝试了XML属性:android.visibility.在我试图"测试"隐藏的视图的PORTION中看起来像这样:
<LinearLayout android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android.visibility="GONE">
<TextView android:id="@+id/scch"
android:layout_width="45dip"
android:gravity="right"
android:textSize="25sp"
android:layout_height="wrap_content"/>
<TextView android:id="@+id/sccg"
android:layout_width="45dip"
android:gravity="right"
android:textSize="25sp"
android:layout_height="wrap_content"/>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
我试过"GONE","Gone"和"gone".他们中没有人在日食模拟器或我的实际手机上工作.因此,尝试参数化此属性没有意义.
接下来我尝试将android:layout_height的XML属性设置为"0dip".这确实适用于模拟器和我的手机,当它被硬编码时.
然后我移动到下一个逻辑步骤(我看到它),在DB中存储一个参数,以便我可以"显示"或"不显示"记录中条件的项目依赖项.所以,我在DB中存储了一个字段,其中包含两个值"0dip"和"wrap_content".我将这些传递给布局,如上面的java中所示为R.id.skip.我还将这些添加到输出中,只是为了审核它们确实在那里.这是XML:
<LinearLayout android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="@+id/skip">
<TextView android:id="@+id/scch"
android:layout_width="45dip"
android:gravity="right"
android:textSize="25sp"
android:layout_height="wrap_content"/>
<TextView android:id="@+id/sccg"
android:layout_width="45dip"
android:gravity="right"
android:textSize="25sp"
android:layout_height="wrap_content"/>
</LinearLayout>
<TextView android:id="@+id/skip"
android:gravity="center"
android:layout_width="315dip"
android:textSize="10sp"
android:layout_height="wrap_content"/>
Run Code Online (Sandbox Code Playgroud)
在上面的测试中,通过Eclipse模拟器和我的android手机,最后一个TextView确认数据库包含"0dip"或"wrap_content",但是LinearLayout包含:
android:layout_height="@+id/skip">
Run Code Online (Sandbox Code Playgroud)
表现得好像它是所有TIME的"0dip".换句话说,我不能编程"影响android:layout_height的XML属性.
如果有更好/更标准的方式来完成我想要做的事情,请分享 - 但要清楚.我是新手,所以CODE EXAMPLES对我来说最好.
5月29日 - 在我看来(基于测试)你不能改变这段代码中指定的布局的布局属性:
SimpleCursorAdapter notes = new SimpleCursorAdapter(this,
R.layout.hole_info,
notesCursor, from, to);
setListAdapter(notes);
Run Code Online (Sandbox Code Playgroud)
我尝试的任何东西都会导致一些错误或另一个错误.所以,我已经看到了这些属性被更改的自定义列表适配器的示例,所以我正在尝试转换为自定义列表适配器.
Gab*_*gut 14
为什么不在代码中呢?
LinearLayout ll = (LinearLayout)findViewById(R.id.your_layout_id);
ll.setVisibility(View.GONE);
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
15916 次 |
最近记录: |